Home > Article > Web Front-end > How to set the left alignment of html
In HTML, you can use the "float" attribute to set left alignment. You only need to set the "float:left" style to the element. The float attribute defines in which direction the element floats. In CSS, any element can be floated; when the value is left, it means that the element floats to the left.
The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.
Divide left alignment conditions and methods You only need to add float:left to the div style to be aligned to the left (round left). Here, create a new html file, create a div container and give it a class attribute. Inside the container are two divs, one aligned to the left and one aligned to the right to show the difference:
Next set the css style. In the style tag, set the float of the div. If the value is left, left alignment is achieved. Finally, set the values for the div height, width, and border attributes. The div on the right is the same except that float is set to right:
Finally come to the browser, you can see that the div is on the left in the browser, and the other is on the right:
Recommended learning: html video tutorial
The above is the detailed content of How to set the left alignment of html. For more information, please follow other related articles on the PHP Chinese website!