Displaying divs on multiple rows with custom limitations

css grid
display: flex
display: table css
css display
display: table-row
bootstrap
display inline-block
display: table css-tricks

I am trying to place 6 boxes, as a small exercise to understand how to do it. I want these 6 boxes to be divided in 4 boxes on a row and then 2 on the second one, and I want to do it with the display feature in CSS so that is not applicable only for this case. This is what I have been trying. https://gyazo.com/f64788cdf85d263e56452c1412fdcfb0?token=f6c45c6813c3fc47addb63483cee3f6a

    .parent{
        display: flex;
        flex-wrap: wrap;
    }

    .parent-wrapper {
        height:100%;
        width:100%;
        border: 1px solid black;}

    .child {
        width: 300px;
        height: 200px;
        background-color: green;
        border: 1px solid red;
        margin: 5px;
        flex: 1 0 21%; 
    }

You could use display: flex.

HTML:

<div class="flex">
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
</div>

CSS (EDITED):

.flex {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
}

.flex div {
    height: 200px;
    background-color: green;
    border: 1px solid red;
    box-sizing: border-box;
    /*flex: 1 0 23%;*/
    width: 24.1%;
    margin: 5px;
    /*margin-bottom: 5px;*/
}

The output is the following:

The display property, There are only a handful of values that are commonly used: div { display: inline; /* Default of all elements, unless UA stylesheet overrides� To position the divs side by side, we are using the float property to float each .float-child element to the left. Since they are both floating to the left, they will display side by side if there’s enough space for both to fit. They do fit because we have two .float-child divs, each at 50% width.

Not sure if you mean this but what I understood from your question:

HTML:

<div class="divTable">
    <div class="divTableBody">
        <div class="divTableRow">
            <div class="divTableCell"></div>
            <div class="divTableCell"></div>
        </div>
        <div class="divTableRow">
            <div class="divTableCell"></div>
            <div class="divTableCell"></div>
       </div>
       <div class="divTableRow">
           <div class="divTableCell"></div>
       </div>
       <div class="divTableRow">
           <div class="divTableCell"></div>
       </div>
   </div>
</div>

CSS:

.divTable{
    display: table;
    width: 100%;
}
.divTableRow {
    display: table-row;
}
.divTableHeading {
    background-color: #EEE;
    display: table-header-group;
}
.divTableCell, .divTableHead {
    border: 1px solid #999999;
    display: table-cell;
    padding: 3px 10px;
}
.divTableHeading {
    background-color: #EEE;
    display: table-header-group;
    font-weight: bold;
}
.divTableFoot {
    background-color: #EEE;
    display: table-footer-group;
    font-weight: bold;
}
.divTableBody {
    display: table-row-group;
}

Line Clampin' (Truncating Multiple Line Text), p> </div>. And you want to limit it to exactly three lines in a container. Like this: . line-clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; } Weekly news: Truncating muti-line text, calc() in custom property values,� You can use float: left, but give the divs 50% width. It's always better to put box-sizing: border-box so padding and borders won't increase the total width/height (if specified) of the elements. And don't use the same id multiple times within the same page, convert that to a class.

If you want to use the display: grid the solution could look like this: https://jsfiddle.net/uvrjs7op/

<div class='Wrapper'>
  <div class='Item-A'></div>
  <div class='Item-B'></div>
  <div class='Item-C'></div>
  <div class='Item-D'></div>
  <div class='Item-E'></div>
  <div class='Item-F'></div>
</div>

.Wrapper {
  Display: grid;
  grid-template-columns: 25% 25% 25% 25%;
  grid-template-rows: 50px 50px;
  Background: orange;
}

.Item-A{
  grid-column-start: 1;
  grid-column-end: 2;
  Background: Green;
}
.Item-B{
  grid-column-start: 2;
  grid-column-end: 3;
  Background: blue;
}
.Item-C{
  grid-column-start: 3;
  grid-column-end: 4;
  Background: red;
}
.Item-D{
  grid-column-start: 4;
  grid-column-end: 5;
  Background: brown;
}
.Item-E{
  grid-column-start: 1;
  grid-column-end: 3;
  grid-row-start: 2;
  Background: yellow;
}
.Item-F{
  grid-column-start: 3;
  grid-column-end: 5;
  grid-row-start: 2;
  Background: purple;
}

Grid system � Bootstrap, <div class="container"> <div class="row"> <div class="col-sm"> One of three Be aware of the limitations and bugs around flexbox, like the inability to use Create equal-width columns that span multiple rows by inserting a .w-100 Make the breaks responsive by mixing the .w-100 with some responsive display utilities. 0 Displaying divs on multiple rows with custom limitations Feb 8 '19. 0 How to prevent user to access login page when its already logged in? Feb 21 '19.

An easy solution will be

Solution

#wrapper {
  display:grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: 1fr;
  grid-column-gap: 5px;
  width:100%;
}
#wrapper > div {
  margin:10px;
  background-color:#bada55;
}
<div id="wrapper">
  <div id="first">first</div>
  <div id="second">second</div>
  <div id="third">third</div>
  <div id="fourth">fourth</div>
  <div id="fifth">fifth</div>
  <div id="sixth">sixth</div>
</div>

Varying Column Heights in Bootstrap - WDstack, Having more than 12 column units in a single . row element*. Some designers out there think that you must limit each .row to 12 columns, and don't understand column wrapping. .row.display-flex { .row.force-height>div { every X columns which can become more complicated for multiple grid tiers. Setting the display as "inline" for the div will remove the line breaks, and cause it to be displayed as an inline element instead of a block element. For your specific requirement, set display as "inline-block" for the divs. The divs would be rendered as block elements, but laid out as inline elements. Hope it helps!

Different Tricks on How to Make Bootstrap Columns All the Same , @media only screen and (min-width : 768px) { .is-table-row { display: table; } < div class="row is-table-row"> <div class="col-sm-4">. So it would actually makes sense to create multiple utility classes: is-xs-table-row the styles a bit because the columns now have a height (not the custom .box element). I wanna show default or one div on load meaning it will always be visible and divs 2 and 3 hidden. Now when you click on 2 or 3 it will show its content and hide the rest! RyanReese July 15, 2015

PhoneGap Build: Developing Cross Platform Mobile Applications in , To limit the width and height of the textarea and to make scroll bars appear when the text are used: <div data-role = "fieldcontain"> <label for = "custommsg"> Custom The initial size of the textarea will be 3 rows and 40 columns. Radio Buttons Both checkboxes and radio buttons are used for displaying different options. Using display: flex, our grid-row stretches to the full size of the container. We use flex-flow: wrap to designate that child divs (our columns/grid-items) should wrap if they exceed the width of the row. Then, flex-flow: row means our grid-items will flex from left to right. If we used flex-flow: column, our child divs would flex from top down.

Getting your DIVs to behave like TABLEs, You can do multiple rows but with no way (that I know of) to do column As I see over and over again, people tell about the advantages using CSS Microsoft and others couldn't display the logo until they passed their� The way I would do it is to dynamically create all the image rows in code behind. On your page you will want to have a main control to populate, like a Panel control. Then in your code behind you will want to dynamically create the div rows for each set of pictures, and then add them to your panel control.

Comments
  • Post your code here instead of sharing it via Screenshot
  • This is what i wish as a output, but the last two on the second row should be the same size as the one on the first row
  • Hi @DavidVulpe , I have updated the CSS of my answer, now it should work as you want :)
  • Thank you, the only thing I need to do now is to center the ones on the second row.
  • You just need to add in the class .flex the following line: justify-content: center;