Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is is valid to declare an inline element as block?

Tags:

html

css

I passed a style sheet with the following to the W3C validator and it passed:

a {
  display: block;
}

So want to make sure, is it valid markup to use an inline element as a block one? I know it will work but is it valid?

Thanks

like image 703
Michael Samuel Avatar asked Dec 20 '22 05:12

Michael Samuel


2 Answers

Yes, it's completely valid. And useful too.

One small note (since the above answer is very short), this method of styling normally inline elements as block elements is quite common. For example, when creating a horizontal navigation menu from a list, you'll often see <a> elements styled with display:block in order for the links to be able to take up the full width and height of the parent list item.

like image 180
j08691 Avatar answered Feb 02 '23 05:02

j08691


Yes it's valid but also you can use inline-block to use an inline element while keeping the block properties.

like image 21
xShirase Avatar answered Feb 02 '23 04:02

xShirase