How do I center an SVG in a div?
SVG is inline by default. Add display: block to it and then margin: auto will work as expected.
SVG is inline by default. Add display: block to it and then margin: auto will work as expected.
Overall just add display:block; to your span. You can leave your html unchanged. Demo You can do it with the following css:
You’re actually seeing the top margin of the #inner element collapse into the top edge of the #outer element, leaving only the #outer margin intact (albeit not shown in your images). The top edges of both boxes are flush against each other because their margins are equal. Here are the relevant points from the W3C … Read more
In this instance, your div elements have been changed from block level elements to inline elements. A typical characteristic of inline elements is that they respect the whitespace in the markup. This explains why a gap of space is generated between the elements. (example) There are a few solutions that can be used to solve this. Method 1 – Remove the whitespace from the markup Example … Read more
If your margin is set on the body, then setting the background color of the html tag should color the margin area http://jsfiddle.net/m3zzb/ Or as dmackerman suggestions, set a margin of 0, but a border of the size you want the margin to be and set the border-color
There are built in classes, namely:
When you have specified a width on the object that you have applied margin: 0 auto to, the object will sit centrally within it’s parent container. Specifying auto as the second parameter basically tells the browser to automatically determine the left and right margins itself, which it does by setting them equally. It guarantees that the left and right margins will … Read more
TL;DR: By default I use margin everywhere, except when I have a border or background and want to increase the space inside that visible box. To me, the biggest difference between padding and margin is that vertical margins auto-collapse, and padding doesn’t. Consider two elements one above the other each with padding of 1em. This padding is … Read more