Edison
Edison

Reputation: 4281

display:block property usage

I have read many articles on the display:block property.What it does it make your element behave like paragraph tag or block element to be exact.My worry is that then why don't we just use paragraph tag there since it already is a block level element and we can also use id(once) and class(many times) attributes on it.Similarly on observing many CSS structure i found that on first or second line following is done more often than not.

header,section,nav,figure,..etc{
display:block;
}

Same question why don't just use paragraph tag and useful nomenclature for figures,nav,footer and header inside

.Following is my solution

<p class="mainNavigation">   </p>
<p class="MainNavfigures">   </p>
<p class="footer">           </p>
<p class="bodyContent">      </p>

So the whole argument is this "Why to invent more tags when P was already there for us?"

Upvotes: 1

Views: 57

Answers (2)

Faust
Faust

Reputation: 15394

Semantics:

  • mainNavigation is not a paragraph
  • MainNavfigures is not a paragraph
  • footer is not a paragraph
  • bodyContent is likely one or more paragraphs, with other things too.

...but you've told us in your code that each of these items is a paragraph.

Machines (search engines!) reading code won't know what your class-names mean and will not know to handle your content accordingly.

Humans reading your code will be understandably confused as well.

Upvotes: 2

Guffa
Guffa

Reputation: 700212

Yes, feel free to use a tag that already behaves as close as possible to what you want, unless there is a reason to use a different tag. A div tag is often more natural to use as a general-purpose block element rather than p, as the paragraph has margin by default.

Sometimes, there isn't a tag available with both the style and functionality that you need. For example, if you want a link that is a block tag, that doesn't exist. You use an a tag and style it with display:block.

For SEO reasons, you should use some specific elements for certain things. The web crawlers simply expect to find some things in certain elements. There should for example be a h1 tag on the page that contains a headline describing the contents. The h1 element is a block element with large and bold text, and a lot of margin, so often you want to style it to fit into the layout.

Upvotes: 1

Related Questions