今天文章重点:
- RWD 范围设定
- 事前准备
- 满版区块显示
- 非满版区块显示
- 实际应用
- 参考资料
这系列的练习都会以最基础的手机版、平板与电脑版的三种尺寸范围做练习。
我习惯从小写到大,好处是:只针对目前版面显示做考虑。
如果从大写到小,在思考版面编排时,我会花比较多的时间先把小尺寸不需要显示的内容先做处置,可能在过程中会不小心改动其他设定...
使用 media query 设定:依据使用者装置大小,决定 三个范围的版面样式。
参考 Bootstrap5(Breakpoints)。
随着使用者装置大小越来越多样,可以发现RWD Breakpoints越来越细,已达到更好的使用者体验。
在 breaking point 我选择设定 min-width
,表示:
/* 可以将全域设定写在这里,例:body内 统一基础字型 */
body{
font-family: 'Roboto', sans-serif;
}
/* X-Small Device : default setting
...
*/
@media(min-width: 768px){
/* Medium Device */
...
}
@media (min-width: 1400px) {
/* XX-Large devices */
...
}
如果是 从大写到小,记得方向设定要修改为 max-width
。
满版容器 > 定宽容器 > 内容容器 > 内容
.mainIntro > .container > .infoList
<!-- HTML -->
<section class="mainIntro">
<div class="container">
<h1 class="mainTitle">IT铁人赛-DAY01</h1>
<ul class="infoList">
<li class="infoItem">
<img src="https://fakeimg.pl/350x350/eae0d0/?text=A" alt="infoItem">
</li>
<li class="infoItem">
<img src="https://fakeimg.pl/350x350/eae0d0/?text=B" alt="infoItem">
</li>
<li class="infoItem">
<img src="https://fakeimg.pl/350x350/eae0d0/?text=C" alt="infoItem">
</li>
<li class="infoItem">
<img src="https://fakeimg.pl/350x350/eae0d0/?text=D" alt="infoItem">
</li>
</ul>
</div>
</section>
步骤:
.infoList{
display: flex; /* 让子层排排站 */
flex-wrap: wrap; /* 如果子层宽度 > 父层宽度,允许 子层折行排列 */
}
%
,让使用者装置自适应宽度大小。 /* X-Small Device */
.infoList .infoItem{
width: 100%;
}
/* Medium Device */
@media(min-width: 768px){
.infoList .infoItem{
width: 50%;
}
}
/* XX-Large Device */
@media(min-width: 1400px){
.infoList .infoItem{
width: 25%;
}
}
codepen 完整范例: https://codepen.io/chen-chens/pen/powypjX
.container
大小。%
,配合定宽容器max-width
,让使用者装置自适应。max-width: 600px
: 在 Medium Device
,如果装置宽度 < 600px,宽度显示 100% ;如果装置宽度 ≥ 600px,宽度显示 600px。 /* X-Small Device */
.container{
max-width: 300px;
margin: auto;
}
/* Medium Device */
@media(min-width: 768px){
.container{
max-width: 600px;
}
.infoList .infoItem{
width: 50%;
}
}
/* XX-Large Device */
@media(min-width: 1400px){
.container{
max-width: 1200px;
}
.infoList .infoItem{
width: 25%;
}
}
明日预告:DAY02 - 图文卡片
<<: 零基础Javascript,Day 01就不废话,开战。
「你因为两个原因来读这本书:首先,你是位程序设计师。再者,你想成为一位更好的程序设计师」 取自: ...
安装前注意事项 unRaid采用随身碟开机(系统跟引导区亦装在随身碟里) 所以须注意随身碟的挑选,千...
(https://www.pinterest.com/pin/492722015457646968...
在上一篇学到了 CSS 的基本语法、使用选择器以及档案的套用方法。接着就让我们来学习如何运用样式属性...
今天我们要介绍的是python当中简易的条件判断式,所谓的条件判断式就是只我们要去判断一个东西的是否...