How can I grow the contained floating point element to the entire height of my container?

First I will ask the main question, and then I ask myself why I ask. I have a bunch of similar floating block elements inside a <div> , and I set overflow:auto to <div> so that its height expands to properly contain all the elements inside it.

Is there any way, using only CSS and HTML, to set only the first floating element to the full height of the div?

Just to be clear: I want to grow the contained element to the height of the container , and not vice versa.

I tried adding

  height: 100% 

for the first CSS element moved, but this has no effect.

To a painful detail. And if a better general approach comes to mind that will fix this particular problem, Iโ€™m all ears.

I mimic a table with a bunch of floating <ul> elements inside a <div> . Each list is a column in the โ€œtableโ€, and the first list is a column of row labels. So, to do the following:

  col A col B row 1 foo baz row 2 bar bat 

I use this markup:

 <div> <ul class='row-label'> <li>&nbsp;</li> * <li>row 1</li> <li>row 2</li> </ul> <ul class='data-col'> <li class='data-header'>col A</li> <li>foo</li> <li>bar</li> </ul> <ul class='data-col'> <li class='data-header'>col B</li> <li>baz</li> <li>bat</li> </ul> </div> 

* there should be an inextricable space in the first element of the list of shortcut lines, but I can not get SO to show &nbsp;

Attentive readers may wonder, โ€œWhy not use a real table?โ€ Two answers:

  • My fake approach is much more relevant, semantically, for my data. The data is more closely related in each column than in each row, but HTML tables allow the opposite. Therefore, I will need more sophisticated PHP on the backend to convert the data into HTML tables, and the result will not make much sense. The โ€œtableโ€ here is really more of a visual / presentation effect than anything.

  • I wanted to leave the ability to manipulate individual columns in JavaScript (show them and hide them in response to user action, with transition effects). From what I could say when I studied it, there is no easy way to do this in a standard HTML table - precisely because a row, not a column, is the basic unit of an HTML table. Please shoot me if I am wrong.

CSS, simplified, is as follows:

 div { overflow: auto; } div ul { float: left; list-style-type: none; padding: 0; margin: 0 0.5em; } 

The problem occurs when a row has more columns than it matches the width of the browser window. The columns wrap to the next line, and I get this careless result:

  col A col B col C row 1 foo baz bar col D col E zab oof 

In the end, I have a better solution, but the simplest fix is โ€‹โ€‹to give the row label column high enough to push these wrapped columns to the row. If I do something like this:

 ul.row-label { height: [lots of ems] } 

Then I get this result:

  col A col B col C row 1 foo baz bar col D col E zab oof 

But since there can be more of these simulated tables below the first, and since each "table" can have any number of rows, I cannot rely on absolute height.

+4
source share
3 answers

Make sure you set the mapping: block to your LI elements inside your UL. You must also indicate your UL display: block, overflow: hidden and height: 100%. By default, list items are an inline block that ignores your height settings.

Here is the proof of concept:

 <html> <head> <style type="text/css"> * { border: solid 1px black; } div { overflow: auto; } div ul { display: block; height: 100%; overflow: hidden; float: left; } div ul li { display: block; } </style> </head> <body> <div> <ul class='row-label'> <li>&nbsp;</li> <li>row 1</li> <li>row 2</li> </ul> <ul class='data-col'> <li class='data-header'>col A</li> <li>foo</li> <li>bar</li> </ul> <ul class='data-col'> <li class='data-header'>col B</li> <li>baz</li> <li>bat</li> </ul> </div> </body> </html> 

Presented example http://img526.imageshack.us/img526/9444/tablewithlists.png

+2
source

First, and, as you pointed out, your REALLY SHOULD use tables for tabular data. You can perform exactly the same manipulations with elements in a table as in any other place.

I donโ€™t know why you would like to do such a crazy thing, but itโ€™s best to just put the .data-col elements in a separate div, add a left margin and put them to the left:

EDIT: code added for my convenience

 ul, li { display: block; margin: 0px; padding: 0px; } ul { float: left; margin: 0px 5px; } li { height: 20px; } .data-cols { left: 0px; margin-left: 50px; overflow: hidden; } <div> <ul class='row-label'> <li> </li> <li>row 1</li> <li>row 2</li> </ul> <div class="data-cols"> <ul class='data-col'> <li class='data-header'>col A</li> <li>foo</li> <li>bar</li> </ul> <ul class='data-col'> <li class='data-header'>col B</li> <li>baz</li> <li>bat</li> </ul> </div> </div> 
0
source

Maybe this will help with ideas? I myself found this css structure:

http://www.blueprintcss.org/

0
source

Source: https://habr.com/ru/post/1286113/


All Articles