2
I’m making a responsive website and I’m using "float" and "clear: Both" to put the Ivs in their places. But after using "clear: Both", the "div6" does not align correctly on the right side.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Title</title>
</head>
<body>
<div class="container">
<div class="div1">1</div>
<div class="div2">2</div>
<div class="div3">3</div>
<div class="div4">4</div>
<div class="clear"></div>
<div class="div5">5</div>
<div class="div6">6</div>
</div>
</body>
</html>
CSS:
.clear
{
clear:both;
}
.container
{
width: 100%;
height:auto;
position:relative;
left: 0;
top: 0;
display:table;
background-color:#CCC;
}
.div1
{
background-color:#FF0;
position:relative;
width: 50%;
height:200px;
float:left;
margin-left:0;
}
@media screen and (max-width: 700px)
{
.div1
{
background-color:#FF0;
position:relative;
width: 100%;
height:200px;
float:left;
margin-left:0;
}
}
.div2
{
background-color:#FC0;
position:relative;
width: 50%;
height:40px;
float:right;
margin-right:0;
}
@media screen and (max-width: 700px)
{
.div2
{
background-color:#FC0;
position:relative;
width: 100%;
height:40px;
float:left;
margin-left:0;
}
}
.div3
{
background-color:#F90;
position:relative;
width: 50%;
height:40px;
float:right;
margin-right:0;
}
@media screen and (max-width: 700px)
{
.div3
{
background-color:#F90;
position:relative;
width: 100%;
height:40px;
float:left;
margin-left:0;
}
}
.div4
{
background-color:#F60;
position:relative;
width: 50%;
height:40px;
float:right;
margin-right:0;
}
@media screen and (max-width: 700px)
{
.div4
{
background-color:#F60;
position:relative;
width: 100%;
height:40px;
float:left;
margin-left:0;
}
}
.div5
{
background-color:#0C6;
position:relative;
width: 50%;
height:80px;
float:left;
margin-left:0;
}
@media screen and (max-width: 700px)
{
.div5
{
background-color:#0C6;
position:relative;
width: 100%;
height:80px;
float:left;
margin-left:0;
}
}
.div6
{
background-color:#396;
position:relative;
width: 50%;
height:40px;
float:right;
margin-right:0;
}
@media screen and (max-width: 700px)
{
.div6
{
background-color:#396;
position:relative;
width: 100%;
height:40px;
float:left;
margin-left:0;
}
}
I imagine that the solution to this is simple but I’m not able to solve this problem. I appreciate the help!
Can I ask you a question? Since you are in the initial stage of the project, still in the construction of the grid, Pq you do not choose to do this grid with Flex and not with float? Float is an archaic technique so to speak, and Flex has a number of advantages, in addition to the alignment classes etc...
– hugocsl