Example with 2 columns of boxes that change to a single column on small screens
html
<div class="my_root_container">
<a href="/somepage">
<div class="my_item_container">
<div>
<div class="my_item_image">
<img src="my_image_default.png" alt="My Image" >
</div>
<div class="my_item_details">
<p class="my_item_title">My Title</p>
</div>
<div style="clear:both"></div>
</div>
</div>
</a>
<a href="/somepage">
<div class="my_item_container">
<div>
<div class="my_item_image">
<img src="my_image_default.png" alt="My Image" >
</div>
<div class="my_item_details">
<p class="my_item_title">My Title</p>
</div>
<div style="clear:both"></div>
</div>
</div>
</a>
</div>
css
/*---------------------------------------*/
/*---------------------------------------*/
/*----- RESPONSIVE COLUMNS OF BOXES -----*/
/*---------------------------------------*/
/*---------------------------------------*/
.my_root_container {
clear: both;
}
.my_item_container {
width: 240px;
border: 1px solid #CCC;
border-radius: 6px;
margin-top: 16px;
margin-right: auto;
margin-left: auto;
margin-bottom: 16px;
padding-top: 6px;
padding-right: 6px;
padding-left: 6px;
padding-bottom: 6px;
}
.my_item_image {
width: 226px;
height: 120px;
text-align: center;
float: none;
margin-left: auto;
margin-right: auto;
}
.my_item_image img {
width: 226px;
height: 120px;
object-fit: contain;
margin-top: 0px;
margin-right: auto;
margin-left: auto;
margin-bottom: 0px;
}
.my_item_details {
overflow: hidden;
padding: 0px 0px 0px 0px;
position: relative;
height: 50px;
}
.my_item_details, .my_item_details a, .my_item_details a:Hover, .my_item_details a:Visited {
text-decoration: none;
}
.my_item_title {
font-size: 18px;
line-height: 140%;
font-weight: bold;
color: var(--odac-color-main1);
margin: 6px 0px 0px 0px;
padding: 0px 0px 6px 0px;
text-align: center;
width: 100%;
position: absolute;
top: 50%;
transform: translateY(-54%); /*For text can need 54%*/
}
/*CHANGE FROM MULTI COLUMN TO SINGLE COLUMN ON SMALL SCREENS */
@media only screen and (max-width: 800px) {
/* When width is less than or equal to 800px */
.my_root_container {
width: 100%;
}
.my_item_container {
float: none;
}
}
@media only screen and (min-width: 801px) {
/* When width is greater than or equal to 801px */
.my_root_container {
width: 560px; /* (2 x odac_post_categories_item_container width) + (4 x odac_post_categories_item_container left right margins) */
margin-right: auto;
margin-left: auto;
}
.my_item_container {
margin-right: 20px;
margin-left: 20px;
float: left;
}
}
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.