Home > Web Front-end > Front-end Q&A > How to set left margin in html

How to set left margin in html

藏色散人
Release: 2021-04-12 10:36:25
Original
13161 people have browsed it

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

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

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