Assuming I have a piece of HTML that is structured as follows:
<div class="linkgrid">
<div class="gridentry">
<a href="#">Loooooooooooooong</a>
</div>
<div class="gridentry">
<a href="#">Short</a>
</div>
<div class="gridentry">
<a href="#">Meeeedium</a>
</div>
</div>
... I would like to use CSS to get a presentation that looks like this:
table {
table-layout: fixed;
}
td {
width: 50%;
padding: 1em;
background-color: red;
text-align: center;
}
td a {
color: white;
}
<table>
<tr>
<td><a href="#">Loooooooooooooong</a></td>
<td><a href="#">Short</a></td>
</tr>
<tr>
<td><a href="#">Meeeedium</a></td>
</tr>
</table>
Run codeHide resultNote that:
- Columns have the same width.
- The table does not have a fixed width (e.g. 100% or 300 pixels), i.e. it is as wide as required to ensure that the content fits into its cells. (Or put it another way: if there is only a small amount of content, the whole table will also be quite narrow.)
- The contents of the cell will only be completed if it makes the entire grid too large to fit in the containing block (in width).
- , HTML. , HTML . ( , .) 1
CSS- . , CSS, , "" , ? , CSS.
, : CSS (= JavaScript)?
EDIT: 1 , . .
, , , gridentry:
<div class="linkgrid">
<div class="wrapper">
<div class="gridentry">
<a href="#">Loooooooooooooong</a>
</div>
</div>
<div class="wrapper">
<div class="gridentry">
<a href="#">Short</a>
</div>
</div>
<div class="wrapper">
<div class="gridentry">
<a href="#">Meeeedium</a>
</div>
</div>
</div>
, - :
<div class="linkgrid">
<div class="wrapper">
<div class="gridentry">
<a href="#">Loooooooooooooong</a>
</div>
<div class="gridentry">
<a href="#">Short</a>
</div>
</div>
<div class="wrapper">
<div class="gridentry">
<a href="#">Meeeedium</a>
</div>
</div>
</div>