拿到視覺稿,首先確定內(nèi)容區(qū),如下:左右兩邊會各留20px(手機端左右留白,不用再特殊處理)
.content-grid {
box-sizing: border-box;
max-width: 1440px;
min-width: 320px;
margin: 0 auto;
padding: 0 20px;
overflow: hidden;
}
1池充、經(jīng)典的文字布局,如下:使用flex布局
.featured-products-ul {
display: flex;
flex-wrap: wrap;
margin: 0 -10px; `消除最左邊和最右邊的10px`
}
.featured-products-item {
width: 20%; //`控制元素寬度`
border-radius: 3px;
}
.item-inner {
margin: 0 10px 20px; //`相鄰兩個元素之間的距離,左右各10缎讼,累加即20px`
background: #fff;
}
.item-inner-content {
padding-top: 25px;
padding-left: 20px;
font-size: 14px;
color: #555;
line-height: 1.5;
height: 235px;`高度固定,文字長度不一樣`
}
2坑匠、banner展示有兩種方式血崭,一個是作為background,一個是img,分別如下:
.banner-img {
background: url("/Alexandria/img/promotions/yiwu-service/banner_yiwu.jpg") no-repeat top center;
height: 670px;
margin: 0 auto;
background-size: cover;
}
.img-wrap {
font-size: 0; `去除底部留白`
img {
max-width: 100%;
max-height: 100%;
border-radius: 0 6px 6px 0;
}
}
3、flex巧用:pc-文字在左,圖片在右夹纫;mobile-圖片在上咽瓷,文字在下
<div class="banner">
//圖片再右
<div class="banner-right">
<div class="img-wrap">
<img src="">
</div>
</div>
//文字在左
<div class="banner-left"></div>
</div>
.banner {
display: flex;
max-width: 1440px;
min-width: 320px;
margin: 0 auto;
justify-content: space-between;
flex-direction: row-reverse; `//逆序排序`
.banner-left {
width: 40%;
background-color: #F5F7FA;
padding-top: 60px;
padding-left: 100px;
box-sizing: border-box;
border-radius: 6px 0 0 6px;
}
.banner-right {
width: 60%;
.img-wrap {
font-size: 0;
img {
max-width: 100%;
max-height: 100%;
border-radius: 0 6px 6px 0;
}
}
}
}
@media screen and (max-width: 767px) {
.banner {
flex-wrap: wrap;
flex-direction: column; `//豎排`
align-items: center;
.banner-right {
width: 100%;
.img-wrap {
text-align: center;
img {
border-radius: 6px;
}
}
}
.banner-left {
width: 100%;
padding: 30px 20px 0;
background-color: #fff;
}
}
}
4、img:max-width:100%;max-height:100%;
5舰讹、flex布局 align-self:base-line