Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html layout: how to float divs vertically

Tags:

html

css

layout

How do I get divs to float vertically like in this picture:

enter image description here

Background: I have a grid of checkboxes with content sorted alphabetically and I'd like to have alphabetic order progress vertically (since horizontal order is quite hard to follow). All the divs have same size (width like picture, height = 1 line size).

Update: To clarify: The main intention is to have a table layout with a variable amount of columns based on available screen width and have the cells in column-major order. The actual number of divs is not known in advance.

like image 556
Askaga Avatar asked Dec 16 '13 13:12

Askaga


People also ask

How do I put two divs vertically?

To align two <div> elements vertically in Bootstrap 3, you can try using the CSS Flexible Box Layout. In the example below, we display the needed row as a flex container box with the CSS display property and then, align the flex-items (columns) vertically with the align-items property.

How do you vertically space a div?

Align divs vertically using flex In this case, you have to set main axis as the vertical axis using flex-direction: column; and also use justify-content:space-between; or justify-content:space-around; to evenly space child elements.

How do I adjust divs side by side?

Use CSS property to set the height and width of div and use display property to place div in side-by-side format. float:left; This property is used for those elements(div) that will float on left side. float:right; This property is used for those elements(div) that will float on right side.

What is div layout?

HTML Div Based LayoutUsing the <div> elements is the most common method of creating layouts in HTML. The <div> (stands for division) element is used for marking out a block of content, or set of other elements inside an HTML document. It can contain further other div elements if required.


1 Answers

CSS

.cols {
        width:20%;
        float:left;
    }
    .rows {
        height:100px;
    }

HTML

 <div class="cols">
        <div class="rows">Div 1</div>
        <div class="rows">Div 2</div>
        <div class="rows">Div 3</div>
    </div>

    <div class="cols">
        <div class="rows">Div 4</div>
        <div class="rows">Div 5</div>
        <div class="rows">Div 6</div>
    </div>

    <div class="cols">
        <div class="rows">Div 7</div>
    </div>
like image 182
dipak_pusti Avatar answered Sep 20 '22 07:09

dipak_pusti