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

Aleksandrs Karevs
Courses Plus Student 11,178 PointsAligning vertical navigation menu to the right side of the screen. Left: CSS property question.
Hi everyone,
I am trying to build a custom navigation bar which is displayed differently on screen sizes and I have stumbled upon a small issue, which I am sure has a very easy solution but I just can't seem to find it...
In order to understand the question, please have a look at the following screenshot of what I am trying to achieve: http://d.pr/i/17DfQ .
As you can see from the screenshot above, I have two different designs for the navigation menu which should appear when the user clicks the "hamburger" icon. On mobile version of the website this menu should take up an entire screen, whereas on iPad version of the website I would like this menu to slide out from right side of the screen to the left and take up only a portion of the screen (as shown on the screenshot).
I have managed to achieve the desired effect on mobile version of my website using the following Javascript and CSS:
jQuery(function($){
$('.navbar-toggle').click(function(){
$('.navbar-collapse').toggleClass('right');
$('.navbar-toggle').toggleClass('indexcity'); // Gives the toggle button maximum z-index so that it would appear there at all times.
});
});
@media only screen and (max-width: 767px) {
.navbar-collapse {
position: fixed;
top: 0;
transition: all 0.2s ease-out;
height: 100%;
width: 100%;
left: 700px;
}
div#navbar.navbar-collapse.right {
padding-top: 0;
}
ul.nav.navbar-nav {
margin-top: 50px;
}
}
/* Custom classes for right-to-left sliding nav menu */
.indexcity {
z-index: 9999;
}
.right {
right: 0 !important;
left: 0 !important;
}
Explanation: originally on both versions of the website this vertical navigation menu is hidden away from the user by using the following property: left: 700px (on mobile version) and left: 1000px (on iPad version). When the "hamburger" icon is pressed, these properties are changed by adding a new .right class with the following properties:
.right {
right: 0 !important;
left: 0 !important;
}
Thus the menu is sliding out from the right side to the left on both versions of the website.
This is how it works on mobile version (short video): http://d.pr/v/1bZHq , and this is how it works on iPad version (short video): http://d.pr/v/1iSeF . As you can see, on iPad version , this vertical menu is located on the left side of the screen but I want it to be located on the right side of the screen (as was shown on the screenshot above). I know that the problem lies in the following line of code:
left: 0 !important;
If I change the value from 0 to lets say 400px.. e.g left: 400px , this is what happens (short video): http://d.pr/v/2eLx , but at the same time it starts to affect the mobile version of my website (short video): http://d.pr/v/WyJc .
Any suggestions how I could achieve the desired effect on iPad version of my website while keeping the mobile version working?
Thank you very much in advance.
3 Answers

Aleksandrs Karevs
Courses Plus Student 11,178 PointsJennifer Nordell Hi Jennifer, maybe you know the answer to this question?:) Thanks

Aleksandrs Karevs
Courses Plus Student 11,178 PointsJennifer Nordell yeah... took me a while to figure those little parts, but now it seems to work fine except this one little thing, which I am sure has an easy solution.. ;) By the way, here are my project files if you need them: http://d.pr/f/dQFn .

Jennifer Nordell
Treehouse TeacherOk wow! Lol you sure do ask the tough ones! I'm still looking. But I find this interesting. I can sort of tell you why it's behaving this way, but I can't yet tell you how to fix it.

Aleksandrs Karevs
Courses Plus Student 11,178 PointsJennifer Nordell Jennifer, I think I found a slightly different and probably a better solution to this navigation menu thingy... Instead of setting the left: property and dragging the navigation menu outside of the visible viewport and changing this property back to normal when the "hamburger" icon is pressed I decided to remove this left: property altogether and add right: 0 property together with opacity: 0. Like so: http://d.pr/i/1638j (screenshot). Hence it is invisible to the user at first. And than when the "hamburger" button is pressed, I set the opacity to 1 with a smooth transition... Still working on this last bit of setting the opacity back to 1 (so that it would become visible), but I think I will eventually figure out how to do it with JavaScript.
So, my current CSS:
div#navbar.navbar-collapse {
position: fixed;
background: #fff;
right: 0;
width: 335px;
height: 100%;
z-index: 2;
overflow-y: scroll;
transition: all 0.2s ease-out;
}
.navbar-collapse {
opacity: 0;
}
Struggling a bit with JavaScript but as far as I understand it should be something like:
$('.navbar-toggle').click(function(){
$('.navbar-toggle').style.opacity = "1";
});
The syntax is definitely wrong, but you get the idea... If you know the correct syntax for JavaScript to change the opacity value from 0 to 1 it would be nice if you share it with me ;)

Jennifer Nordell
Treehouse TeacherThat's sort of where I was going with my thinking as well. Because eons and eons ago you typed a line somewhere that says
left: 1000px;
and that's where the iPad size media query is deriving its size from for the link menu. You can fix it by adjusting the left rule that you had inside the right
class, but then the smaller media query also gets that and it gets messed up too. Because they are doing the same thing, but the derived values aren't allowing you to do what you want

Jennifer Nordell
Treehouse TeacherWell now that I can do! Phew... wasn't sure I was going to have a single bit of help here for you.
$('.navbar-toggle').css('opacity', 1);
Enjoy!
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherAleksandrs Karevs hi there again! Well I see you got it all clickable and whatnot now. That's great!. I'm taking a look now. Hope I can come up with something