- 1

How do i change the style of the first word of a string?

For example: <p id="string">hello world</p> what should i do with the css code in order to change the style of the first word of the string "hello world"?

28th Nov 2016, 1:53 PM
Foxtrot Pipe
Foxtrot Pipe - avatar
10 Respuestas
+ 7
html <p id="string"> <span id="yourID">hello </span>world </p> css span#yourID { YOUR STYLE }
28th Nov 2016, 2:27 PM
ManuCarv
+ 1
What you are looking for is a pseudo-element that doesn't exist. There are :first-letter and :first-line, but no :first-word. To style the first word of a paragraph, you can use some jquery code. Here’s how you can accomplish it: $('p').each(function() { var word = $(this).html(); var index = word.indexOf(' '); if(index == -1) { index = word.length; } $(this).html('<span class="first-word">' + word.substring(0, index) + '</span>' + word.substring(index, word.length)); }); And now you can simply use the .first-word class to style the first word of each paragraph: .first-word {font-style:italic;}
28th Nov 2016, 7:29 PM
Thiago Santos
Thiago Santos - avatar
+ 1
The best thing for you is to go and learn css3 And HTML5 and all your answers will be answered
26th Dec 2016, 11:43 PM
Cele Prince
Cele Prince - avatar
- 1
p::first-letter {      font-size: 200%;     color: #8A2BE2; }
4th Dec 2016, 11:26 PM
Alex Qo
Alex Qo - avatar