I have a webpage with various floated boxes and a footer positioned at the bottom. The issue arises when trying to create space between the boxes and the footer without using margins.
#main {
max-width: 700px;
margin: 0 auto;
}
.box {
width: 46.6668%;
padding-bottom: 46.6668%;
margin: 1.6666%;
background-color: black;
float: left;
}
#footer {
clear: both;
text-align: center;
height: 200px;
background-color: gray;
}
<div id="main">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<div id="footer">
<p>Sample Text</p>
</div>
To address this, I introduced an additional div element to act as a spacer, setting its height equal to the desired margin. The modified html and css codes will appear like this:
#main {
max-width: 700px;
margin: 0 auto;
}
.box {
width: 46.6668%;
padding-bottom: 46.6668%;
margin: 1.6666%;
background-color: black;
float: left;
}
#footer {
clear: both;
text-align: center;
height: 200px;
background-color: gray;
}
#space {
clear: both;
height: 200px;
}
<div id="main">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<div id="space"></div>
<div id="footer">
<p>Sample Text</p>
</div>
Do you think this solution is suitable for the layout?