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

I have 5 list elements, want 4 to view and last to be out of picture and scroll to.

Hi! I have a manubar(nav, ul, li) with 5 list elements. I want 4 of them to view and set the size to 25%. That works. Last element though will jump on new line. I want that to be out of the picture on the right side and I want to be able to scroll to it. Anybody understand what I want and how to do so? i've tried to use overflow properties like overflow-x but that doesn't seem to do the thing. The problem is probably that whe nav is 100% and if li can't be out of that, but how would I achieve what I want?

4 Answers

I'm not sure if you wanted to scroll the whole page horizontally or only the menu. See Robert's answer if you wanted to scroll the whole page.

Here's a codepen demo where you're only scrolling the menu: http://codepen.io/anon/pen/gpjFL

It's the same idea with the percentages, 125% and 20%.

It depends on where you wanted the scrolling to take place.

Yes! Scrolling o the menubar only. Thank you!

Robert Komaromi
Robert Komaromi
11,927 Points

I noticed you used box-sizing instead of calc(% - value) - this is a good idea since box-sizing is better supported and makes the math easier ;)

Robert Komaromi
Robert Komaromi
11,927 Points

Make the container nav with a width of 125% and the child li elements with a width of 20% and floated to the left. This will ensure the last element is always off the screen and must be scrolled to. See my demo on Plunker here. Is this what you wanted to achieve?

Note 1: I set the margins and paddings in my Plunker to 0 for every element to make the calculations easy. If you have padding, border or margin, you can do something like width: calc(20% - padding/border/margin) for the li elements.

Note 2: There are other ways to accomplish this too, but this is the first way that come to mind and probably the simplest.

Aside: You misspelled menubar in your question (you have it as "manubar").

Sander de Wijs
PLUS
Sander de Wijs
Courses Plus Student 22,267 Points

This is hard to accomplish with css alone. You proberaly want to use jQuery as well, so the menu can be like a horizontal scrollable carrousel, triggered by mouse movement.

You could give your menubar large width, larger than the screenwidth and give the container div of your navbar a width of 100%. This way the menubar will be cutt-off by the containing element.

<div id="menubar-container" style="max-width: 100%;">
<div id="menubar" style="width: 2000px;">
<ul class="menu-items">
<li class="menu-item"><a href="index.html">home</a></li>
<li class="menu-item"><a href="about.html">about</a></li>
<li class="menu-item"><a href="contact.html">contact</a></li>
....etc
</ul>  
</div>
</div>
Robert Komaromi
Robert Komaromi
11,927 Points

This is hard to accomplish with css alone.

Not really. What exactly is hard to do in CSS here?

You [probably] want to use jQuery ...

Why? Unless jQuery is already added to the website or OP wants some fancy menubar, I would advise against using jQuery just because you can. Maybe post some Javascript/jQuery showing your idea of the nav?

OP wanted the li items to have a width of 25% (i.e. the first four items will always fill the width of display while the last one will always be off screen to the right). Your code doesn't quite accomplish this, and the 2000px width is a bit arbitrary.

Sander de Wijs
PLUS
Sander de Wijs
Courses Plus Student 22,267 Points

The jQuery part helps the menu to interact with mouse movement when a user hovers over the menu. The menu is a bit more accessible this way and you don't need the horizontal scrollbar anymore.

Robert Komaromi
Robert Komaromi
11,927 Points

I agree - the regular scrollbar is ugly and the idea is not very user-friendly... OP, can we possibly have a peek at your creation? (PS: This should be a comment, not a new answer).