How to keep two divs in one row and two divs in one row

Source: Internet
Author: User

How to keep two divs in one row and two divs in one row

We know that div is a block-level element and exclusive to a row. Generally, two adjacent divs are not in a row.
For example:

<! DOCTYPE html> 

Browser effect:

So how can we make two adjacent divs in the same row?
There are two methods

<! DOCTYPE html> 

Running effect:

<! DOCTYPE html> 

Running effect:

Note:
(1) Why use display: inline-block instead of display: inline; Because display: inline invalidates the height and width styles of elements.
(2) Why is the display effect different from that of the two methods?
In method 2, there will be 8 PX margin in the two divs. Where does this come from? It is inherited from the body.

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.