css bold first word

后端 未结 5 1896
鱼传尺愫
鱼传尺愫 2020-12-06 16:48

How can I bold the first word of sentence using CSS selectors and is this a good/bad way to do this with respects to browser comparability?

code:

  &         


        
相关标签:
5条回答
  • 2020-12-06 16:56

    just put the first word in a strong tag.

    <h1><strong>This</strong> is how you do it simply.</h1>
    

    Here is the JS Fiddle

    0 讨论(0)
  • 2020-12-06 17:02

    The current CSS selectors do now allow this.

    So I change my approach to bold the first line.

    HTML

    <h2>this<br> is a sentence</h2>
    

    CSS

    h2::first-line{
       font-weight: bold;
    }
    
    0 讨论(0)
  • 2020-12-06 17:07

    There is no ::first-word pseudo-element in CSS; you'll have to wrap the first word in an extra element and then select that.

    0 讨论(0)
  • 2020-12-06 17:11

    I have put the word between <b>First</b>

    0 讨论(0)
  • 2020-12-06 17:12

    Use Span class

    So creat a class called bold and wrap first word in the class.

    .bold {
    font-weight:bold;
    }
    

    Then

    <h2><span class="bold">the</span> brown fox</h2>
    
    0 讨论(0)
提交回复
热议问题