HTML width messed up by border

后端 未结 2 677
猫巷女王i
猫巷女王i 2021-01-24 19:05

HTML/CSS novice here.

Trying to put into practice what I\'ve learned on Codeacademy and I\'m stuck with an issue where my header which is set to width:100% ends up going

相关标签:
2条回答
  • 2021-01-24 19:49

    You could use box-sizing: border-box to calculate the width and height of the box including the paddings and borders.

    Also, you could use * { box-sizing: border-box } on everything. as suggested by Paul Irish.

    0 讨论(0)
  • 2021-01-24 19:58

    Adding a border increases the element's width past 100%.

    You can play with the box model, as others have suggested, using box-sizing.

    However, in this case, I suggest removing width:100%.
    The <div> will span the entire width of the page by default.

    You can also safely remove margin:auto.

    div#header {
        height: 100px;
        background-color: white;
        border: 10px solid black;
        font-size: 80px;
        text-align: center;
        font-family: Helvetica, Ariel, Sans;
    }
    

    http://jsfiddle.net/93EPg/

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