Home  >  Article  >  Web Front-end  >  How to prevent div from wrapping in html

How to prevent div from wrapping in html

青灯夜游
青灯夜游Original
2021-10-11 16:03:2518848browse

htmlHow to prevent div from wrapping: 1. Use the displays attribute and just add the "display: inline-block;" style to the div tag. 2. To use the float attribute, just add the "float: left;" style to the div tag.

How to prevent div from wrapping in html

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

div automatically wraps by default, but you can use the following two methods to control the non-wrapping

1. Use the displays attribute

display: inline-block;

Example

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<style>
			div{
			    width: 300px;
			    height: 300px;
			    background-color: #20B2AA;
			    display: inline-block;
			}
		</style>
	</head>
	<body>
		<div></div>
		<div></div>
	</body>
</html>

How to prevent div from wrapping in html

2. Use the float attribute

float: left;

Example:

nbsp;html>

	
		<meta>
		<style>
			div{
			    width: 300px;
			    height: 300px;
			    background-color: #00aa00;
			    float: left;
			}
		</style>
	
	
		<div></div>
		<div></div>
	

How to prevent div from wrapping in html

For more programming-related knowledge, please visit: Programming Video! !

The above is the detailed content of How to prevent div from wrapping in html. 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
Previous article:What is a form in htmlNext article:What is a form in html