Multiple div boxes in CSS share the instance code of the peer display

Source: Internet
Author: User
1, Div Two column row two-column Div layout How to implement, div two column side-by-row two-column div layout tutorial Solution
Two div boxes are implemented side-by, one line shows only two column div layouts, and the width width +float floats for a row to display a double-column div layout.
In the first case, float floats the same
Let the two div box float the same value, for example, set Float:left or Float:right, the width is set appropriately. Here we implement a two-row div layout with a case.
1), complete instance DIV+CSS code:

<! DOCTYPE html> 

2), need to note is the width, to want a row of two-column div layout, to avoid the third Div also side, here to set the calculation of the width (here the percentage width is 49%), three div box width is greater than the width of the parent, two div width and less than the parent width, you can achieve only 2 div side-by.
3), the second case, float float value is different
One is set to Float:left; one is set to Float:right.
Full HTML source code:

<! DOCTYPE html> 

2, div horizontal arrangement _css How to let a number of div box side-by-side display, how to make a number of div box side by row div horizontal display it?
We first set up 3 div box objects, and what CSS styles do not set a look at the effect. The code is as follows:
Show Div without peers
Three div boxes are displayed exclusively on one line
The default Style property of the Div box itself is exclusive, and there are usually two ways to resolve a Div exclusive line, one to set floats, and another to set the display style. Next for everyone through the article + Picture + case method to solve the div box objects side-by lateral arrangement and peer display method.
One, using CSS float side-by display
We can set a float floating property on the div to resolve the side-by, as long as your side div box total width is less than or equal to the outermost box width, you can implement multiple Div objects side-by-side display.
Add float float to achieve div box side-by display
Add float float to implement multiple div side-by display
Here we set a floating div pass, of course, when the actual use, to display the Div object to join the CSS class, we have to peer display CSS selector set floating. Avoid other settings that are not required to be added to the floating style.
Second, using CSS display peers show
We join Display:inline to resolve the Div box object that the peer side of the implementation will display. In order to distinguish between other objects that do not need to be set horizontally to display div boxes, we have a uniform bold CSS class for the Div box adjacent to the same row display, and the CSS is named ". Div-inline".
The CSS code is as follows:

. div-inline{Display:inline}


HTML code snippet:

<div class= "Div-inline" > First div box </div> <div class= "Div-inline" > Second box </div> <div class= " Div-inline "> A third box </div>

Third, summary: whether float floating or display implementation side-by-side, to display the first side of the total width is less than or equal to the object ancestor width, so that the side-by-side display to achieve a horizontal arrangement layout.

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.