CSS irregular background image centered in navigation

Source: Internet
Author: User

In the production of CSS navigation, there is a problem, the previous navigation is left and right symmetry, as long as the use of margin:0 auto, you can achieve the center. But this time the picture template navigation of the left width, the right narrow, if all as the background to layout, a glance will feel that the navigation is not in the middle.

In order to have its visual logo and the white area of the navigation menu centered, it is necessary to use relative positioning and absolute positioning.

Left-side.pngright-side.png

The code for HTML is as follows:

<DivID= "MSG">         <Divclass= "Left-side"></Div>         <Divclass= "Right-side"></Div>... </Div><!--msg End -

The CSS code is as follows:

#msg{float: Left;width:100%;Height:130px;Margin-left:-18px;/*changes relative to the original position*/position:relative;Background-color:#fff;}. Left-side{position:Absolute;/*changes relative to the parent, which is msg at the parent level*/ Left:-90px;Background-image:URL (images/left-side.png);background-repeat:no-repeat;width:90px;Height:130px;}. Right-side{position:Absolute; Right:-70px;Background-image:URL (images/right-side.png);background-repeat:no-repeat;width:70px;Height:130px;}

CSS irregular background image centered in navigation

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.