Last active
May 17, 2020 13:22
-
-
Save manikrathee/6719554 to your computer and use it in GitHub Desktop.
Common UI pattern problem with a simple solution: Space elements without having an extra set of padding at the bottom of a container.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Div has 10px padding on all sides. | |
- P or LI's have margin-bottom to space out the next element. | |
- What you're left with is a giant space at the bottom of the div from the combined properties: padding-bottom: 10px on the Div and margin-bottom: 15px on the last child element. So, instead of using :last-child to try and un-do the styles set on each element, why not set it differently in the first place? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
<p>Here's a sentence</p> | |
<p>Here's another sentence</p> | |
<p>Oh damn, a third sentence.</p> | |
</div> | |
<div> | |
<ul> | |
<li>Uno</li> | |
<li>Maybe Another Uno</li> | |
<li>Boom. Uno x3</li> | |
</ul> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
div { | |
padding: 10px; | |
} | |
p { | |
& + p { | |
margin-top: 15px; | |
} | |
} | |
li { | |
& + li { | |
margin-top: 10px; | |
padding-top: 10px; | |
border-top: 1px solid #000; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wonderful idea! How didn't I got to this before?
Starred. Thank you! :D