Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

HTML & CSS Create Responsive div on an Image using css

benjoe64

New Coder
I have an image slide show with a div ,some text in the div and a button. I need the div and the button to resize and responsive on small scale. My code doesn’t work. Below is my code
[CODE title="Responsive div"]
div class="slideshow-container">
<div class="mySlides fade">
<div class="numbertext">1 / 3</div>
<img src="@Url.Content("~/Content/Images/donatecar.jpg")" alt="index1" class="img3" />
<div class="text">Hello we accept any car donation</div>
</div>

<div class="wrapper">
<div class="post-content">
<h1>My heading test</h1>
<p style="color: black; font-size: 1.7rem; overflow-wrap: break-word; white-space: normal; font-family: ariel">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>

</div>
<button type="button" class="button1 button3" onclick="location.href = '@Url.Action("Pay", "Donations")'"><b style="font-size: 18px;">Donate Your Car</b></button>

</div>
</div>
.slideshow-container { width: 100%; position: relative; display: block;
}
.post-content {
background: none repeat scroll 0 0 #FFffff;
margin: 0 auto;
margin-top: -140px;
text-align: center;
position: relative;
display: block;
height: 330px;
width: 90%;
border: 2px solid lavender;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
border-radius: 12px;
overflow: hidden;
}
.wrapper {
text-align: center;

}
.button1 {
background: none repeat scroll 0 0 #FFffff;
color: blue;
padding: 20px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
left: 1px;
right: 410px;
margin: 4px 2px;
margin-top: -90px;
position: relative;
border: 1.2px solid lightblue;
}

.button3 {
border-radius: 8px;
}



[/CODE]
 
@benjoe64 This looks like you copied it from somewhere without understanding what is going on with it. The use of 'position: relative;' in places where it is not needed comes to mind. The need to have :
Code:
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
when it is not necessary. A good place to check on usage of HTML/CSS is Can I Use.
'overflow: hidden;' will hide your text when smaller screen cause the text to shrink width wise.
The real problem is using a height on the div that holds your Lorem ipsum text.
Lastly 'margin-top: -140px;' shoves your text upward. and I could not see the heading.

You might want to add a bottom padding to the text:
Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My Site</title>
<style>

.button1 {
    background: none repeat scroll 0 0 #ffffff;
    color: blue;
    padding: 20px 20px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    left: 1px;
    right: 410px;
    margin: 4px 2px;
    margin-top: -90px;
    position: relative;
    border: 1.2px solid lightblue;
}
.button3 {
    border-radius: 8px;
}  

/* These are modified*/
.slideshow-container {
    width: 100%;
    display: block;
}
.post-content {
    background: none repeat scroll 0 0 #ffffff;
    margin: 0 auto;
    text-align: center;
    display: block;
    width: 90%;
    border: 2px solid lavender;
    border-radius: 12px;
}
.wrapper {
    text-align: center;
}
</style>
</head>
<body>


<div class="slideshow-container">

    <!--
    <div class="mySlides fade">
        <div class="numbertext">1 / 3</div>
            <img src="@Url.Content("~/Content/Images/donatecar.jpg")" alt="index1" class="img3" />
        <div class="txet">Hello we accept any car donation</div>
    </div>
    -->

    <div class="wrapper">
        <div class="post-content">
            <h1>My heading test</h1>
            <p style="color: black; font-size: 1.7rem; overflow-wrap: break-word; white-space: normal; font-family: ariel">
            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
            </p>

        </div>
        <button type="button" class="button1 button3" onclick="location.href = '@Url.Action("Pay", "Donations")'"><b style="font-size: 18px;">Donate Your Car</b></button>
    </div>

</div>

</body>
</html>
 
@benjoe64 This looks like you copied it from somewhere without understanding what is going on with it. The use of 'position: relative;' in places where it is not needed comes to mind. The need to have :
Code:
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
when it is not necessary. A good place to check on usage of HTML/CSS is Can I Use.
'overflow: hidden;' will hide your text when smaller screen cause the text to shrink width wise.
The real problem is using a height on the div that holds your Lorem ipsum text.
Lastly 'margin-top: -140px;' shoves your text upward. and I could not see the heading.

You might want to add a bottom padding to the text:
Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My Site</title>
<style>

.button1 {
    background: none repeat scroll 0 0 #ffffff;
    color: blue;
    padding: 20px 20px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    left: 1px;
    right: 410px;
    margin: 4px 2px;
    margin-top: -90px;
    position: relative;
    border: 1.2px solid lightblue;
}
.button3 {
    border-radius: 8px;
} 

/* These are modified*/
.slideshow-container {
    width: 100%;
    display: block;
}
.post-content {
    background: none repeat scroll 0 0 #ffffff;
    margin: 0 auto;
    text-align: center;
    display: block;
    width: 90%;
    border: 2px solid lavender;
    border-radius: 12px;
}
.wrapper {
    text-align: center;
}
</style>
</head>
<body>


<div class="slideshow-container">

    <!--
    <div class="mySlides fade">
        <div class="numbertext">1 / 3</div>
            <img src="@Url.Content("~/Content/Images/donatecar.jpg")" alt="index1" class="img3" />
        <div class="txet">Hello we accept any car donation</div>
    </div>
    -->

    <div class="wrapper">
        <div class="post-content">
            <h1>My heading test</h1>
            <p style="color: black; font-size: 1.7rem; overflow-wrap: break-word; white-space: normal; font-family: ariel">
            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
            </p>

        </div>
        <button type="button" class="button1 button3" onclick="location.href = '@Url.Action("Pay", "Donations")'"><b style="font-size: 18px;">Donate Your Car</b></button>
    </div>

</div>

</body>
</html>
Hi oldman
Thanks for your good advice. I have got it working the way I want now by adding padding-bottom: 10%; and removing the height setting
 
Back
Top Bottom