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 trialRobert Berube
8,119 PointsCSS Navigation Bar to look like it wraps
So I want to style a nav bar so it looks like it wraps around the header as shown as the example shown in the picture.
https://dl.dropboxusercontent.com/u/50738254/Rob/nav-wrap.jpg
Can anyone help me with how to create this visual effect with CSS?
2 Answers
Jake Lundberg
13,965 PointsThere are many ways in which you can accomplish this...
Here is how I did it:
<div id="element-being-wrapped-around">
<!-- whatever content you want in here... -->
</div>
<div id="element-wrapping-around">
<!-- whatever content you want in here... -->
</div>
#element-being-wrapped-around {
position: absolute;
top: 100px;
left: 50%;
width: 500px;
height: 200px;
margin-left: -250px;
background: black;
}
#element-wrapping-around {
position: absolute;
top: 200px;
left: 50%;
width: 520px;
height: 50px;
margin-left: -260px;
background: red;
}
#element-wrapping-around::before {
content: ' ';
position: absolute;
left: 0;
top: -10px;
width: 0;
height: 0;
border-bottom: 10px solid firebrick;
border-left: 10px solid transparent;
}
#element-wrapping-around::after {
content: ' ';
position: absolute;
right: 0;
top: -10px;
width: 0;
height: 0;
border-bottom: 10px solid firebrick;
border-right: 10px solid transparent;
}
Oliver Sewell
16,425 Pointshmmm im not too sure maybe you could use the z-index property more info here http://www.w3schools.com/cssref/pr_pos_z-index.asp
Oliver Sewell
16,425 PointsOliver Sewell
16,425 PointsCSS Ninja !
Jake Lundberg
13,965 PointsJake Lundberg
13,965 Pointslol
Robert Berube
8,119 PointsRobert Berube
8,119 PointsThat definitely does it. Now to figure out how to make it work with my layout (I am a bit new to CSS and this forum, so I hope I am posting things correctly and interested in understanding the concept in the code that creates the effect).
The way I have it set now, the position: absolute; makes the container alignment go crazy, so I am wondering if I set this up correctly to do this, or how I get to it from my design (what to change).
Currently, I am working with the header styling. I recently moved the nav element outside the #header-wrapper to to make #nav-wrapper create the effect on #header-wrapper. Ultimately, I am trying to use a background-image for the nav bar that is a hospital fall risk bracelet, and make it look like it is wrapping around the element above (#header-wrapper). Here is how the html is set up currently...
<body> <div id="header-wrapper">
<header> <img src="img/trsc-title-logo.svg" id="title-logo" class="title-logo"> <img src="img/trsc-logo.svg" id="logo" class="title-logo"> </header> </div>
And the CSS
Thanks for the help guys.
Jake Lundberg
13,965 PointsJake Lundberg
13,965 PointsYou would use your header-wrapper and nav-wrapper in the same way I used element-being-wrapped-around and element-wrapping-around. Do a little reading on positioning and the possible values you can use. This is a great little project to work on this very important aspect, so I highly recommend taking the time to figure it out. I'm happy to help in this instance, but it is through these confusing projects that you learn the most, so I don't just wanna give the answer here...
Robert Berube
8,119 PointsRobert Berube
8,119 PointsSo, I was able to use the before/after pseudo elements to create the visual effect, but was running into an issue on viewport resizing...one edge that was not absolute positioned was moving out of place...until I discovered that you can (and how to) position multiple corners of the div (left and right).
Then I figured I could remove my over-width and negative margin values that were overlapping the div and just handle it with negative values in the absolute positioning.
Hope it is ok to do it that way, because it seems to work...at least for now LOL.