How to select first letter of a paragraph inside a div?
My HTML looks like this
I want the first letter of the first paragraph (F) to be capitalized. This is my CSS attempt
But this is making the first letter of every paragraph larger. I only want the first paragraph targeted. I think I should be using something like
first-child
but I haven't found the right combination of selectors to make it work.19 Replies
.post-content > p:first-child::first-letter
You'd want to do something like this:
Note that it's
:first-letter
not ::first-letter
it should be
::
no?Thanks! Weird, I just got this to work as well
:
div:is()
, just use the base class as your selector.A combination of the ::before pseudo-element and the content property may inject some text at the beginning of the element. In that case, ::first-letter will match the first letter of this generated content.Its tech a element
And yes, pretty much the same as mine, but you chose to
:first-of-type
the paragraph where I targeted the children of the .post-content
classerr quoted the wrong thing but yea mdn says its a element
::
Wait, crap, I was looking at the wrong page
:first-child
is a pseudo-class and ::first-letter
is pseudo-element. /sighThere is a small chance the first child of the div is not a <p> and I only want to affect paragraphs, but I always want to affect the first paragraph.
So in that case, I might not want to use the first child of .post-content
I was going off of what you said the HTML looked like
yes, sorry.
But if it doesn't look like you posted above then no, don't use my code lol
I think I understand what's going on! I need to read up on pseudo classes and pseudo elements, too!
Thank you!!!
I'm not sure how to mark posts as solved!
If you right-click on the actual post in the main list you should have the option to edit tags
or just close it 😄 (had closed it)
But if you close it it won't be marked as SOLVED, @b1mind
There's a ✅ SOLVED tag now
Weird. I can't see how to add a new tag. I will have to read through the Discord docs. I see it got added somehow. Will close the post now, thanks!
Oh, I see the
edit-tags
option when I hover over the post!👍