Example

Margins

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link name="favicon" type="image/x-icon" href="https://skillzam.com/uploads/system/e353194f3b7cd1b75d69c3ab88041985.png" rel="shortcut icon" />
    <title>Margins</title>

    <style>
        
        /* margin shorthand property is set for the h1 heading element */
        h1 {
            background-color: cornflowerblue;
            text-align: center;
            border: 3px solid indigo;
            margin: 60px 20% 0 20%; 
        }

        /* para1 & para3 classes are set the left margin to "50%" of the viewport */
        .para1, .para3 {
            margin-left: 50%;
            border: 2px solid indigo;
        }

        /* para2 & para4 classes are set the right margin to "50%" of the viewport */
        .para2, .para4 {
            margin-right: 50%;
            border: 2px solid indigo;
        }

    </style>

</head>
<body>
<!-- 
    Margins are used to create space around elements, outside of any defined borders.
    CSS has properties for specifying margin for each side of an element:
        - margin-top : specifies margin for top-side of an element.
        - margin-right : specifies margin for right-side of an element.
        - margin-bottom : specifies margin for bottom-side of an element.
        - margin-left : specifies margin for left-side of an element.
    margin : is a shorthand property for following individual margin properties:
    Example - margin: 30px 40px 55px 90px;
-->

    <h1>Demo: Margins</h1>

    <p class="para1">Lorem, ipsum dolor sit amet consectetur adipisicing elit. Natus eaque illo, aperiam quibusdam corrupti officiis porro aliquam esse soluta sed.</p>
    <p class="para2">Lorem ipsum dolor sit amet consectetur adipisicing elit. Cupiditate, quia magni? Non perspiciatis consequuntur dignissimos labore animi eaque. Illo, veritatis.</p>
    <p class="para3">Lorem ipsum dolor sit amet consectetur adipisicing elit. Enim dolorum quisquam explicabo expedita quaerat eius, illo perferendis sunt ipsa doloribus!</p>
    <p class="para4">Lorem ipsum dolor sit amet consectetur adipisicing elit. Enim dolorum quisquam explicabo expedita quaerat eius, illo perferendis sunt ipsa doloribus!</p>

</body>
</html>

Output

View original