1

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;
}
Heatmanofurioso
  • 838
  • 6
  • 17

5 Answers5

2
<div class="master"> 
<div class="second" style="float:left">1st</div>
<div class="second">2nd</div>
</div>
Ashwani
  • 674
  • 1
  • 6
  • 15
2

Add this css -

.second {

    float: left;
    margin-left: 5px;

}

Check the DEMO

Sougata Bose
  • 30,169
  • 8
  • 42
  • 82
1

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

Friendly Crook
  • 930
  • 1
  • 7
  • 13
0

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

Sourabh Kumar Sharma
  • 2,756
  • 3
  • 20
  • 31
0

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;
}

More on this:

How do you keep parents of floated elements from collapsing?

Community
  • 1
  • 1
gmast
  • 172
  • 8