Home >Web Front-end >CSS Tutorial >Detailed explanation of common CSS operation alignment methods

Detailed explanation of common CSS operation alignment methods

高洛峰
高洛峰Original
2017-03-26 11:19:101247browse

This article mainly explains in detail the common CSS operation alignment methods. Interested friends can refer to it

1. Use the margin attribute for horizontal alignment

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

margin: value 1 Value 2

Value 1 represents up and down, value 2 represents left and right

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

2. Use the position attribute for left and right alignment

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

3. Use the float attribute for left and right alignment

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

The above is the detailed content of Detailed explanation of common CSS operation alignment methods. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn