Languages
[Edit]
EN

CSS - negative margin

0 points
Created by:
Inayah-Alexander
437

In this article, we would like to show you how to use negative margin in CSS.

Quick solution:

div {
  margin: -10px; 
}

 

Practical example

In this section, we present a practical example of how to use a negative margin on HTML page.

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <style>
    body {
      display: flex;
    }

    .container {
      width: 100px;
      height: 100px;
      border: 1px solid black;
      margin: 30px;
    }

    .negative-margin {
      margin: -20px; 
    }

  </style>
</head>
<body>
  <div class="container">
    <div class="negative-margin">Example text...</div>
  </div>
  <div class="container">
    <div >Example text...</div>
  </div>
</body>
</html>

References

  1. margin - CSS | MDN
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join