CSS to select/style first word

后端 未结 11 1907
礼貌的吻别
礼貌的吻别 2020-11-22 13:30

This one has me kind of stumped. I want to make the first word of all the paragraphs in my #content div at 14pt instead of the default for the paragraphs (12pt). Is there a

11条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 13:55

    Pure CSS solution:

    Use the :first-line pseudo-class.

    display:block;
    Width:40-100px; /* just enough for one word, depends on font size */
    Overflow:visible; /* so longer words don't get clipped.*/
    float:left; /* so it will flow with the paragraph. */
    position:relative; /* for typeset adjustments. */
    

    Didn't test that. Pretty sure it will work fine for you tho. I've applied block rules to pseudo-classes before. You might be stuck with a fixed width for every first word, so text-align:center; and give it a nice background or something to deal with the negative space.

    Hope that works for you. :)

    -Motekye

提交回复
热议问题