The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Is it possible to style this?
Terminator
post May 8 2015, 04:53 PM
Post #1


Advanced Member
****

Group: Members
Posts: 218
Joined: 19-March 15
Member No.: 22,398



For an unordered list, is it possible to add a CSS style to change the color of the entire first word including the colon? But keep the whole word that is after the colon the default font color?

example:

<ul class="list1">
<li>Question: Answer</li>
<li>Question: Answer</li>
<li>Question: Answer</li>
</ul>

Basically I would want "Question:" to be an orange color, the entire word including the colon :

Then "Answer" would stay as the default font color

I know about :first-of-type and ::first-line, etc, but this is usually going to be on one line.

I was trying to avoid doing it this way:

<ul class="list1">
<li><mark class="orange">Question:</mark> Answer</li>
<li><mark class="orange">Question:</mark> Answer</li>
<li><mark class="orange">Question:</mark> Answer</li>
</ul>

thanks

This post has been edited by Terminator: May 8 2015, 05:02 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post May 8 2015, 05:52 PM
Post #2


.
********

Group: WDG Moderators
Posts: 9,656
Joined: 10-August 06
Member No.: 7



QUOTE(Terminator @ May 8 2015, 11:53 PM) *

For an unordered list, is it possible to add a CSS style to change the color of the entire first word including the colon? But keep the whole word that is after the colon the default font color?

Not that I know of.

QUOTE
I was trying to avoid doing it this way:

You could use a definition list instead, that way the markup becomes a little more semantically meaningful as well. See http://www.w3.org/TR/html5/grouping-conten...#the-dl-element
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post May 8 2015, 06:22 PM
Post #3


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



There are JavaScript solutions to work around the lack of a :first-word pseudo element. Here's one, but it's oldish. There's problably newer ones around. Not saying this script is bad, I just don't know how it fares in newer browsers.

http://www.dynamicsitesolutions.com/javasc...-word-selector/
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 24th April 2024 - 10:51 PM