Skip to content

Instantly share code, notes, and snippets.

@SarahElson
Forked from AakashRao-dev/index.html
Created February 6, 2023 15:54
Show Gist options
  • Save SarahElson/80047d9fb48a6c5cc14bf4baf0123a23 to your computer and use it in GitHub Desktop.
Save SarahElson/80047d9fb48a6c5cc14bf4baf0123a23 to your computer and use it in GitHub Desktop.
External Spacing or Margin
<div class="container">
<h1>External Spacing or Margin</h1>
<div class="box">
<div class="m-top">
<div></div>
<div></div>
<p>margin-top: 60px;</p>
</div>
<div class="m-right">
<div></div>
<div></div>
<p>margin-right: 60px;</p>
</div>
<div class="m-bottom">
<div></div>
<div></div>
<p>margin-bottom: 30px;</p>
</div>
<div class="m-left">
<div></div>
<div></div>
<p>margin-left: 60px;</p>
</div>
<div class="m-allFourSides">
<div></div>
<div></div>
<p>All four sides: 60px;</p>
</div>
</div>
</div>
@import url("https://fonts.googleapis.com/css2?family=Rowdies&display=swap");
/* MAIN CODE SHOWCASING THE USE OF MARGIN */
.m-top > div {
margin-top: 60px;
}
.m-right > div {
margin-right: 60px;
}
.m-bottom > div {
margin-bottom: 60px;
}
.m-left > div {
margin-left: 60px;
}
.m-allFourSides > div {
margin: 60px;
}
/* -------------------------- */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body {
height: 100%;
}
body {
font-family: "Rowdies", cursive;
color: #262626;
}
.container {
width: 100%;
height: 100%;
border: 16px ridge #ff6550;
background: #ffe7e7;
text-align: center;
overflow: auto;
}
.box {
margin-top: 3rem;
display: grid;
grid-template-columns: repeat(3, minmax(200px, 1fr));
justify-content: center;
align-items: center;
gap: 3rem;
padding: 2rem;
}
[class^="m-"] {
border: 4px solid tomato;
}
[class^="m-"] > div {
width: 100px;
height: 100px;
background: #d33a25;
}
@media (max-width: 900px) {
.box {
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment