Reputation: 1028
I have 2 divs which i cannot give different class names, due to them being the same but in a repeatable php code, which doesen't allow me to give them different class names. So i basically want to display them side by side. I have tried giving them a float left and relative position and a master div surrounding them with absolute position and other things like that, but to no avail.
HTML:
<div class="master">
<div class="second">1st</div>
<div class="second">2nd</div>
</div>
CSS currently applied:
.second{
color:#FFF;
width:300px;
height: 10%;
background-color:#69F;
border-radius:25px;
opacity: 0.7;
filter: alpha(opacity=40);
float:left;
}
.master{
width:960px;
padding-top:12%;
margin: 0 auto;
font-size:50px;
}
Upvotes: 1
Views: 2023
Reputation: 1198
Try adding display: inline-block
.second {
display: inline-block;
}
and make sure not to increase the width of any .second
container to more than half of the parent
Upvotes: 0
Reputation: 192
If you use "float:left" you have to set a width (in percentage -obviously they must not exceed 100%-, or pixels) for the floated divs. Also, you might want to use this css for the container:
.container:after {
content: "";
display: table;
clear: both;
}
How do you keep parents of floated elements from collapsing?
Upvotes: 0
Reputation: 31749
Add this css
-
.second {
float: left;
margin-left: 5px;
}
Check the DEMO
Upvotes: 2
Reputation: 732
<div class="master">
<div class="second" style="float:left">1st</div>
<div class="second">2nd</div>
</div>
Upvotes: 2
Reputation: 2817
In your css code put this:
.class
{
float:left;
}
also make sure that if you put the width of that class .second
then it should not exceed 50% as these two divs are only contained in the main div with the class .master
Upvotes: 0