I have to make a website for an assignment, and I'm having a bit of trouble. I've created a navbar up the top, and it's in a fixed position. However, when I scroll, everything shows through it. What I want, is essentially for the webpage to start under the navbar, so it's there at the top, and when I click 'About Me', it doesn't have the title under the navbar, like in the second image.
http://i.imgur.com/oTkXlWx.png
Does anyone know how to do this? Thanks.
#top-bar
{
border-top:#fff dashed 1px;
width:100%;
height:32px;
background:black;
opacity:0.8;
text-align:center;
position:fixed;
top:0;
padding-bottom:12px;
}
#top-nav li
{
display: inline-block;
line-height: 49px;
padding: 0px 14px;
}
#top-nav li a
{
display:block;
color: #ddd;
font-weight: 700;
letter-spacing: 0.08em;
text-decoration: none;
text-transform: uppercase;
}
#top-nav li:hover, #top-nav li:hover a
{
background-color:#333;
color:#fff;
}
and the html:
<nav id="top-bar">
<ul id="top-nav">
<li>
About Me
</li>
<li>
Programming
</li>
<li>
Hometown
</li>
<li>
Swinburne
</li>
<li>
Acheivements
</li>
</ul>
</nav>
Basically, I don't want the webpage to 'scroll through' the nav bar.
Also, my class hasn't done javascript yet, so if there is a solution not using javascript that would be great.
Thanks guys.
P.S. Here is the code for the div for the about:
<div id="about-text" class="box">
<h3>About Me</h3>
<p>My name is , I'm 18 years old, and a Computer
Science student at Swinburne University of Technology, Hawthorn.
I've always been interested in computers, there is something
beautiful about technology working to do so many things the human
brain cannot possibly do.</p>
</div>
and the css:
#about-text, #programming-text, #home-text, #achievement-text
{
border-style : solid;
border-width:0.2em;
opacity:0.5;
width : 70%;
transition: opacity 0.2s;
-webkit-transition: opacity 0.2s;
}
I believe you simply need to give the .boxes enough of a margin-top for it to clear the fixed navbar.
Update:
Discovered that the root cause of the issue was the use of in-page links, which always scrolled right to the top of the viewport (under the fixed nav) when clicked.
The best solution ended up being adding empty a elements before each div.box to use as the target of the links, and give those a large enough size that the .box would fall into place below the navbar:
<div class="box"> ... </div>
.button {
display: block;
padding: 25px;
}
One trick that you can use is to put nav within the header tag and give background color for header, white or whichever color you are using. Scrolling down will go below the nav bar but it wont be seen due to the background color which overlaps it.
Related
I am currently working on a website and at the top of the site i have a navigation bar that stays at the top of the screen as you scroll. Here is a sample image of it: https://i.imgur.com/R4QiDoP.png
The problem it, when I scroll down, some (but not all) text is visible through the navigation bar and makes it illegible: https://i.imgur.com/LDnZ3ZN.png
Here is the code for the:
HTML
<div class="nav">
<div class="container">
<ul class="pull-left">
<li>Home</li>
<li>Tools</li>
</ul>
<ul class="pull-right">
<li>About Us</li>
<li>Contact Us</li>
</ul>
</div>
</div>
CSS
.nav {
position: fixed;
background-color: #efefef;
border-bottom: 1px solid #dbdbdb;
width: 100%;
top: 0;
opacity: 1.0;
}
.nav a {
color: #5a5a5a;
font-size: 11px;
font-weight: bold;
padding: 10px 10px;
text-transform: uppercase;
}
.nav a:hover {
background: #e1e1e1;
color: black;
}
.nav li {
display: inline;
}
I have already tried changing the opacity but that made it illegible 100% of the time. I am willing to try any suggestions that you have. Thank you!
Check the z-indexes you use in your website and make sure to give the .nav the heigest z-index, that should solve the problem. Do it like this:
.nav {
z-index: ...; /* higher amount than used somewhere else */
}
Let me know if that works or not!
Your nav and the rest of the page are likely on the same 'layer' which is mish-mashing them together when they overlap. Try adding a z-index to .nav to place it 'above' the rest of the page. The z-index number will need to be 1 higher than the current highest z-index on your page (if no other element has a z-index, that would be 1).
.nav {
z-index: 1;
}
I'm sort of new to HTML and currently, I am creating a custom home page for myself containing links to site I often visit.
When I hover over a picture it expands to show more specific links (i.e. subreddits).
However, the problem is that the "sub-link-icons" are not properly aligned with the expanding DIV It will show in front of the bigger picture when hovering over it.
What I am trying to do is have the sub-link-icons to be in sync with the expanding div.*
HTML:
<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
<title>Homepage</title>
</head>
<body>
<div class="submenu" id="steam"><img src="steam.png"></div>
<div class="submenu" id="reddit">
<img src="reddit.png"/>
<ul>
<li><img src="reddit.png"/></li>
<li><img src="reddit.png"/></li>
<li><img src="reddit.png"/></li>
</ul>
</div>
<div class="submenu" id="youtube"><img src="youtube.png"/></div>
</body>
</html>
CSS:
body {
background-color: #330000;
color: white;
}
div img {
width:256px;
height:256px;
border-radius:5px;
}
li img {
width:75px;
height:75px;
border-radius:15px;
}
#youtube:hover {
border: #E6E6E6 solid 4px;
background-color: #E6E6E6;
}
#steam:hover {
border: #12151A solid 4px;
background-color: #12151A;
}
#g2a:hover {
border: #0F1F2E solid 4px;
background-color: #0F1F2E;
}
#reddit:hover {
border: #999999 solid 4px;
background-color: #999999;
}
ul{
position:absolute;
list-style-type: none;
display:none;
margin-left: 125px;
}
.submenu {
border-radius: 5px;
position:relative;
display: inline-block;
margin-left: 0px;
width:256px;
height:256px;
border:4px solid #330000;
text-align:center;
margin-left:5px;
margin-top:5px;
transition: width 1s;
z-index:0;
}
.submenu img {
float:left;
}
.submenu:hover {
width:350px;
transition: width 1s;
}
.submenu:hover img {
float:left;
z-index:2;
}
.submenu ul {
position: absolute;
}
.submenu:hover ul {
display:inline-block;
float:right;
margin-top:-10px;
margin-left:-45px;
position:absolute;
z-index: 1;
}
.submenu:hover ul li img {
float:left;
margin-left: -30px;
margin-top: 12.5px;
}
I've tried searching the web for help but couldn't quite manage it.
JSFIDDLE
Lets go through this step by step.
First issue: On hover, "sub-icon-links" are layered over your big pictures, instead of under it.
This IS fixable with z-index, but first you have to understand how z-index works.
Note: z-index only works on positioned elements (position:absolute, position:relative, or position:fixed).
With z-index you can layer elements that are in the same HTML layer. Because it didn't work I assume you've tried to apply z-index on the sub-menu-links. This wouldn't work because the big picture is not on the same layer as them. If we take a look at your HTML structure you'll see:
<div class="submenu" id="reddit">
<img src="http://www.workatplay.com/files/styles/fpo_medium/public/article/logo/Reddit%20Small.jpg?itok=dclAuuiP"/>
<ul>
<li><img src="http://www.workatplay.com/files/styles/fpo_medium/public/article/logo/Reddit%20Small.jpg?itok=dclAuuiP"/></li>
<li><img src="http://www.workatplay.com/files/styles/fpo_medium/public/article/logo/Reddit%20Small.jpg?itok=dclAuuiP"/></li>
<li><img src="http://www.workatplay.com/files/styles/fpo_medium/public/article/logo/Reddit%20Small.jpg?itok=dclAuuiP"/></li>
</ul>
</div>
To use z-index in this case, you have to see at which points the images or their containers are on the same layer.
Your big image is contained within an anchor tag (a)
Your small images are contained within list items
These list items are contained within an unordered list
This unordered list and the anchor tag are on the same layer. Applying z-index to one of these will fix this issue.
Note: This works different when using things like "position: absolute" and "position: fixed" or any other attribute that changes the position of the element in the HTML stack.
JSFiddle: https://jsfiddle.net/eehdo8wa/5/
What I did:
Added "z-index: -1;" to ".submenu ul"
Removed "z-index: 1;" from ".submenu:hover ul"
Second issue: On hover, the "sub-icon-links" should expand at the same rate as the div expands
So, doing this should be very simple now the pictures are layered under the big picture correctly. Basically, when you think about it, all you should have to do is make the pictures stick to the right side of its parent, so when it expands, the pictures stick to the right side and slide along, taking them into the view.
JSFiddle: https://jsfiddle.net/eehdo8wa/6/
What I did:
I redid some of the CSS to make it so everything is already in the right position before sliding into the view. This is essentially what you want in these cases. In your original fiddle you had a LOT of styling on the hover portions, changing all kinds of styling and spacings, but was it really needed? In the end, no. Now it's all in position behind the big image, ready to slide right into the view.
So I wanted to create the fixed nav bar on top of the page. Instead of creating nav bar with ordered list, I used the following approach:
<header>
<div class="nav">
<img src="images/logo_ab.png" alt="AurinBioTech Logo"/>
Home
About
Team
Science
Need
Pipeline
Contact
</div>
</header>
CSS:
header .nav {
margin-top:100px;
width:100%;
height:10%;
text-align:center;
padding-top:2%;
margin:0 auto;
position:fixed;
top:0;
}
header .nav a {
font-size: 2em;
padding-left: 15px;
padding-right: 15px;
color:rgb(1, 1, 1);
text-decoration: none;
font-family: 'Bebas';
}
header .nav a:hover {
color:white;
background-color: #404040;
border-radius:5px;
padding:0 auto;
}
header .nav a:active{
background-color: #404040;
border-radius:5px;
text-decoration:overline;
}
header .nav img {
width:260px;
height:65px;
padding-right:4em;
}
The reason I used this approach is because I wanted to use logo image next to the nav bar so it would align properly in the same line. Now the problem is that I need to add sub-menus under Science and Pipeline heading. Since I didn't use UL or LI, how can I add sub-menus under those heading.
OR, can you tell me any other way to create a NAV bar that shows the logo as well.
so it would be LOGO and MENUS on the same line.
Great thanks in advance.
Use the normal ul li structure.
If you set the height and line-height of top level li tags to be equal to the height of the image it will align the text to the center of the image.
I can suggest you to use a tool.
CSSMENU where you can create a menu without writing the code.You can also change the code or add images as your wish if needed. There are some inbuilt images where you can use them too.
have a two column structure in your nav bar one column for the logo and other for the nav-bar options.
<header>
<div class="nav">
<img src="images/logo_ab.png" alt="AurinBioTech Logo"/>
</div>
<div class="options">
<ul>
<li>Home</li>
<li>About</li>
<li>Team</li>
<li>Science</li>
<li>Need</li>
<li>Pipeline</li>
<li>Contact</li>
</ul>
</div>
</header>
and
with css give them appropriate width and align them using padding or margin properties
I have a drop down menu (#dropDownMenu) which appears when the "#headerNav" of my website is hovered over. It works properly if I position the #dropDownMenu (originally hidden with display:none until link is hovered over) slightly over the #headerNav div.
This stops the slight flickering that is caused if the cursor isn't moved over fast enough to the drop down menu when it appears. By slightly overlapping #dropDownMenu over #headerNav this makes it seem like the #headerNav is still being hovered over when cursor is actually in the #dropDownMenu.
Anyway I now want to hide the overlapping part of #dropDownMenu behind header or #headerContent so everything looks neater and so the drop down menu actually looks like it's appearing beneath the #headerNav.
I've tried different z-index settings and none seem to work which is quite annoying. When I set the z-index of #headerNav:hover #dropDownMenu to -1 it is hidden behind all content as expected.
If I set z-index of header or #headerContent to a number higher than "#headerNav:hover #dropDownMenu" then hover over #headerNav there is no difference. I can still see #dropDownMenu overlapping.
CSS:
header {
position:fixed;
top:0;
right:0;
left:0;
height: 40px;
z-index:20;
}
#headerContent {
background-color: $main-background-color;
width: $site-width;
margin:0px auto 0px auto;
height:40px;
}
#headerNav {
float:right;
height:37px;
width:auto;
margin-top:1px;
background-color:#464646;
color:#cccccc;
}
#headerNav:hover {
background-color:#626262;
cursor:pointer;
color: white;
}
#headerNav:hover #dropDownMenu {
position:absolute;
background-color:white;
border:1px solid gray;
top:35px;
right:-39px;
height:300px;
width:200px;
font-weight:bold;
color:gray;
display:block !important;
z-index:1;
}
ul li {
float:right;
}
#photoThumbnail img {
height:28px;
width:31px;
padding-top:5px;
padding-right:8px;
-moz-border-radius: 1px 12px 1px 12px;
border-radius: 1px 12px 1px 12px;
}
#currentUser {
position:relative;
padding-top:12px;
padding-left:12px;
padding-right:6px;
}
#siteNavigation {
display:none;
}
HTML
<header>
<div id='headerContent'>
<div id='LogoHolder'>
</div>
<nav id='headerNav'>
<ul>
<li id='photoThumbnail'></li>
<li id='currentUser'>
<ul id='dropDownMenu'>
<li>link1</li>
<li>link2</li>
<li>link3</li>
<li>link4</li>
<li>link5</li>
<li>link6</li>
</ul>
</li>
</ul>
</nav>
</div>
</header>
Examples and corrections will be greatly appreciated.
Kind regards
If your z-index setting is being ignored you might need to add position property, set it to relative or whatever it needs to be. I'm pretty sure z-index is ignored if position property is not set.
I think you'll find that you are trying to hack your way around a fundamental markup issue. THe usual way to do ul based drop downs is this
<ul id='headerNav'>
<li>Menu Title
<ul class='dropDownMenu>
<li>link1</li>
<li>link2</li>
</ul>
</li>
</ul>
This way you set the hover action on #headerNav li:hover and your drop down is a child of your hover element and the menu will stay open (and not flicker) when you move your mouse over the .dropDownMenu as it is also being hovered. You're close.. you just need to wrap your html a bit better and adjust your css to hover on the li and show and hide the "li ul.dropDownMenu"
This should get rid of the need for your overlap - and fix your problem.
I have a simple drop down menu.
When i add other elements under the menu (like text for exemple) they are still visible even if the drop down menu is oppened. The drop down menu is somehow merged with the content under it, resulting in ugly superimposed content.
Here is my css :
ul#menu, ul#menu ul{
margin: 0px;
padding: 0px;
}
ul#menu li{
width: 160px;
margin: 4px 0px 0px 4px;
padding: 5px;
list-style: none;
position: relative;
float: left;
background: #eef;
border: #bbf solid 1px;
}
ul#menu li ul li{
width: auto;
margin: 4px 0px 0px 0px;
float:none;
display: none;
background: #ddf;
border: #bbf solid 1px;
}
ul#menu li:hover ul li{
display: block;
}
ul#menu li:hover{
background: #ddf;
}
ul#menu li ul li:hover{
background: #ccf;
}
ul#menu li img{
margin-right: 10px;
}
Here is my html :
<ul id="menu">
<li>
<span><img src="images/logos/file_small.png">Bilan</span>
<ul>
<li id="creer"><img src="images/logos/add_small.png">Créer</li>
<li id="consulter"><img src="images/logos/other_small.png">Consulter / Modifier</li>
</ul>
</li>
<li>
<span><img src="images/logos/chartbar_small.png">Extract</span>
<ul>
<li><img src="images/logos/pdf_small.png">Pdf</li>
<li><img src="images/logos/xls_small.png">Excel</li>
</ul>
</li>
<li>
<span><img src="images/logos/first_small.png">Module Conso/Gene</span>
</li>
</ul>
I hope you can help. :)
http://jsfiddle.net/chrisvenus/GRfDT/2/ is a fiddle with your modifications and a solution.
What I did was firstly altered the margin to make sure the text appeared in the right place (ie increasing the top margin).
Then I modified the z-index on that text to put it behind the menu stuff. You could also have modified the z-index of the menus and it might even be best practice to put a z-index on both.
<div style="position: absolute; margin-top: 50px; z-index: -1"> SOME CONTENT </div>
z-index is basically designed for exactly this purpose - determining what order the content is in from background to foreground. For more information on it see http://www.w3.org/TR/CSS2/visuren.html#propdef-z-index
Also I shoudl note that kinakuta, although replying before your problem was fully explained, is right about the fact that you should probably be making your menu absolute rather than the content that follows it. Mainly because I suspect it will mean neater HTML overall since it will stop you having to either have a container with all your other content or making far more things absolute than you want or worst case nto making everythign take it into account so some things get moved about or overlayed by your absoluted text in other ways...
something like this: http://jsfiddle.net/chrisvenus/GRfDT/3/ (the same as before but with some swaps about where the position: absolute is)
The main issue I see is that when your menu "displays" it's pushing things below it down. You want to set the position of the nested list to absolute to remove it from the flow of the page:
#menu li ul { position: absolute; }
This will make the menu appear over the text/content instead of pushing it down.
One more thing - you'll want to add some positioning to that same ul - left 0; and top 25px; (or something around there to fit how you want it to look.)