www.webdeveloper.com
Results 1 to 5 of 5

Thread: firstchild element?

  1. #1
    Join Date
    Aug 2006
    Location
    New York/North Carolina
    Posts
    238

    firstchild element?

    I want to use css to style the first word of every <p> tag within a div that has a specific id. How can I do this? It is a pretty big document and I don't want to have to go through for each <p> and put a span with a style in it.

  2. #2
    Join Date
    Jan 2005
    Location
    Frankfort, KY, USA
    Posts
    6,167
    There are pseudo elements called :before and :after, but they don't work in IE6 (don't know about IE7).

    Take a look: http://www.w3schools.com/css/css_pseudo_elements.asp

    KDLA

  3. #3
    Join Date
    Aug 2006
    Location
    New York/North Carolina
    Posts
    238
    I don't think that will do it, that will put something before or after the tag, not in the tag. For example say I want to bold and italic the first word of this:

    <p>The first word should be bold and italic</p>

    How can i do that for multiple <p> tags in a very large document (like a glossary of terms A - Z) without having to put a
    <strong><span style="font-style:italic">Content</span></strong> around every word I want to do it to? Can't CSS do that same thing to every first word of a <p> without having to do that?

  4. #4
    Join Date
    Jan 2005
    Location
    Frankfort, KY, USA
    Posts
    6,167
    Yes, you're right. I was thinking of first-letter and/or first-line, which are on the same page as :after and :before.

    I don't think CSS alone can control the appearance of one word. It relies on container tags for the style specifications.

    There might be a javascript alternative, but I doubt it would be any easier than the span method, using a class:
    Code:
    .first {font-weight: bold; font-style: italic}
    Code:
    <p><span class="first">The</span> first word should be bold and italic</p>
    KDLA

  5. #5
    Join Date
    Aug 2006
    Location
    New York/North Carolina
    Posts
    238
    I guess I am going to have to go through word by word , and add a span to each one. My fingers are going to be sore when I am done, lol.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles