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

CSS CSS Layout Basics Controlling Layout with CSS Display Modes Positioning Elements Side-By-Side with Inline Display

Arikaturika Tumojenko
Arikaturika Tumojenko
8,897 Points

Width doesn't apply, left margin does. Why?

Although width, just like margin-left applies horizontally (at least in theory), when it comes to inline elements width has no effect but left-margin does. What's the explanation?

2 Answers

Ryan M
Ryan M
16,203 Points

To add a width to an inline element you need to change its display value to inline-block

.yourlnlineElement {
    display: inline-block;
    width: 200px;
6,762 Points

It's important to know that, when it comes to margins and padding, browsers treat inline elements differently. When an element's display is set to in-line like the items here in the header. The browser will not apply any height and width properties. Or top and bottom margin settings. An inline element will only accept left and right margins and any padding value.

This has been mentioned in this video.

Laly Singh
Laly Singh
2,029 Points

*An inline element will only accept left and right margins and "left and right" padding value