SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru
    Join Date
    Jul 2003
    Location
    england
    Posts
    823
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question Attribute Selector for Specific Content

    I haven't found an answer to my research regarding using Attribute Selectors to format text based upon a phrase. I know that this can be done with PHP/jQuery, but I'm wondering if it's even possible to do so with CSS alone without applying a 'class' or 'span' to the specific phrase?

    For example, for every word ('pulley') within a paragraph I would like to format it using CSS. Is there any way to do this without adding classes/spans?

  2. #2
    Community Advisor silver trophybronze trophy
    dresden_phoenix's Avatar
    Join Date
    Jun 2008
    Location
    Madison, WI
    Posts
    2,819
    Mentioned
    34 Post(s)
    Tagged
    2 Thread(s)
    The very premise of CSS is to SEPARATE content from style. So the answer is no, CSS cannot target "content"

    Additionally, there is a SEMANTIC concern to your question. If you are styling some content fora REASON.. you should use the PROPER TAG that indicates the reason. Example , if you are placing emphasis on the word "pulley" you NEED to use an EM tag. If you just are styling for purely aesthetic reasons then you would use a SPAN.

    LAZY TIP, B and I tags also have no semantic meaning so if you feel you feel to lazy to type SPAN you can use I or B w/o affecting semantics ( just rember that the text will be bold or italics with CSS off)

    hope that helps

  3. #3
    SitePoint Guru
    Join Date
    Jul 2003
    Location
    england
    Posts
    823
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The idea is to style a particular phrase throughout the whole site without having to use tags on every single page the phrase is being used. So I guess going with jQuery or PHP would have to do the trick.

  4. #4
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,046
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    With JavaScript it would be quite simple (although you would still be injecting the tags into the page).
    Let me know if you need any help.

  5. #5
    Community Advisor silver trophybronze trophy
    dresden_phoenix's Avatar
    Join Date
    Jun 2008
    Location
    Madison, WI
    Posts
    2,819
    Mentioned
    34 Post(s)
    Tagged
    2 Thread(s)
    CSS is not meant for this use.
    The idea is to style a particular phrase throughout the whole site without having to use tags on every single page the phrase is being used. So I guess going with jQuery or PHP would have to do the trick.
    Am going to guess that this is because you are building the site off a CMS and do not want to input the tags at data entry, other wise ti really doesnt make much sense.

    As Pullo said, .js (or jQuery) could accomplish this ( by searching the content and then wrapping the tags around it). So in essence you are still adding tags.. just the hard way.

    I would advice to use PHP , instead, to search/ replace phrase with tags around it during output. Plus that way your styling would remain intact if users have .js turned off, not to mention (again) that proper tag usage has SEO/semantic benefits.

  6. #6
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,117
    Mentioned
    28 Post(s)
    Tagged
    2 Thread(s)
    The very premise of CSS is to SEPARATE content from style. So the answer is no, CSS cannot target "content"
    You're right but CSS can generate content and use HTML attributes so the lines are starting to blur.

    I'd opt for JavaSscript for something like this.


Tags for this Thread

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
  •