Home  >  Article  >  Web Front-end  >  How to make three divs side by side with css

How to make three divs side by side with css

青灯夜游
青灯夜游Original
2021-11-10 17:38:2616369browse

Css method to make three divs side by side: 1. Set the "display:inline;" or "display:inline-block;" style to the three div elements; 2. Use the float attribute to make the three divs The element is floated with the syntax "float:left;".

How to make three divs side by side with css

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

div is a block element, which is displayed on its own line by default:

<div></div>
<div></div>
<div></div>

How to make three divs side by side with css

So how do you make these three divs display side by side? There are two methods. Let me introduce them to you below:

1. Use the display attribute

to set all three divs to display:inline;or display:inline-block;

div{
	width: 100px;
	height: 20px;
	border: 1px solid red;
	display:inline-block;
}

How to make three divs side by side with css

Note: When set to display:inline;, it is required in the div There is content, otherwise the div cannot be opened.

2. Use the float attribute

to float the three divs

div{
	width: 100px;
	height: 20px;
	border: 1px solid red;
	float:left;
}

How to make three divs side by side with css

(Learning video sharing: css video tutorial)

The above is the detailed content of How to make three divs side by side with css. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn