Responsive Squares Divs
I want to have a column with 4 divs with a background-image and fit the 100% of the parent width and give the same to the height to make a square. This is what i have without %: M
Solution 1:
You may use a pseudo element:
.slot {
box-shadow:inset 005px#C9A170;
background:#EBE6C9;
border:solid #78624A;
overflow:hidden;
padding:5px;
margin:1em;
}
.slot:before {
content:'';
float:left;
padding:50%0;
}
body {
margin:0;
}
<divclass="col-sm-3 slots"style="background-color: red;"><divclass="slot"> anything here</div><divclass="slot"> can grow taller than the initial square shape</div><divclass="slot"></div><divclass="slot"></div></div>
Solution 2:
I don't understand what you're trying to accomplish... if you want those boxes to dynamically change size according to their parent div you need javascript for that, can't do with CSS.
Solution 3:
You can use a vertical padding with a percentage for this:
.slots {
width: 150px;
}
.slot {
width: 100%;
padding-bottom: 100%;
}
Post a Comment for "Responsive Squares Divs"