Home>Article>Web Front-end> How to set the left alignment of html

How to set the left alignment of html

醉折花枝作酒筹
醉折花枝作酒筹 Original
2021-06-03 10:27:51 31561browse

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.

How to set the left alignment of html

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:

How to set the left alignment of html

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:

How to set the left alignment of html

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:

How to set the left alignment of html

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!

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