CSS Learning Notes

Source: Internet
Author: User

CSS Layout Summary

CSS

I write too little, referring to a lot of information on the web, try to summarize the various layouts of CSS, so that their own pages can be quickly find ideas. That 's it.


One • Horizontal centering
1.使用inline-block和text-align:center.parent{text-align: center;}.child{display: inline-block;}2.使用margin:0 auto;(定宽或者display:table;).child{width:200px;margin:0 auto;}.child{display:table;margin:0 auto;}3.使用绝对定位4.使用flex布局/*第一种方法*/.parent{display:flex;justify-content:center;}/*第二种方法*/.parent{display:flex;}.child{margin:0 auto;}
Two • Vertical centering
1.使用vertical-align(元素必须是inline或inline-block,必须设置行高或者table-cell)/*第一种方法*/.parent{display:table-cell;vertical-align:middle;height:20px;}/*第二种方法*/.parent{display:inline-block;vertical-align:middle;line-height:20px;}2.使用绝对定位.parent{position:relative;}.child{positon:absolute;top:50%;transform:translate(0,-50%);}3.使用flex布局.parent{display:flex;align-items:center;}
Three • Horizontal vertical centering
1.利用vertical-align,text-align,inline-block实现.parent{display:table-cell;vertical-align:middle;text-align:center;}.child{display:inline-block;}2.利用绝对定位实现.parent{position:relative;}.child{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);}3.利用flex实现.parent{display:flex;justify-content:center;algn-items:center;}
Left and right layout
没想好咋写
Left Middle right layout
待补充
Little Tricks
CSS布局用到的一般就几种:浮动,inline-block,display:table;,flex,还有框架。
@whhjdi 2018-04-06 11:49 字数 阅读 0

CSS Learning Notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.