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 Introduction to HTML and CSS (2016) Adding a New Web Page Write the CSS

H1 background query

Hello, ma'am, you have added the back ground to h1 tag but it's exceeding from the right. How to shorten it so that it only applies to text?

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! The h1 is a block level element by default, which means that it will take up the full width. So when you apply a background, the background color will take up the full width of the parent container, but the text might not be that long.

Keep in mind that this is an introduction to CSS and HTML. If you continue along the path you're on now, you will learn all sorts of neat tricks on how to style things and put them exactly where you want on your page. You will even learn how to make it look different on mobile devices than it does on a desktop so that your mobile users will have a great experience.

Hope this helps! :sparkles:

Thanks

The neat tricks you are talking about will be further in this course or something else.

SRIMUGAN J
PLUS
SRIMUGAN J
Courses Plus Student 5,345 Points

Hi Nishoo,

h1 is a block level element so it takes the full width, if you want to add the background only to its content size, you can simply add any class names to h1 element and make it as inline-block. for eg

<h1 class="heading">Hello World!</h1>

CSS:-

.heading{
  display: inline-block;
  background: #333;
}

Hope this helps

Thanks