Twitter Bootstrap - borders

前端 未结 2 513
盖世英雄少女心
盖世英雄少女心 2020-12-07 09:51

I just started using Twitter Bootstrap, and I have a question about how to best add a border to a parent element?

for instance, if I have

 
相关标签:
2条回答
  • 2020-12-07 10:32

    Another solution I ran across tonight, which worked for my needs, was to add box-sizing attributes:

    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    

    These attributes force the border to be part of the box model's width and height and correct the issue as well.

    According to caniuse.com » box-sizing, box-sizing is supported in IE8+.

    If you're using LESS or Sass there is a Bootstrap mixin for this.

    LESS:

    .box-sizing(border-box);
    

    Sass:

    @include box-sizing(border-box);
    
    0 讨论(0)
  • 2020-12-07 10:41

    If you look at Twitter's own container-app.html demo on GitHub, you'll get some ideas on using borders with their grid.

    For example, here's the extracted part of the building blocks to their 940-pixel wide 16-column grid system:

    .row {
        zoom: 1;
        margin-left: -20px;
    }
    
    .row > [class*="span"] {
        display: inline;
        float: left;
        margin-left: 20px;
    }
    
    .span4 {
        width: 220px;
    }
    

    To allow for borders on specific elements, they added embedded CSS to the page that reduces matching classes by enough amount to account for the border(s).

    Screenshot of Example Page

    For example, to allow for the left border on the sidebar, they added this CSS in the <head> after the the main <link href="../bootstrap.css" rel="stylesheet">.

    .content .span4 {
        margin-left: 0;
        padding-left: 19px;
        border-left: 1px solid #eee;
    }
    

    You'll see they've reduced padding-left by 1px to allow for the addition of the new left border. Since this rule appears later in the source order, it overrides any previous or external declarations.

    I'd argue this isn't exactly the most robust or elegant approach, but it illustrates the most basic example.

    0 讨论(0)
提交回复
热议问题