- Bootstrap 4:Responsive Web Design
- Silvio Moreto Matt Lambert Benjamin Jakobus Jason Marah
- 387字
- 2021-07-09 18:54:43
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!
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.
- VSTO開發入門教程
- 薛定宇教授大講堂(卷Ⅳ):MATLAB最優化計算
- Learning Salesforce Einstein
- UML 基礎與 Rose 建模案例(第3版)
- Android開發:從0到1 (清華開發者書庫)
- Scala Reactive Programming
- Python High Performance Programming
- Python機器學習算法與應用
- 從程序員角度學習數據庫技術(藍橋杯軟件大賽培訓教材-Java方向)
- SAS編程演義
- Less Web Development Cookbook
- Mastering Clojure
- Raspberry Pi開發實戰
- Web前端開發技術實踐指導教程
- Python程序設計教程