Home  >  Article  >  Web Front-end  >  How to set left margin in html

How to set left margin in html

藏色散人
藏色散人Original
2021-04-12 10:36:2513103browse

How to set the left margin of html: first create a new HTML document; then define a box; then enter the style tag in the head tag; finally enter "position:absolute;" positioning in "#box1" and enter Letf just defines the left margin.

How to set left margin in html

The operating environment of this article: Windows7 system, HTML5&&CSS3 version, Dell G3 computer.

Create a new HTML document, as shown in the picture

How to set left margin in html

Define a box, enter

<div id="box1"></div>

as shown in the picture

How to set left margin in html

Then enter the style tag in the head tag

How to set left margin in html

Define the color and size of the box, enter

         width: 100px; 
        height: 100px; 
        background-color: #000000;
# in the style tag ##As shown in the picture

How to set left margin in html

Press f12 to preview and you can see a black square

How to set left margin in html

Return to dw, In #box1, enter position: absolute; for positioning, enter letf to define the left margin, enter left: 100px; to indicate 100 pixels from the left side of the screen, as shown in the figure

How to set left margin in html

Finally Press f12 to preview and you can see that the square is farther from the left

How to set left margin in html

[Recommended learning:

HTML video tutorial]

The above is the detailed content of How to set left margin 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:How to set html5 bordersNext article:How to set html5 borders