css专题总结

拿到视觉稿,首先确定内容区,如下:左右两边会各留20px(手机端左右留白,不用再特殊处理)

.content-grid {
  box-sizing: border-box;
  max-width: 1440px;
  min-width: 320px;
  margin: 0 auto;
  padding: 0 20px;
  overflow: hidden;
}

1、经典的文字布局,如下:使用flex布局

image.png

.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-图片在上,文字在下

pc.png
mobile.png
<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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 选择qi:是表达式 标签选择器 类选择器 属性选择器 继承属性: color,font,text-align,li...
    love2013阅读 2,350评论 0 11
  • H5移动端知识点总结 阅读目录 移动开发基本知识点 calc基本用法 box-sizing的理解及使用 理解dis...
    Mx勇阅读 4,659评论 0 26
  • 移动开发基本知识点 一.使用rem作为单位 html { font-size: 100px; } @media(m...
    横冲直撞666阅读 3,545评论 0 6
  • CSS 是什么 css(Cascading Style Sheets),层叠样式表,选择器{属性:值;属性:值}h...
    崔敏嫣阅读 1,513评论 0 5
  • 第一部分 HTML&CSS整理答案 1. 什么是HTML5? 答:HTML5是最新的HTML标准。 注意:讲述HT...
    kismetajun阅读 27,844评论 1 45