The value of the CSS margin attribute can be negative.

Source: Internet
Author: User

The value of the boundary margin in CSS can also be negative. Sometimes we can't believe it. This is an interesting topic. The negative boundary will bring us more novel ideas, it makes our work more exciting and challenging.

Let's take a look at an example. First, let's take a look at the CSS code:

<Style type = "text/css">
# Box1, # box2 {
 
Float: left;
Width: 200px;
Height: 300px;
Color: # ffffff;
Font-size: 36px;
Text-align: center;
Line-height: 300px;
}
# Box1 {
Border: solid 5px # ff0099;
Background-image: url('bg2.jpg ');
}
# Box2 {
Border: solid 5px # ffff00;
Background-image: url('bg3.jpg ');
}

</Style>
The XHTML structure is as follows:

<Div id = "box1">
Left column
</Div>
<Div id = "box2">
Right column </div>

Running result:

Now we want to change the positions of the left and right columns.
<Div id = "box1">
& Nbsp;
</Div>
<Div id = "box2">
Right column </div>

Replace:
<Div id = "box2">
Right column </div>
<Div id = "box1">
& Nbsp;
</Div>
You can.
However, when pages are complex, various tags are nested with hundreds of lines of code. This seemingly simple location change may take a long time and can certainly achieve the desired results, now, we have another idea to implement:
# Box1 {
Border: solid 5px # ff0099;
Background-image: url('bg2.jpg ');
Margin-left: 105px;
 
}
# Box2 {
Border: solid 5px # ffff00;
Background-image: url('bg3.jpg ');
Margin-left:-420px;

After running:

Related Article

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.