Float: center ???, Floatcenter

Source: Internet
Author: User

Float: center ???, Floatcenter

Old rule, first (ignore the text ^ V ^ in the figure ):

At first glance, it seems that the float: center is used for the middle image. But if you think about it carefully, the float attribute does not have the center value. How is that implemented? I will show it to you step by step.

1. Build the subject structure

The container contains two sub-elements: float: left and float: right;

2. Use a pseudo element: before as the intermediate img placeholder

If there is no interval between page-left and page-right, the width of the two pseudo elements is half of the img in the middle, which is as high as that of img.

.page_left:before, .page_right:before {            width: 151px;            height: 278px;            content: "";        }        .page_left:before{            float: right;        }        .page_right:before{            float: left;           }

3. Restore img

The pseudo element is already in the img position. Now you only need to reset the img.

 .img {            width: 302px;            height: 278px;            position: absolute;            top:0;            left: 349px;            background-image: url("img/sec1_qq.png");        }

For the demo, click http://runjs.cn/detail/nqhgwmbmand download the attachment. Cainiao, Pat !!!

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.