官术网_书友最值得收藏!

Cleaning up the mess

First, we will stop the line from breaking in the Ctrl + D text in the second row of our design. For fixing this issue, we will create our first line of CSS code. Add the <head> tag to a custom CSS file. Remember to place it below the bootstrap.css import line:

<link rel="stylesheet" href="css/base.css">

In the base.css file, create a helper class rule for .nowrap:

.nowrap {
    white-space: nowrap;
}

In the HTML file, add the created class to the <kbd> element (line 43):

<kbd class="nowrap"><kbd>ctrl</kbd> + <kbd>d</kbd></kbd>

Reload the page and you'll see that one problem is solved. Now, let's fix the horizontal scroll. Can you figure out what is making the unintended horizontal scroll? A tip, the problem is in the table!

Tip

What is the meaning of the white-space CSS property?

The white-space property specifies how whitespace is handled inside an element. The default is normal, where the line breaks will occur when needed. nowrap will prevent line break by creating a new line and pre will only wrap on line breaks.

The problem is caused by the buttons with the display block that make the content of each column larger than intended. To fix this, we will create our first CSS media query:

@media (max-width: 48em) {
    table .btn {
        font-size: 0.75rem;
        font-size: 3.5vw;
    }
}

Breaking down each line, first we see the current media query. The rule is that for max-width of 48em (defined in Bootstrap as small devices), apply the following rules. If the view port is greater than 48em, the rule will not be applied.

For the .btn elements inside the table element, we changed the font size (this was causing the horizontal overflow). We used a new way to set the font size based on the viewport with the 3.5vw value. Each 1vw corresponds to 1 percent of the total viewport. If we change the viewport, we will change the font size dynamically without breaking the layout.

Since it is a new property, nowadays just Chrome 20-34 and Safari 6 or higher have this rendering feature. For this reason, we added the other line with font-size: 0.75rem as a fallback case. If the browser can't handle the viewport font size, it will already had decreased the font to 12px, which is a font that does not break the layout.

主站蜘蛛池模板: 边坝县| 惠州市| 延津县| 湖口县| 共和县| 宝坻区| 海林市| 济南市| 卢氏县| 高要市| 旌德县| 万山特区| 德令哈市| 辽中县| 新乐市| 邯郸县| 特克斯县| 神木县| 德格县| 江北区| 上蔡县| 和林格尔县| 云浮市| 吉水县| 延寿县| 广平县| 海南省| 合肥市| 奉贤区| 桐柏县| 洛川县| 安达市| 天水市| 兴文县| 惠州市| 延长县| 柏乡县| 丽水市| 石门县| 玛曲县| 视频|