Home Web Front-end HTML Tutorial How to use margin 0 auto in HTML

How to use margin 0 auto in HTML

Nov 23, 2017 pm 05:56 PM
auto html margin

Margin is a very important attribute, so how to use margin 0 auto in HTML? Today we will introduce margin:0 auto. Here is a small example

margin setting objectOuter margin, if we set a border line (border) for DIV After setting the style, you can see in the DW software that the margin setting value is actually the distance outside the border. This style sets the style of the spacing between objects (DIV).

margin:0 auto function syntax

1. Margin:0 auto introduction

margin:0 auto sets the upper and lower spacing of the object to 0, and the left and right spacing is automatic.

Can be split: margin: 0 auto 0 auto (up and down)

can also be split into: margin-left:auto;margin-right:auto;margin-top:0;margin-bottom:0;

2. Function

Set margin:0 for DIV The auto style is to center the DIV horizontally in the browser. For layout centering and horizontal centering, just add margin:0 auto.

Joint point: auto (automatic, adaptive)

If we set the width of a DIV to 500px, and then set the margin:0 auto style, if the width of your browser window is 1000px wide, At this time, the spacing between the left and right sides of the DIV is (auto). At this time, the browser will automatically recognize the 250px width spacing between the left and right sides of the DIV. At this time, the DIV box will naturally be horizontally centered in the browser.

Why set margin:0 auto?

Set this style to center the DIV layout horizontally in the browser. The purpose is to be compatible with major browsers and center the layout. If you do not add the margin:0 auto CSS style, the layout will be centered in some browsers and to the left in others.

Forbidden: If you want the DIV layout to be centered in the browser, add margin: 0. Auto cannot add the floatfloat style to avoid logic errors and cause layout centering incompatibility.

I believe that through our introduction, you have mastered the attribute of margin 0 auto. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Related reading:

How to set the background image of a web page in HTML

How to set the cursor attribute of css

How to use border-radius in CSS

The above is the detailed content of How to use margin 0 auto in HTML. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles