css div vertical and horizontal centering implementation_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:44:47
Original
1222 people have browsed it

For example, if you set the div below in HTML to be centered vertically and horizontally, then

<<strong>div </strong><strong>id=</strong><strong>"box"</strong>></<strong>div</strong>>
Copy after login


css Style

<strong>#box</strong>{    <strong>width</strong>: 300<strong>px</strong>;    <strong>height</strong>: 200<strong>px</strong>;    <strong>margin-left</strong>: -150<strong>px</strong>;//宽度的一半,很重要,不然不居中,会偏右    <strong>margin-top</strong>: -100<strong>px</strong>;//高度的一半    <strong>position</strong>: <strong>absolute</strong>;//绝对定位方式    <strong>top</strong>: 50%;    <strong>left</strong>: 50%;    <strong>background-color</strong>: <strong>aqua</strong>;//背景颜色,便于测试查看效果}
Copy after login

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template