Is there a way to specify different widths for columns in CSS3?
Asked Answered
D

3

23

I would like to use CSS to present a two-column layout. The markup I am using is this

<div style="-webkit-column-count: 2;
            -webkit-column-rule: 1px solid black;
            -webkit-column-width: 80px;
             margin-left:20px;margin-top:20px;">
    <div id="picturebox" style="">picture box</div>
    <div id="nme">name</div>
</div>

Is there a way to give one column a width of 20px and one column a width of, say, 80px?

Demark answered 16/3, 2010 at 10:23 Comment(0)
S
19

No, there isn't a way.

The feature is designed for content that flows between equal columns.

Subaltern answered 16/3, 2010 at 10:33 Comment(0)
G
18

Technically it's not possible to do it with the multi-column property only but for a 2-column layout you can accomplish that by setting a negative margin on one of the sides.

div {
    width: 400px;
    background-color: lightgreen;
}

ul {
    -moz-columns: 2 auto;
    -webkit-columns: 2 auto;
    columns: 2 auto;
    -moz-column-gap: 80px;
    -webkit-column-gap: 80px;
    column-gap: 80px;
    margin-right: -80px;
}
<div>
    <ul>
        <li>Lorem Ipsum Lorem Ipsum</li>
        <li>Lorem Ipsum Lorem Ipsum</li>
        <li>Lorem Ipsum Lorem Ipsum</li>
        <li>Lorem Ipsum Lorem Ipsum</li>
        <li>Lorem Ipsum Lorem Ipsum</li>
        <li>Lorem</li>
        <li>Lorem</li>
        <li>Lorem</li>
        <li>Lorem</li>
    </ul>
</div>

See JSFiddle Demo

Girish answered 19/3, 2015 at 22:49 Comment(1)
So following the logic behind the above nice idea, you can accomplish this with a 3-column layout as well.Dim
H
3

You could use the grid property:

.container-grid {
  display: grid;
  grid-template-columns: 20px 50px; /*columns widths*/
  height: 40vh;
}

.col-1 {
  background-color: blue;
}

.col-2 {
  background-color: green;
}
<div class="container-grid">
  <div class="col col-1"></div>
  <div class="col col-2"></div>
</div>
Humorist answered 18/1, 2019 at 21:47 Comment(1)
The grid is unable to break a child element into columns. Each element will always be in one of the columns as a whole.Sputum

© 2022 - 2024 — McMap. All rights reserved.