css居中与布局

- 水平居中

1.行内元素:text-align:center
  <p class="cen">居中</p>     //html代码
  .cen{                      //css代码
  text-align:center;
  border:1px solid red;
  }
2.块级元素

让块级元素居中的方法就是设置 margin-leftmargin-rightauto
margin:0 auto

  <div class="first"></div>          //html
  .first{                            //css
        width:20px;
        height:20px;
        margin:0 auto;
        border:1px solid red;
  }

- 垂直居中

1.设置padding-top与padding-bottom相等

  <div class="first">first</div>      //html
  .first{                             //css
        width:200px;
        padding-top:20px;
        padding-bottom:20px;
        border:1px solid red;
  }

2.设置height与line-height相等

 <div class="first">first</div>      //html
  .first{                            //css
  width:100px;
  height: 50px;
  line-height: 50px;
  border:1px solid red;
  }

- 左右布局

通过float浮动实现,float:left与float:right

<div class="first">leftcontent</div>
<div class="second">rightcontent</div>
.first{                       
  width:100px;
  height: 100px;
  float:left;
  border:1px solid red;
}
.second{                       
  width:100px;
  height: 100px;
  float:right;
  border:1px solid green;
}

- 左中右布局

思路:使用div将左中左浮,右侧右浮

<div class="out">
    <div class="clearfix inner" style="float:left"> 
        <div class="first">left</div>
        <div class="first">middle</div>  
     </div>   
     <div class="third">right</div>
</div> 

.out{
    width:354px;
    height:100px;
    border:1px solid red;
}
.clearfix::after{
    content:'';
    display:block;
    clear:both;
}
.first{                       
  width:100px;
  height: 100px;
  float:left;
  border:1px solid red;
}
.second{                       
  width:100px;
  height: 100px;
  float:left;
  border:1px solid green;
  margin-left:25px;
}
.third{                       
  width:100px;
  height: 100px;
  float:right;
  border:1px solid green;
}


其他技巧

google关键字:
  • css shadow generator 生成阴影
  • css gradient generator 渐变背景
  • webpage free psd 免费psd文件
  • dribbble 网站
  • css tricks shape css形状代码
  • iconfont.cn 图标库
  • wallhaven 高清壁纸
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 阳光明媚的星期天,天空是那么晴朗,空气是那么新鲜,阳光把所有的光芒带到了大地,大地就变得暖洋洋的,就连云彩...
    栀蓝_鈊阅读 396评论 0 0
  • 如果有人问你“你的梦想是什么”你会如何回答? 朋友小A是一个外表纯良,内心坚毅的妹子。记得才上大学时,她说“这里只...
    清婉Roise阅读 170评论 0 0
  • 第二局 第二个夜晚 三维投影上出现了师也横死的画面,他就跟小鸡一样摊在地上,而他的头顶,一根皮带还在微微摇晃。 ...
    刀疤儿阅读 835评论 2 7
  • 熬夜写东西搞定了一个研究设计已经快5点了
    dq920813阅读 69评论 0 0