I'm trying to understand why the background color of the "row" element doesn't stretch on tablets. On tablets it appears only in the "center" element, while on desktop it's applied also to "left" and "right" divs. In the code, I put the "right" div before the "center" div because I want to align the "right" div to the "left" div on mobile/tablets.
Edit2: I've just realised that the real problem is that the background color of the h3
tag in the center
div is applied to the left
and right
div. Though, I didn't find any solution, neither the reason why this happens.
Edit: I've just noticed that if I use clear:both;
instead of float:none;
in the media query of the center
element it works. Why?
.row {
background-color: #5c5c5c;
}
.row h3{
background-color: #fff;
}
.left {
width: 25%;
float: left;
color: #fff;
padding: 0 10px 0 10px;
}
.right {
width: 25%;
float: right;
color: #fff;
padding: 0 10px 0 10px;
}
.center {
width: 50%;
float: left;
border-left: 2px solid #eaeaea;
border-right: 2px solid #eaeaea;
}
.clear {
clear: both;
}
@media (max-width: 1023px) and (min-width: 768px) {
.left {
float: left;
width: 50%;
}
.right {
float: left;
width: 50%;
}
.center {
float: none;
width: 100%;
}
}
<div class="row">
<div class="left">
content
</div>
<div class="right">
content
</div>
<div class="center">
<h3>content</h3>
</div>
<div class="clear"></div>
</div>