CSS/HTML Margin to auto to Center Code For Website - Learn About Website | DaddyFile

0

Use of The auto Value Explain

You can set the margin property to auto to horizontally center the element within its container.
The element will then take up the specified width, and the remaining space will be split equally between the left and right margins.



Html Code:

<!DOCTYPE html>
<html>
<head>
<style>
div {
    width:300px;
    margin: auto;
    border: 1px solid red;
}
</style>
</head>
<body>

<h2>Use of the auto Value</h2>
<p>You can set the margin property to auto to horizontally center the element within its container.
The element will then take up the specified width, and the remaining space will be split equally between the left and right margins:</p>

<div>
This div will be centered because it has margin: auto;
</div>

</body>
</html>






Html Code Result:



Post a Comment

 
Top