I am using display: table;
on the container and display: table-cell;
on the child elements, to highlight some posts horizontally on a page.
The thing is, I have no idea as to how to make them responsive, i.e. as the screen-size becomes smaller, each child (i.e. table-cell
) should become proportionately smaller, whilst continuing to stay aligned horizontally.
How do I do this?
Setting display to table makes the element behave like a table. So you can make a replica of an HTML table without using the table element and corresponding elements such as tr and td . For example, in HTML, you can make a table with the <table> element and also a <div> , or any container of your choice.
The primary method of making a responsive table is to add a class table table-responsive inside the table tag. To make a table responsive, we wrap the whole table inside a container tag like div with property overflow-x equals to auto .
You can just wrap your <table> tag inside of <div class="table-responsive"></div> since you're using bootstrap. Just like this: (use <table> instead of grid system (e.g. col-xs-1 etc.)) .. That's it!
The display CSS property sets whether an element is treated as a block or inline element and the layout used for its children, such as flow layout, grid or flex. Formally, the display property sets an element's inner and outer display types.
To scale the inner containers down with the page, you can set the container div
's width to 100%
:
in your example:
#the-big-stories {
display: table;
table-layout: fixed;
/** add 100% width **/
width:100%;
}
further, if you want to scale the images with the child containers, just give them width: 100%;
as well with height:auto;
see your codepen forked below:
http://codepen.io/braican/pen/xCmsw
You'll probably need to use media queries to really get the stuff inside to play nicely together, but the container will scale with the browser, as will the inner div
's.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With