A div for the front end of a designer's little piece of knowledge

Source: Internet
Author: User

Div is born with the bully gene (do not understand please read the first article OH), in fact, it is not met can conquer it you! haha ... Bring us here today to take him down.

Well, I admit that the word "add-on style" doesn't know where to look or what I call it, and then we'll be divided into styles and default styles.

  One, rectangular row sit

Do you remember the picture below?

They are really overbearing, but in the HTML sector, more overbearing, today we first to clean it up.

Draw two rectangles inside the body:

<div style= "width:100px; Height:100px;background-color:yellow; " ></div>

<div style= "width:100px; Height:100px;background-color:blue; " ></div>

(ps:html color is also directly can write words, do not want to write the color value of children's shoes can also directly write pink, black, red ...). And so on usually know some color English words. I forgot to tell you in the last section that the color value 3 and 6 bits are OK, for example: #333333, #4ed ... All right, to ask why the words still want to pull the system, I will not repeat, you remember on the line. )

Then save, and the browser opens to see:

So in order for the blue rectangles to line up on the right side of the yellow rectangle, first let the yellow rectangle position, "Step aside",

Add a new style to the first rectangle: float:left (ie to the left, follow our writing habits from left to right, you can also try to the right)

And then......

Why is there only one left!!!

I'll give it to you slowly.

Well, why do you ask me to tell you this? One more attribute: opacity (transparency), followed by a decimal number, 0.5 means 50% transparency.

<div style= "width:100px; Height:100px;background-color:yellow;float:left; opacity:0.5; "></div>

<div style= "width:100px; Height:100px;background-color:blue; " ></div>

And then save the refresh:

If you verify it, you will find that this color is the color that we reduce the yellow transparency and the blue intersection in PS. Other words:

Yes, yes, the blue rectangle is obscured by the yellow rectangle. (for short, two rectangles are small blue and small yellow)

As to why it is obscured, this is related to the property of float. Float is the meaning of floating, that is, the addition of the float property of the small yellow is actually floating up, so originally it "station" position on the empty, small blue "usurper" and occupy a small yellow original position. Like a layer, the above layer will cover the same size as its own area, so the small blue will never be with the small yellow "equal" (Woo-woo ...) You are beyond my reach. But your light in the blue rectangle and add floating attributes are not used, Div's innate bullying gene does not allow ... Don't believe you try, haha ...

Then the problem comes, want to row, and do not want to be small yellow trample at the foot, how to do?

Only the small blue also raised up slightly.

So two rectangles should have a float property so they're on the same level

<div style= "width:100px; Height:100px;background-color:yellow;float:left; "></div>

<div style= "width:100px; Height:100px;background-color:blue;float:left; "></div>

OK, you can try to draw a different size of the rectangle, let them line up, but not all of them can be good row. In HTML, the body size is infinite, but your screen can only show what it means to be a little bit wider. In addition to the current popular full screen pages, general Web pages will be specified width and will not specify height. You may often see pages with vertical scrollbars, but there is almost no horizontal scroll bar (unless your device screen is smaller than the general PC screen or a few times the page is magnified), so you can also say that the size of the page is related to your browser display area.

So many sites will take a variety of screens are applicable to the content width, that is, do webui when you stay in the effective content area (common 1200px, 1001px, etc.). The developer will determine a maximum width for the layout based on your size.

Draw a few more rectangles of the same width, add a left-floating attribute (float:left;) to narrow your browser width, and you'll find that they don't stay in the first row all the time, and sometimes they wrap. When the far right distance is not enough to let go of it, he will choose a different line. This is one of the mysteries of the response Web site, the same Web page, PC and mobile phone can be viewed, and the layout will change without affecting the content. The following figure:

Do you think that the red is not found in the location of the third line and changed into the phone to see the page like that? (*^__^*)

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.