Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSAMUEL LAWRENCE
Courses Plus Student 8,447 PointsWhy is my first letter black and not bold and the bottom margin is bigger than the right margin?
Hi guys, I checked the forum and didn't see any questions relating to this, so I don't know if this is just happening to me. Did anyone else have the problem where the first letter is black it's not bold and there seems to be a bigger margin on the bottom, pushing the next line of text all the way down. making it look really bad? I entered the code in codepen and the same thing is happening. When I removed the float: left. it became blue and bold but then it went back to the top of the line and the rest of the text did not wrap around it. When I replaced the float: left. it became black again with the irregular bottom margin. here is the code. What am I missing here?
<!DOCTYPE html>
<html>
<head>
<title> Pseudo-Elements</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<p class="intro">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nullam
lobortis elit id sem placerat sagit.
</p>
</body>
</html>
.intro::first-line {
color: royalblue;
font-weight: bold;
font-size: 32px;
}
.intro::first-letter {
float: left;
margin: 10px 10px 0 0;
padding: 5px 10px;
background: #e0e0e0;
font-size: 100px;
line-height: 1;
}
Oh by the way I noticed that the problem with the margin is that. In the video Guil wrote margin: 10px 10px; but when I added a bottom and left value of 0 0 it fixed the marging problem but the text was still black and in the video it was blue, and also when I comment out the float property, it turns blue and the font is also not bold like in the video or when I removed the float property. Why is that?
20 Answers
Jason Anello
Courses Plus Student 94,610 PointsHi Samuel,
This appears to be a bug in firefox. ::first-letter
does not correctly inherit styles from ::first-line
when ::first-letter
is floated.
I was able to find this bug report: https://bugzilla.mozilla.org/show_bug.cgi?id=13610
I thought it was odd but that was the only link I could find about this. I imagine that this is not affecting a lot of people.
If you apply the color and bold styles again to first-letter then you should get the expected results.
Here's a codepen demo where I did that: http://codepen.io/anon/pen/YPPrVz
However, this is not desirable to repeat styles in case you need to change them later. If the color royalblue
needed to be changed then you have 2 spots to change it in.
A possible workaround you can use until this bug is fixed is to group the 2 selectors like this:
.intro::first-line {
font-size: 32px;
}
/* Workaround for firefox since ::first-letter doesn't inherit styles from ::first-line when floated */
.intro::first-line,
.intro::first-letter {
color: royalblue;
font-weight: bold;
}
.intro::first-letter {
float: left;
margin: 10px 10px 0 0;
padding: 5px 10px;
background: #e0e0e0;
font-size: 100px;
line-height: 1;
}
This way you don't have repeated style declarations as shown in the codepen demo and you've worked around the firefox bug.
Jonathan Grieve
Treehouse Moderator 91,253 PointsTry explicitly setting the font-weight and colour in your element selectors. These are special kinds of selector elements and it could be they're just not inheriting styles from parent elements as others do. :-)
SAMUEL LAWRENCE
Courses Plus Student 8,447 PointsHi thanks for your reply. Unfortunately that didn't work. It actually got smaller and lost the float: left property all together and it got smaller.
.intro::first-line {
color: royalblue;
font-weight: bold;
font-size: 32px;
}
.intro::first-letter {
float: left;
margin: 10px 10px 0 0;
padding: 5px 10px;
background: #e0e0e0;
font-size: 100px;
line-height: 1;
font-weight: bold;
font-size: 32px;
}
Jonathan Grieve
Treehouse Moderator 91,253 PointsIt is odd.
short of maybe trying p.intro:first-letter, so adding p to your CSS selectors I'm not sure what else to suggest. Browser support is top notch for these kinds of selectors.
What if you tried with only one colon : instead of the 2? What kind of effect does that have? (last resort, here)
Wayne Priestley
19,579 PointsHi Samuel,
This is what i get from your code in code pen.
I just need to get my head around what is wrong here, do you want the L to be higher up?
Or is it that you want the text under the first line to be blue too?
Sorry that I'm not completely getting your explanation.
Jonathan Grieve
Treehouse Moderator 91,253 PointsThat's the effect he wants but it seems like he's not getting it for whatever reason. :-)
Wayne Priestley
19,579 PointsThats what I get using Samuels EXACT code in code pen in my Safari browser.
SAMUEL LAWRENCE
Courses Plus Student 8,447 PointsHi Jonathan, I tried what you suggested I'm getting the same results. Wayne just replied and he is getting the effect you're supposed to get but he doesn't understand my explanation so I'm going to try and explain better. this is the new code u suggested.
p.intro:first-letter {
float: left;
margin: 10px 10px 0 0;
padding: 5px 10px;
background: #e0e0e0;
font-size: 100px;
line-height: 1;
font-weight: bold;
font-size: 32px;
}
Wayne Priestley
19,579 PointsHi Samuel,
I did understand your explanation, but then i used your code in code pen and it seemed to be okay so i thought you were looking for something other than what i got.
Which browser are you using?
Jonathan Grieve
Treehouse Moderator 91,253 PointsYup that just selects the element a little more specifically. The one colon is an older version for CSS2 so I'm sorry but that won't work. I'm at a loss though as to why the code you originally supplied though doesn't work
SAMUEL LAWRENCE
Courses Plus Student 8,447 PointsHi Wayne, thanks for the reply. The effect you have in the paragraph you posted is exactly the result I'm trying to achieve. I followed the code Guil used exactly. But I'm not getting that effect. I still don't understand how to post images otherwise I would send you an image of the results I'm getting. But the results you have up top, that's exactly how it's supposed to look like in the video, but for some odd reason I'm getting a black L which isn't bold or blue and irregular margin. As you can see from the code I pasted above. I'm not sure what's wrong and as Guil said pseudo-elements and pseudo-classes have excellent browser support.
SAMUEL LAWRENCE
Courses Plus Student 8,447 PointsI also entered this in code pen and I'm getting the same thing as on my laptop browser. I'm using firefox.
Jason Anello
Courses Plus Student 94,610 PointsHi Samuel,
It could help if you save and post the codepen demo link. Then we should be able to see what you're seeing.
SAMUEL LAWRENCE
Courses Plus Student 8,447 PointsNo that's exactly what I want. But honestly it isn't happening. Can you please explain to me how to post images. I read the markdown cheatsheet but I still don't get it.
Jonathan Grieve
Treehouse Moderator 91,253 PointsIt's a little like doing it in HTML
![alt text](/path/to/img.jpg "Title")
So give altnerative text in square brackets and the provide a file path to your image. I think you have to put an image on a web server
SAMUEL LAWRENCE
Courses Plus Student 8,447 Pointsoh, I C. You can't upload the image directly from your computer?
Jonathan Grieve
Treehouse Moderator 91,253 PointsNot as far as i can see.
Wayne Priestley
19,579 PointsWell thats your code I'm using so you got it right.
I posted the image using dropbox, it takes a bit of editing but ill try to explain it here.
Here is the link generated by dropbox for the image.
https://www.dropbox.com/s/i8eylka2yj5odp2/Lorem-img.png?dl=0
and here is the code edited so i can insert it (removed text from beginning and end)
dropbox.com/s/i8eylka2yj5odp2/Lorem-img.png
here is the code i wrapped it in.
![alt text](https://dl.YOUR IMAGE CODE GOES HERE "Title")
so the end result is
![alt text](https://dl.dropbox.com/s/i8eylka2yj5odp2/Lorem-img.png "Title")
Hope this helps.
SAMUEL LAWRENCE
Courses Plus Student 8,447 PointsHope this works
Wayne Priestley
19,579 PointsYep, thats messed up,
Like i said before, i used your original code that you put in your first post and it works for me using Safari, i don't have Firefox installed to check it, but ill try Chrome and see how it looks.
SAMUEL LAWRENCE
Courses Plus Student 8,447 PointsAnd this is when I use the same code as Guil
Wayne Priestley
19,579 PointsYour Original code works in Chrome too Samuel.
SAMUEL LAWRENCE
Courses Plus Student 8,447 PointsYes you're right it works in safari. It seems it's only in firefox it's not working. Any idea why? I thought firefox should have top notch capabilities? for example most of the things that don't render properly in safari and chrome works perfectly in firefox. This is new. Anyway I guess it's not a problem with the code, just the browser. Well thanks guys for your patience and help. You guys rock.
Wayne Priestley
19,579 PointsI have no idea mate why it won't render in Firefox, like you said, I would have thought Firefox would be no problem.
Just as an idea, try changing the font you used to something common and see if its a rendering problem that Firefox has with the font you used.
SAMUEL LAWRENCE
Courses Plus Student 8,447 PointsNo, unfortunately it's not the font. I tried 'Open Sans' and 'Gill Sans'. same thing in firefox. but works fine in safari and chrome.. Thanks again buddy. By the way one more thing, could you ask around and see if anyone else is having the same issue with the exact code on their firefox? Thanks.
SAMUEL LAWRENCE
Courses Plus Student 8,447 PointsHi Jason, thanks for your help man. This was really helpful. You rock dude. Thanks also for showing me the work around. Sometimes because we're new to this I guess we don't use our heads enough. Because this grouping technique was thought to us a few lessons back. Thanks again dude.
sam
Abby Hoover
1,167 PointsI should read these questions more often. I struggled with this exact same issue for about 15 minutes trying to figure out what I was doing wrong. Then I come here and see all you nice folks have got it figured out.
SAMUEL LAWRENCE
Courses Plus Student 8,447 PointsYes dude. The treehouse forum is freaking awesome, not only do you get a bunch of masters to help you with a problem, but also others who have similar problems who have figured it out to help you, and what's even more awesome, you don't have to wait a day or two, you get a response almost immediately dude. freaking awesome. treehouse. seriously. Most helpful forum I've ever been in. I didn't particularly like forums before, now I'm beginning to.
Abby Hoover
1,167 PointsIt really is a pretty cool learning experience. I just wish that the instructors would pause a bit in the videos before switching over to the browser window. It would make it easier to follow along.
Just curious but what is China like?
SAMUEL LAWRENCE
Courses Plus Student 8,447 PointsWell that's not really necessary since you can download the project files. I always do, I don't copy what's in it but if there is something I don't get the first time I can go over it slowly in the files, plus you can download the videos and watch them as many times as you like you can also pause. I think it's cool. What I would like is if they did a better job at verbally explaining how some of the concepts work, instead of simply showing. It's always good to see but sometimes you don't always understand what you see and because of that can't use it properly, because you don't get how to use it, or when is it best to use it. You get what I mean? The tutor Nick Petite does a very good job of explaining the concept verbally first then showing you how it works. Some of the others just show you then do a very poor job of explaining how it actually works. That sucks.
Dominic Hudson
1,916 PointsI had to fix it with the following code to help it to work in Firefox. I always use Chrome, but I watch Treehouse in Chrome along with all my other open tabs, and preview the code from Dreamweaver, and in Firefox Browser, and have noticed a few bugs that pop up now and then in these tutorials.
/* Pseudo-elements */
.intro::first-line {
color: royalblue;
font-weight: bold;
font-size: 32px;
}
.intro::first-letter {
float: left;
margin: 10px 10px 0 0;
padding: 5px 10px;
background: #e0e0e0;
color: royalblue;
font-weight: bold;
font-size: 100px;
line-height: 1;
}
Jason Anello
Courses Plus Student 94,610 PointsHi Dominic,
You're on the right track here. You've discovered that whatever styles you want ::first-letter
to inherit must be explicitly set again because the inheritance is broken in firefox.
However, you now have styles duplicated. You can check my answer for a way to avoid that style duplication if you're interested.