詳解CSS常用操作對齊方法

來源:互聯網
上載者:User
這篇文章主要為大家詳解CSS常用操作對齊方法,感興趣的小夥伴們可以參考一下

一、使用margin屬性進行水平對齊

*{    margin: 0px;}.div{    width: 70%;    height: 1000px;    background-color: red;    margin-left: auto;    margin-right: auto;}

margin:值1 值2

值1代表上下 值2代表左右

*{    margin: 0px;}.div{    width: 70%;    height: 1000px;    background-color: red;    margin: 100px auto;}

二、使用position屬性進行左靠右對齊

*{    margin: 0px;}.div{    width: 70%;    height: 1000px;    background-color: red;    position: absolute;    right: 0px;}

三、使用float屬性進行左靠右對齊

*{    margin: 0px;}.div{    width: 70%;    height: 1000px;    background-color: red;    float: left;}
相關文章

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.