Home > Article > Web Front-end > How to prevent div from wrapping in html
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.
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>
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>
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!