Comments on: margin https://css-tricks.com Tips, Tricks, and Techniques on using Cascading Style Sheets. Sat, 14 Oct 2023 04:46:56 +0000 hourly 1 https://wordpress.org/?v=6.4.3 By: Kekeli https://css-tricks.com/almanac/properties/m/margin/#comment-1805883 Sat, 14 Oct 2023 04:46:56 +0000 http://css-tricks.com/?page_id=14069#comment-1805883 This is beautiful

]]>
By: Dan https://css-tricks.com/almanac/properties/m/margin/#comment-1794907 Sat, 12 Mar 2022 00:46:32 +0000 http://css-tricks.com/?page_id=14069#comment-1794907 In reply to Ivy.

Yes, these two are supposed to do the same, because in the first rule set value 0 is used for top and bottom margin while 1.5em is used for left and right margin.

In the second rule set these values are defined explicitly.

Remember the order of values: top right bottom left.

]]>
By: Ivy https://css-tricks.com/almanac/properties/m/margin/#comment-1794870 Mon, 07 Mar 2022 11:40:52 +0000 http://css-tricks.com/?page_id=14069#comment-1794870 Can you please explain to me this paragraph:

“If fewer than four values are set, the missing values are assumed based on the ones that are defined. For example, the following two rule sets would get identical results:

.box {
  margin: 0 1.5em;
}

.box {
  margin: 0 1.5em 0 1.5em;
}

Are these two supposed to do the same? Because that is not correct. Or am I not reading this correctly?

]]>
By: sandeep https://css-tricks.com/almanac/properties/m/margin/#comment-1605748 Mon, 26 Dec 2016 11:08:41 +0000 http://css-tricks.com/?page_id=14069#comment-1605748 I have already listen and implement about “margin” property in css but I didn’t understand about these…
“margin-block-start”, “margin-block-end”, “margin-inline-start”, “margin-inline-end” in css. What are the purpose of these? And can you please show a demo so we can easily understand it. Thanks.

References:
https://developer.mozilla.org/en-US/docs/Web/CSS/Reference
https://developer.mozilla.org/en-US/docs/Web/CSS/margin-block-end

]]>
By: Floyd https://css-tricks.com/almanac/properties/m/margin/#comment-1605465 Wed, 07 Dec 2016 21:20:24 +0000 http://css-tricks.com/?page_id=14069#comment-1605465 In reply to Moath.

Moath, remove the <br> and make the img tags be display:block; and it’ll fix your double margins. Ideally, you wouldn’t margin your image and you would instead margin its wrapper (like if you stuck the image in a <figure>).

]]>
By: Moath https://css-tricks.com/almanac/properties/m/margin/#comment-1601699 Mon, 23 May 2016 19:02:36 +0000 http://css-tricks.com/?page_id=14069#comment-1601699 Very useful tips. Btw, I have tested the collapse margins and I noticed that when I used same elements, it will NOT collapse. Meaning if we take two image tags “<img…”, and apply the same CSS as mentioned in the example given in this article (p, h2 tags), it will not collapse. See examples below:

EXAMPLE-1(NO Collapse):

HTML:

<img id="code-1" src="..."> <br>
<img id="code-2" src="...">

CSS:

#code-1{margin: 0 0 20px 0;}
#code-2{margin: 10px 0 0 0;}

This code above will result in a 30px margin (20+10).

EXAMPLE-2(Collapse- same example given in this article):

HTML:

`<h2>Collapsing Margins</h2>`
`<p>Example text.</p>`

CSS:

h2 {
  margin: 0 0 20px 0;
}

p {
  margin: 10px 0 0 0;
}

This will result in a 20px margin (the higher margin).

Please let me know if I am missing something here. Thank you

]]>
By: Faisal https://css-tricks.com/almanac/properties/m/margin/#comment-1599095 Fri, 15 Jan 2016 20:52:22 +0000 http://css-tricks.com/?page_id=14069#comment-1599095 Very Nice tutorial.

]]>
By: daGo https://css-tricks.com/almanac/properties/m/margin/#comment-1594827 Fri, 22 May 2015 11:01:19 +0000 http://css-tricks.com/?page_id=14069#comment-1594827 In reply to daGo.

Already easy got it.Definitely it was my biggest css ahaha moment, unfortunately I can’t delete this post above, what a shame))

]]>
By: daGo https://css-tricks.com/almanac/properties/m/margin/#comment-1594815 Thu, 21 May 2015 18:34:32 +0000 http://css-tricks.com/?page_id=14069#comment-1594815 Silly question (css comment about margin-right) but answer me please. http://codepen.io/dagolinuxoid/pen/wazPJJ

]]>
By: nick.spiel https://css-tricks.com/almanac/properties/m/margin/#comment-1592650 Fri, 20 Feb 2015 05:43:46 +0000 http://css-tricks.com/?page_id=14069#comment-1592650 “This is helpful in most cases since there is no need to redefine any of the top margins to remove the extra vertical space.”

I always looked at the collapsing margin as a bug. But you can totally rock this to your advantage especially when building flexible theme layouts where the sequence of elements my change.

I can’t believe I have only just realised this…

“A whole new world… A hundred thousand th…”

]]>
By: z https://css-tricks.com/almanac/properties/m/margin/#comment-1586547 Sun, 09 Nov 2014 13:59:39 +0000 http://css-tricks.com/?page_id=14069#comment-1586547 You are wonderful chris.

]]>
By: Daniel https://css-tricks.com/almanac/properties/m/margin/#comment-1585230 Fri, 12 Sep 2014 10:39:46 +0000 http://css-tricks.com/?page_id=14069#comment-1585230 In reply to Ruksun.

I think Ruksun, that it is meant to say “vertical” instead of “horizontal”. If possible that could be changed so as not to confuse a newer designer. :)

“It should also be pointed out that auto is useful only for horizontal centering, and so using auto for top and bottom margins will not center an element vertically, which can be confusing for beginners.”

]]>
By: Julia https://css-tricks.com/almanac/properties/m/margin/#comment-1581470 Wed, 21 May 2014 10:21:59 +0000 http://css-tricks.com/?page_id=14069#comment-1581470 In reply to Livia.

Livia, just giving two values will result in the first value being used for top and bottom and the second value being used for left and right. If you just set one value it will be used on all (top, bottom, left, right). In both cases margin values that are set before, will be overwritten.

More information about margin on mozilla developer network

]]>
By: Livia https://css-tricks.com/almanac/properties/m/margin/#comment-1417479 Sat, 22 Mar 2014 20:00:08 +0000 http://css-tricks.com/?page_id=14069#comment-1417479 Since the order of the margin selector values is top > right > bottom > left, why does placing 0 auto make top + bottom 0 and left + right auto? Shouldn’t that keep bottom at whatever default value (assuming it’s not 0)?

]]>
By: Ruksun https://css-tricks.com/almanac/properties/m/margin/#comment-574210 Sat, 05 Oct 2013 16:07:10 +0000 http://css-tricks.com/?page_id=14069#comment-574210 And how is this-“It should also be pointed out that auto is useful only for horizontal centering, and so using auto for top and bottom margins will not center an element horizontally, which can be confusing for beginners.”, not confusing to beginners?

]]>