I am trying to understand image sprites on CSS, and one line of code looks like this.
#navlist li, #navlist a{height:44px;display:block;}
I am just wondering what effect does display:block has on "a", I know that it is for the "a" tag since the link won't work if I removed "a" and conversely if I removed "display:block", I'm just wondering why it should be "display:block".
To make the inline element (a, span etc) to behave like a box model element (div, p, h1 etc), in other words, to make the
a
tag behave like adiv
tag.Inline elements can live side by side on the same line, for example if you write
they will appear like Link1 Link2 but box model elements can't live in the same line, for example, if you write something like
they will appear like
Both divs will occupy the whole space around them (even if they are smaller in width). In a list, for example,
If the list width is
300px
then the a tag will not cover the full width of the li's width because by default thea
tag isinline
and usingdisplay:block
will make thea
element to occupy the full width of theli
, even if it's not that wide.There are more to say about this, I've just gave you an example, you should read more. Check this link and also Check this example.
The w3schools explanation for
display:block
is as fallowThe element is displayed as a block-level element (like paragraphs and headers)
and you can check the display behavior herepractically mostly we use
display:block
in four situationsdiaply:none
anddisplay:block
But link functionality doesn't have any relationship with the
display
orCSS
, link showld work interdependently, CSS wrote for the anchor tag, just for style the link.here is some more details about
display
https://developer.mozilla.org/en-US/docs/Web/CSS/display