r/csshelp • u/Babandi • May 15 '20
Resolved padding or margin? which method is reccomendable?
Hi everyone,
I would like to make a simple footer for a web page that should have this structure
I was thinking using a <div class="footer"> as main container a second <div class="content"> to put all the links inside, like this. I was thinking about using a display: flex; to simply arrange all the text elements but I wasn't sure about how to space them.
do you think would be better to use a padding for the class="footer" or give margins to the div content? I'm quite new to css so these two ways seems both good for me but I don't really know which would be the most appropriate.
Thank you!
2
u/artyfax May 16 '20
This one is interesting. Let us think about what margin and padding actually are.
The CSS box model shows us the hierarchy of an element.
Margin is the space outside your element, while Padding is the space inside the element.
It is the safer bet to focus on one of them. Personally I prefer the padding way. This lets us create reliable borders and spacing.
Your example here using grid and padding.
But this is the web and its 2020 and we want this to look good on any device, even your iWatch or Tamagochi. We cannot use fixed widths anymore.
So we don't, we think fluidly and get rid of all those fixed numbers. We love percentages and fractions now.
And this is what we get. (try resizing this)
Another version using left right bottom classes: here
1
u/Silversunset01 May 15 '20
I think it's largely subjective based on what you're going for. This is a good explanation on the difference between the two (with visuals)
http://www.differencebetween.net/technology/difference-between-padding-and-margin/
0
May 15 '20
[deleted]
1
May 15 '20
Surround text with `backticks`
0
May 15 '20
[deleted]
1
May 15 '20
...there are only so many buttons in the Fancy Pants editor, if you have that available I don't know why you wouldn't just try them. You want the Inline Code button, looks like
</>.
1
u/teampingu May 15 '20
For flex I like no margin on the flex box then margin/padding the things inside. This way you can set the width to 25%, 20% for 4/5 boxes respectively and not have to worry about calc or what not.