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 trial
Rikki Collier
2,708 PointsParagraph text not recognising caption - masked by caption background
Hi Treehouse
Run into a bit of a tricky one today. I have a container in which I have a figcaption which encapsulates my h2. The figcaption itself has a background in it (which provides a nicer aesthetic than a simple colour, I think)
The HTML looks like this.
'<div class="container clearfix">
<div class="primary col">
<figcaption class="welcomecaption"><h2>Welcome</h2></figcaption>
<p class="welcometext">Lorem ipsum dolor sit amet, suspendisse facilisi ridiculus in nonummy diam, quis proin placerat, fringilla orci donec, blandit sit.</p>
</div>
Now.. the paragraph text within the "primary col" is not clearing the figcaption. In essence it is not recognising the space that the caption takes up, and thus some of the p text appears to be masked underneath the caption.
Here is a screenshot to illustrate what I mean: http://imgur.com/wwqcGU0
And another screenshot when the background image is not part of the caption: http://imgur.com/a/hdi7C - You can see how the p text is not honouring the caption.
The CSS looks like this:
.welcomecaption {
height: 35px;
background-image: url("../img/welcome.jpg");
background-size: cover;
width: 100%;
border-top-left-radius: 8px;
border-top-right-radius: 8px;
position: absolute;
top: 0; }
I've tried playing with the margins of both the paragraph text and the figcaption AND the h2. None of it seems to work. And it's not something I can work out from the course video as that only deals with putting a caption on top of an image, not within a container that has paragraph text.
If anyone could help me with this I'd be very grateful!
Thanks,
Rik
p.s. If any of this needs more clarification please let me know
4 Answers
webdesignertroy
Front End Web Development Techdegree Graduate 14,718 PointsI would have to see the entire project to really help you. Mostly the position: absolute declaration within your welcomecaption class is doing you in. Because of the absolute value, .welcomcaption is not set relatively in the DOM. For all intents and purposes, it's floating. Other elements will not respect your spacing.
Either, you have to change your current position: absolute declaration to position: relative or your current top: 0 declaration to top: inherit (or get rid of it). Without seeing the entire project, that's the only advice I can give.
Daniel Gonzalez
22,105 PointsHi Rikki,
The figcaption tag is mainly used to include the caption text of an image with the <img>and <figcaption> tag nested inside a <figure> tag. Would it be easier to wrap your <h2> tag inside a <div> tag and apply the .welcomecaption styles?
Rikki Collier
2,708 PointsThank you both your quick answers.
@webdesignertroy: I changed the position value on the .welcomecaption from 'absolute' to 'relative' and that did the job nicely! Thank you very much!
@Daniel - I did not get a chance to try out your method as Troy's suggestion proved to be quick and painless. Thank you for the response though.
What a great community.
Rikki Collier
2,708 PointsOn second thoughts, and coming back to your point Daniel, I may wrap the <h2> text inside a <div> as inputting "text-align: center" to the .welcomecaption class does not re-align the text. I guess this is because the text is taking on the relative position value of its parent container (.welcomecaption) and that overrides any text-align value.
Once again thank you both for your insights.
Regards,
Rik