Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using 'table' and 'table-cell' with display property in responsive design?

Using table and table-cell

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?

  • Example Code: http://www.codepen.io/anon/pen/dCLgq
  • Demo: http://codepen.io/anon/full/dCLgq
like image 420
its_me Avatar asked Feb 14 '13 19:02

its_me


People also ask

What does display table cell do in CSS?

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.

How do I make my table responsive?

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 .

How do I make a table row responsive in HTML?

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!

What is the CSS display property and can you give a few examples of its use?

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.


1 Answers

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.

like image 124
braican Avatar answered Sep 27 '22 20:09

braican