Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Apr 2005
    Posts
    315
    Thanks
    18
    Thanked 2 Times in 2 Posts

    Bold, and italic?

    Before I started using CSS. If I wanted to make the first word in a particular sentence bold or italic, I would use the <b> and <i> tags. Is there a way I can achieve this affect with CSS. When I use <b> or <i> tags, I can't get my page to validate?

    Thanks

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,695
    Thanks
    6
    Thanked 1,011 Times in 984 Posts
    As far as I know b and i are still valid in strict (X)HTML but you can achieve the effect by using semantically neutral span elements and applying styles to these elements through CSS.
    If it's just the first letter that is supposed to be styled you can use the :first-letter pseudo class:
    Code:
    p:first-letter {font-style: oblique;}

  • #3
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,302
    Thanks
    28
    Thanked 276 Times in 270 Posts
    Quote Originally Posted by michael180 View Post
    If I wanted to make the first word in a particular sentence bold or italic, I would use the <b> and <i> tags. Is there a way I can achieve this affect with CSS.
    I don’t think that this is possible with current or planned CSS. You’d have to touch the structural (HTML) markup:

    HTML:
    Code:
    <p><span class="firstWord">Welcome</span> to my world.</p>
    CSS:
    Code:
    span.firstWord { font-weight: bold; font-style: italic; }
    For every complex problem, there is an answer that is clear, simple, and wrong.


  •  

    Posting Permissions

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