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

HTML How to Make a Website Styling Web Pages and Navigation Style the Portfolio

Forest Forest
Forest Forest
529 Points

How to control the padding above / under the paragraph of the list?

I am watching the "Style the Portfolio" session of " How to make a website", and I saw the teacher is managing the padding of the paragraph under the image by styling #gallery l a p {}, in there, setting padding as 5%. I am just wondering the 5% seems to give space before the text, however, how to control the padding above and under the texts? I feel like even without doing anything, there is already some space above / behind the texts.

Remember that the box-model works clockwise(top,right,bottom,left). Try playing around with padding to get your desired outcome. For a good reference on how the box-model works, check out this link

1 Answer

Mark Pryce
Mark Pryce
8,804 Points

When defining a padding rule you can use multiple ways remember the values always work clockwise starting from the top.

h1 {
   padding: 5%; 

/* defined for all sides, top, right, bottom & left */
}

h1 {
   padding: 5% 10%;

/* 5% = top and bottom 10% = right and left */
}

h1 {
   padding: 5% 10% 3%;

/* 5% applies to top side, 10% applies to left and right, 3% applies to the bottom */
}

h1 {
   padding: 1% 2% 3% 4%;

/* 1% = top,   2% = right,   3% = bottom, 4% = left*/
}

Hope this clears it up a bit, happy coding!

Edit: As frontend mentioned the best way to see it is to fiddle around with the values, also don't mistake padding for margin they are different! ;)