Home > Web Front-end > Front-end Q&A > How to prevent div from wrapping in html

How to prevent div from wrapping in html

青灯夜游
Release: 2021-10-11 16:03:25
Original
18871 people have browsed it

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;
Copy after login

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>
Copy after login

How to prevent div from wrapping in html

2. Use the float attribute

float: left;
Copy after login

Example:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<style>
			div{
			    width: 300px;
			    height: 300px;
			    background-color: #00aa00;
			    float: left;
			}
		</style>
	</head>
	<body>
		<div></div>
		<div></div>
	</body>
</html>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template