Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

twitter bootstrap box-sizing ruined my layout

Tags:

my layout broken when I implement bootstrap during the half way of my project, fixed that with some css modification, and I had commented out this

/**, *:before, *:after {   -webkit-box-sizing: border-box;      -moz-box-sizing: border-box;           box-sizing: border-box; }*/ 

in bootstrap.css, will that affect its core? I just want to use the grid system in my project..

like image 473
Ulises Colen Avatar asked Oct 01 '13 06:10

Ulises Colen


People also ask

What is box-sizing unset?

box-sizing: unset; Removes the previously set box-sizing value, reverting it back to the initial browser value.

What does * box-sizing border-box do?

border-box tells the browser to account for any border and padding in the values you specify for an element's width and height. If you set an element's width to 100 pixels, that 100 pixels will include any border or padding you added, and the content box will shrink to absorb that extra width.

What is box-sizing in bootstrap?

Easily make an element as wide or as tall (relative to its parent) with our width and height utilities. Width and height utilities are generated from the $sizes Sass map in _variables.scss . Includes support for 25% , 50% , 75% , and 100% by default.


1 Answers

I have the same problem and bootstrap 3 destroys my existing layouts and third party widgets. Here are something things I've tried in order of increasing difficulty and stability.

Easiest Way

Safe only if you don't use other bootstrap components

Add the following css after the bootstrap css is loaded:

*, *:before, *:after {   -webkit-box-sizing: content-box;      -moz-box-sizing: content-box;           box-sizing: content-box; }  .container .row *, .container .row *:before, .container .row *:after {   -webkit-box-sizing: border-box;      -moz-box-sizing: border-box;           box-sizing: border-box; } 

This will use the border-box sizing only for elements within the grid system. This won't work if you have custom widgets within the grid as they would still have border-box applied.

More targeted approach

Safe only if you don't use other bootstrap components

Alternatively, you could add a custom col class to every column div which already have a col-*-* applied like so:

<div class="container">     <div class="row">         <div class="col-md-3 col">Grid still works</div>         <div class="col-md-9 col">:)</div>     </div> </div> 

Then use the following css instead:

*, *:before, *:after {   -webkit-box-sizing: content-box;      -moz-box-sizing: content-box;           box-sizing: content-box; }  .container .row .col, .container .row .col:before, .container .row .col:after {   -webkit-box-sizing: border-box;      -moz-box-sizing: border-box;           box-sizing: border-box; } 

This works fine if you ONLY need to use the bootstrap grid system in your project. If you intend to use other bootstrap components however, I don't recommend this approach either since other bootstrap components would depend on the border-box being set.

Cherry-pick each containing element to fix

A still better way would be to just override the box-sizing as content-box on a specific parent element for a widget like this:

.your-custom-widget-class *, .your-custom-widget-class *:before, .your-custom-widget-class *:after {   -webkit-box-sizing: content-box;      -moz-box-sizing: content-box;           box-sizing: content-box; } 

This approach offers the best forward compatibility with future bootstrap components, even if it seems to be working for you now.

like image 161
user193130 Avatar answered Sep 23 '22 12:09

user193130