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 trialElena Paraschiv
9,938 Points::first-line and text-indent
I am trying to make only every first line of the paragraph after each h3 indent, but does not seem to work Imgur
this is my code :
<div class="main supporting" id="zen-supporting" role="main">
<div class="explanation" id="zen-explanation" role="article">
<h3>So What is This About?</h3>
<p>There is a continuing need to show the power of <abbr title="Cascading Style Sheets">CSS</abbr>. The Zen Garden aims to excite, inspire, and encourage participation. To begin, view some of the existing designs in the list. Clicking on any one will load the style sheet into this very page. The <abbr title="HyperText Markup Language">HTML</abbr> remains the same, the only thing that has changed is the external <abbr title="Cascading Style Sheets">CSS</abbr> file. Yes, really.</p>
<p><abbr title="Cascading Style Sheets">CSS</abbr> allows complete and total control over the style of a hypertext document. The only way this can be illustrated in a way that gets people excited is by demonstrating what it can truly be, once the reins are placed in the hands of those able to create beauty from structure. Designers and coders alike have contributed to the beauty of the web; we can always push it further.</p>
</div>
<div class="participation" id="zen-participation" role="article">
<h3>Participation</h3>
<p>Strong visual design has always been our focus. You are modifying this page, so strong <abbr title="Cascading Style Sheets">CSS</abbr> skills are necessary too, but the example files are commented well enough that even <abbr title="Cascading Style Sheets">CSS</abbr> novices can use them as starting points. Please see the <a href="http://www.mezzoblue.com/zengarden/resources/" title="A listing of CSS-related resources"><abbr title="Cascading Style Sheets">CSS</abbr> Resource Guide</a> for advanced tutorials and tips on working with <abbr title="Cascading Style Sheets">CSS</abbr>.</p>
<p>You may modify the style sheet in any way you wish, but not the <abbr title="HyperText Markup Language">HTML</abbr>. This may seem daunting at first if you’ve never worked this way before, but follow the listed links to learn more, and use the sample files as a guide.</p>
<p>Download the sample <a href="/examples/index" title="This page's source HTML code, not to be modified.">HTML</a> and <a href="/examples/style.css" title="This page's sample CSS, the file you may modify.">CSS</a> to work on a copy locally. Once you have completed your masterpiece (and please, don’t submit half-finished work) upload your <abbr title="Cascading Style Sheets">CSS</abbr> file to a web server under your control. <a href="http://www.mezzoblue.com/zengarden/submit/" title="Use the contact form to send us your CSS file">Send us a link</a> to an archive of that file and all associated assets, and if we choose to use it we will download it and place it on our server.</p>
</div>
<div class="benefits" id="zen-benefits" role="article">
<h3>Benefits</h3>
<p>Why participate? For recognition, inspiration, and a resource we can all refer to showing people how amazing <abbr title="Cascading Style Sheets">CSS</abbr> really can be. This site serves as equal parts inspiration for those working on the web today, learning tool for those who will be tomorrow, and gallery of future techniques we can all look forward to.</p>
</div>
h3+p::first-line{
background: yellow;
text-indent:2em;
}
4 Answers
Jacob Mishkin
23,118 PointsI would suggest instead of using the pseudo class of :first-line, I would make the div a block-level element and use the selector text-indent. The problem is that first-line only works with fonts, background effects and nothing else. you can target the first line of the p tags, if you make the div a block-level element and use that selector. Here are the docs on text-indent and :first-line:
I hope this helps.
Elena Paraschiv
9,938 PointsIt helps if I indent all the p in the div, but I want to indent just the first paragraph inside every divs. You can see there are more p .
Jacob Mishkin
23,118 PointsThe first thing I thought of is to create a class for your first p tags, then use that class to style that p tag, or you could see if nth-of-type or nth-child will work. I believe nth-of-type should do it.
Milutin Jovkovic
2,614 PointsI think you need just this
p { background: yellow; text-indent:2em; }
Milutin Jovkovic
2,614 Pointsand put class at first paragraphs..
Elena Paraschiv
9,938 Pointsworked like a charm. Thanks Jacob!
Jacob Mishkin
23,118 PointsAwesome! nth-of-type work? or did you go the way of the class?
Johnathan Mercier
5,527 PointsJohnathan Mercier
5,527 PointsHi, unfortunately text-indent and margin-left can not be applied to the first-line pseudo-class. Your best option is to apply a class to each of the first p tags like this. Hope this helps