/    Sign up×
Community /Pin to ProfileBookmark

firstchild element?

I want to use css to style the first word of every <p> tag within a div that has a specific id. How can I do this? It is a pretty big document and I don’t want to have to go through for each <p> and put a span with a style in it.

to post a comment
CSS

4 Comments(s)

Copy linkTweet thisAlerts:
@KDLADec 15.2006 — There are pseudo elements called :before and :after, but they don't work in IE6 (don't know about IE7).

Take a look: http://www.w3schools.com/css/css_pseudo_elements.asp

KDLA
Copy linkTweet thisAlerts:
@polorboyauthorDec 15.2006 — I don't think that will do it, that will put something before or after the tag, not in the tag. For example say I want to bold and italic the first word of this:

<p>[I][B]The[/B][/I] first word should be bold and italic</p>

How can i do that for multiple <p> tags in a very large document (like a glossary of terms A - Z) without having to put a

<strong><span style="font-style:italic">Content</span></strong> around every word I want to do it to? Can't CSS do that same thing to every first word of a <p> without having to do that?
Copy linkTweet thisAlerts:
@KDLADec 15.2006 — Yes, you're right. I was thinking of first-letter and/or first-line, which are on the same page as :after and :before.

I don't think CSS alone can control the appearance of one word. It relies on container tags for the style specifications.

There might be a javascript alternative, but I doubt it would be any easier than the span method, using a class:
<i>
</i>.first {font-weight: bold; font-style: italic}

<i>
</i>&lt;p&gt;&lt;span class="first"&gt;The&lt;/span&gt; first word should be bold and italic&lt;/p&gt;

KDLA
Copy linkTweet thisAlerts:
@polorboyauthorDec 15.2006 — I guess I am going to have to go through word by word ? , and add a span to each one. My fingers are going to be sore when I am done, lol.
×

Success!

Help @polorboy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...