Reputation: 724
I'm making a site that has 3 different span
that sits next to each other by using a float:left
parameter. But this messes up the padding
I have on the wrapper the two elements are contained in.
How can I make them sit next to each other without messing with the padding?
.wrapper {
width: 100%;
padding: 10px 0;
background: red;
}
.box-A {
width: 49%;
float: left;
}
.box-A {
width: 49%;
}
<h1>Not working but aligned</h1>
<div class="wrapper">
<div class="box-A">
Lorem
</div>
<div class="box-A">
Ipsum
<br> Ipsum
<br> Ipsum
<br> Ipsum
<br>
</div>
</div>
<h1>Working, but not aligned</h1>
<div class="wrapper">
<div class="box-B">
Lorem
<br> Lorem
<Br>
</div>
<div class="box-B">
Ipsum
<br> Ipsum
<br>
</div>
</div>
Upvotes: 1
Views: 186
Reputation: 96
Make following changes in your css, I hope this should be work.
.wrapper {
width: 100%;
padding: 10px 0;
background: red;
}
.box-A {
width: 49%;
float: left;
}
.box-A {
width: 49%;
}
.wrapper:after {
content:"";
clear:both;
display:block;
}
Upvotes: 0
Reputation: 14179
Add overflow:hidden
on wrapper
.wrapper {
width: 100%;
padding: 10px 0;
background: red;
display: inline-block;
overflow: hidden;/*Add This Property*/
}
Upvotes: 1
Reputation: 168
<h1>Not working but aligned</h1>
<div class="wrapper">
<div class="box-A">
Lorem
</div>
<div class="box-A">
Ipsum<br>
Ipsum<br>
Ipsum<br>
Ipsum<br>
</div>
</div>
<style>
.wrapper {
width: 100%;
padding: 10px 0;
background: red;
display: inline-block;
}
.box-A {
width: 49%;
float: left;
}
.box-A {
width: 49%;
}
</style>
Upvotes: 1
Reputation: 8695
There are two solutions to be fixed the issue.
display:inline-block
instead of float:left
and remove the spaces which is occured by inline-block
clearfix
to wrapperUpvotes: 3