Columns must be immediate children of rows?
Asked Answered
C

3

-1

Columns must be immediate children of rows or I can have other divs inside a row without being a column? I'm working with drupal and it produces a lot of divs inside a container or row I've created.

For example I'm restricted to follow this structure always:

<div class="container">
  <div class="row">
    <div class="col">
      One of three columns
    </div>
    <div class="col">
      One of three columns
    </div>
    <div class="col">
      One of three columns
    </div>
  </div>
</div>

Or I can do something like this:

<div class="container">
  <div class="row">
    <div class="something">
      Something
    </div>
    <div class="col">
      One of three columns
    </div>
    <div class="col">
      One of three columns
    </div>
    <div class="something__else">
      Something else
    </div>
  </div>
</div>
Coleridge answered 15/5, 2019 at 8:54 Comment(1)
it is css, row and col are classes, you can use them freely; but in order to write maintanable, clear code (which others in your team can support), you should follow the framework...Ruffianism
H
2

From the Bootstrap docs...

"Rows are wrappers for columns. Each column has horizontal padding (called a gutter) for controlling the space between them. This padding is then counteracted on the rows with negative margins. This way, all the content in your columns is visually aligned down the left side... In a grid layout, content must be placed within columns and only columns may be immediate children of rows."

Therefore, the columns have padding that is specifically designed to work inside the row. If you use other than col, the content will not be aligned correctly on the left (and right) side as you can see with this example using borders...

https://codeply.com/go/hDcyKs2cWy

Haplography answered 15/5, 2019 at 10:29 Comment(1)
I know how to use the classes when I write HTML by myself. I was asking what should I do in the scenario which I use a CMS like drupal. It's creates various div in which I don't have immediate access so I can't give the classes with the right sequence.Coleridge
V
0

Something that helps me often is to define a border on the elements. So I can easily test if my Css works the way I want. Like Akber said, row and col are classes so you can use them when you want. But check out this link : Bootstrap grid documentation , this way you use the framework as it should. Good luck!

Version answered 15/5, 2019 at 9:41 Comment(0)
S
0

The reason we follow the framework is to write code that is clearly readable by colleagues, and by yourself when you inevitably come back to the code in 6 months. Writing code with inconsistent classes and structures will work, but it will be unreadable by others.

tl;dr - yes it's fine, but you shouldn't do it.

Sharmainesharman answered 15/5, 2019 at 9:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.