Perfectly realize the horizontal and centered display of floating elements_Basic Tutorial

WBOY
Release: 2016-05-16 12:03:39
Original
1363 people have browsed it

we often encounter page layouts that display several different areas of content in a row, but they are centered relative to the page. note that the content in these areas is not just text, but may also be mixed with images or other elements. generally, it is easy for us to think of using floating floats for such a layout, but how to center-align it and be compatible with low-end browsers? please read on.

first look at the html code:

some people will say that these items are all text. in fact, it is also feasible to replace ul with other elements (such as div). the principle is that .wrap is centered relative to the page, and the width is 1200px. of course, it can also be 1000px. the width can be freely defined, as long as it is greater than the content width. then .tabs floats left and sets position: relative; left: 50%; and then sets float: left; position: relative; left: -50%; for its internal element ul. finally, add overflow: hidden; *position to .wrap : relative;

the css code is as follows:

Copy after login

explain why you need to add overflow: hidden; *position: relative; to .wrap? the reason is that if the content is relatively long, due to the left: 50%; of .tabs, its position exceeds the width range of .wrap. when the display is slightly smaller, a horizontal scroll bar will appear on the page, and ie7 is more stubborn, so *position must be added. : relative; only works. interested users can try it by removing overflow: hidden;

finally, change ul to

(write css for .inner: float: left; position: relative; left: -50%;) and you can write the float you want in .inner typesetting (for example: a picture of a qr code, a customer service phone number and icon, and then a link to weibo...etc.).
Related labels:
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!