SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Location
    California
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Text in <div> tags

    I was watching a CSS video from lynda.com and the instructor showed this:

    HTML Code:
    <div id="mainBanner">Welcome to the so and so Museum</div>
    What caught my attention was that he had text inside of a <div> tag. I know that this will render correctly, but is it semantically correct? Shouldn't text always be wrapped inside of a tag that denotes text, like a <p> tag?

    What do you guys think? Have you ever placed text inside of a <div> tag?

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,097
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    Have you ever placed text inside of a <div> tag?
    Yep, it's perfectly fine, and often a good idea. Small bits of text often are not a paragraph, anyhow. I find this setup is good for things like a logo.
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."

  3. #3
    Community Advisor silver trophybronze trophy
    dresden_phoenix's Avatar
    Join Date
    Jun 2008
    Location
    Madison, WI
    Posts
    2,791
    Mentioned
    34 Post(s)
    Tagged
    2 Thread(s)
    Echoing what ralph just said; It is perfectly in fact THE semantic way for a myriad of situations: logos, mottos , single lines of text( tho I feel that that could go either way), etc.

    Also, consider the fact that it's not valid place form elements directly on a form ( and that sometimes you don't need/want to do use a fieldset). It is in fact preferable to use a P instead of a DIV in that case as well.

  4. #4
    om nom nom nom Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,266
    Mentioned
    50 Post(s)
    Tagged
    2 Thread(s)
    It is in fact preferable to use a P instead of a DIV in that case as well.
    Are label-input pairs a paragraph? Though I notice the original decade-old specs at w3.org still show p's in forms, at least a div is specifically saying, semantically, that there are no semantics to that tag at all.

    Like Matt I'm also uneasy with zero-semantic elements wrapping text fragments. I still often use p's for fragments, falling back to the way some dictionaries are totally okay with paragraph not even needing to be a full sentence.

    When using a div, you're basically saying "I, web developer, need a block element here." Which often is the reason we use divs.

  5. #5
    Robert Wellock silver trophybronze trophy xhtmlcoder's Avatar
    Join Date
    Apr 2002
    Location
    A Maze of Twisty Little Passages
    Posts
    6,316
    Mentioned
    60 Post(s)
    Tagged
    0 Thread(s)
    No, it's not really preferable to place P in place of fieldset in a normative language. Actually the W3C had other such silliness in their 4.01 form examples, for example: <FORM action="..." method="post"><P><FIELDSET><LEGEND>Personal Information</LEGEND> I don't think they thought it through enough. Only in the loosest sense "some" data would fit the P.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •