2

I have a couple of questions I hope you help me to clarify about working with semantic markup, using less with bootstrap 3 mixins.

First, columns setup:

On a non-semantic html you'd declare the cols on the div class <div class="col-lg-4 col-md-6 col-sm-12 col-xs-12"></div> as example.

As stated on bootstrap documentation you should declare the amount of columns for a given div with the .make-xx-column(@columnms), but, if you want to replicate the non-semantic it's supposed that code would be:

.make-lg-column(4); .make-md-column(6); .make-sm-column(12); .make-xs-column(12);

With this I found that when you are on a big resolution (more than 1200px) and if I have defined .make-lg-column(4); and .make-md-column(6); the result will be the 6 medium columns will be showed. On my inspector it shows as @media (min-width: 992px) and will rule over the @media (min-width: 1200px)

What is then, the correct way to set the different column values for a div? It seems to not be equal to how you'd set them up on a non-semantic layout.

Finally a question about padding,

Why when on the regular bootstrap css the column has a defined padding (15px as default) on the mixins the default padding is 0px? That forces to set the padding each time you declare a column amount (.make-lg-column(12, 30px);) ?

I appreciate if someone can help me working with this the right way, I'm sorry but It's the first time I work with LESS and semantic html code with bootstrap.

lukasgeiter
  • 147,337
  • 26
  • 332
  • 270
Jaypee
  • 1,272
  • 5
  • 17
  • 37
  • 1
    no clue, but if you care about semantics, ditch bootstrap – albert Mar 11 '14 at 19:46
  • In regards to the `padding`, because BS3 is using `box-sizing: border-box;`, you can change the padding without implications to columns fitting in your `.row` containers. So, BS3 uses 30px as it's default, but you can override that for your custom component. – dlane Mar 17 '14 at 15:34
  • Hi @dward. I understand that it has 30px as default, but what I'm saying is that when I'm working with less and BS3 mixins I get a padding of 0 as default. I'm putting columns within container and row – Jaypee Mar 17 '14 at 18:47

2 Answers2

1

I'm sure that this question has an answer on SO already, but for the time being.

You should call the mixins for the smallest grid (xs) first, or better call the mixins from small to width. (kind of mobile first)

The above make sense because of the media queries for the grid are defined with min-width, see also http://getbootstrap.com/css/#grid.

If you set the largest grid first (min-width:1200px) follow by (min-width:992px) then both will evaluate true for screensize wider than 1199 pixels, and so the latest override the first.

You should use:

.make-xs-column(12); 
.make-sm-column(12); 
.make-md-column(6); 
.make-lg-column(4);

Why when on the regular bootstrap css the column has a defined padding (15px as default) on the mixins the default padding is 0px? That forces to set the padding each time you declare a column amount (.make-lg-column(12, 30px);) ?

The default grids have a gutter of 30 pixels (set by @grid-gutter-width) between the columns. 15 pixels on each side of the columns, makes 2 x 15 pixels between each column.

Why when on the regular bootstrap css the column has a defined padding (15px as default) on >the mixins the default padding is 0px? That forces to set the padding each time you declare >a column amount (.make-lg-column(12, 30px);) ?

I found that:

@import "variables";
@import "mixins";
selector {
.make-lg-column(12, 30px);
}

compiles into CSS code as follows:

selector {
  position: relative;
  min-height: 1px;
  padding-left: 15px;
  padding-right: 15px;
}
@media (min-width: 1200px) {
  selector {
    float: left;
    width: 100%;
  }
}
Community
  • 1
  • 1
Bass Jobsen
  • 48,736
  • 16
  • 143
  • 224
-2

Bootstrap uses predefined sizing to maintain responsiveness behavior regardless of the screen size. I know you are thinking "1200px is 1200px regardless the screen. But remember we are talking about percentages. So, if you were going to display a gallery with a tiles side to side in a laptop, you'll be fine with:

<div class="col-md-3">picture 1</div>
<div class="col-md-3">picture 2</div>
<div class="col-md-3">picture 3</div>
<div class="col-md-3">picture 4</div>

They will fit just fine and keep a great display. But will that be the case if the split the width of the screen 4 ways in a smartphone? Probably too small, right? In that case, you'll be better off with:

<div class="col-xs-12">picture 1</div>
<div class="col-xs-12">picture 2</div>
<div class="col-xs-12">picture 3</div>
<div class="col-xs-12">picture 4</div>

This way they display accross the entire screen

In summary, ideally, you'd want to do the following:

<div class="col-md-3 col-xs-12">picture 1</div>
<div class="col-md-3 col-xs-12">picture 2</div>
<div class="col-md-3 col-xs-12">picture 3</div>
<div class="col-md-3 col-xs-12">picture 4</div>

Hope that helped

LOTUSMS
  • 10,317
  • 15
  • 71
  • 140
  • Thanks LOTUSMS but I understand those basics, but that code is not semantic as I'm trying to do. I don't think that's the way to use it. Please read this post about this matter http://ruby.bvision.com/blog/please-stop-embedding-bootstrap-classes-in-your-html – Jaypee Mar 19 '14 at 16:10