Navbar full width & dropdown width issues - html

I have a couple of problems to which the solution has eluded me. The first problem:
As a horizontal navbar, that section needs to span the entire width of the screen. This is all well and good on my monitor, but when I zoom in or adjust the browser width so that the horizontal scrollbar appears, the navbar background cuts off at the length equal to the browser's width. That is, no matter what the size or zoom, the navbar will span the entire visible width, but scrolling even a little to the right will show you that the navbar does not span the entire page width.
The second problem relates to the dropdown feature. At the moment, the width adjusts automatically to the width of the longest word (ie, spaces cause words to break to the next line). Firstly, how do I stop this, and secondly, is it possible to adjust the width to always be as wide as the distance between the borders to either side of the main navbar links? (EDIT: Ignore the first part of this paragraph. I accidentally deleted white-space:nowrap from the CSS. Second part is still an issue, though)
Link to fiddle
HTML:
<nav class="bg">
<ul class="width nav">
<li><span class="bord"></span></li>
<li>DropLink
<ul class="drop">
<li>LongerLinkName</li>
<li>LongLink WithSpace</li>
<li>Link</li>
</ul>
</li>
<li><span class="bord"></span></li>
<li>Link</li>
<li><span class="bord"></span></li>
<li>Link</li>
<li><span class="bord"></span></li>
<li>Link</li>
<li><span class="bord"></span></li>
<li>Link</li>
<li><span class="bord"></span></li>
</ul>
</nav>
CSS:
*{margin:0;padding:0;font-size:small;vertical-align:middle;}
a{color:#F00;text-decoration:none;}
.width{margin:0 auto;min-width:1000px;width:84%;}
.bg,.drop{background:#000;}
nav>ul{width:100%;text-align:justify;font-size:0;position:relative;}
nav>ul:after{content:"";width:100%;display:inline-block;}
nav li{list-style:none;display:inline-block;position:relative;}
nav a{display:inline-block;background:rgba(0,0,0,0);transition:background 0.2s linear;padding:8px;}
nav a:hover{background:rgba(0,0,255,1);}
.drop{position:absolute;left:-1000px;top:-1000px;opacity:0;transition:opacity .5s,top 0 .25s,left 0 .25s;border-left:1px solid #BBB;border-right:1px solid #BBB;border-bottom:1px solid #BBB;}
.nav li:hover .drop{left:0;top:100%;opacity:1;transition:opacity .5s,top 0s,left 0s;}
.bord{border-left:1px solid #000;border-right:1px solid #555;padding:7px 0;}
Also, while I'm at it, how come I can't get the borders to be exactly the same height as the navbar itself? If I increase the padding, it becomes a pixel too long. If I decrease the padding, it becomes a pixel too short.
Also, apologies if your browser requires prefixes in the code. I substituted prefixed CSS for a script that does it for me.

For your first issue I was unable to replicate it (maybe I misunderstood you).
For your second issue you can stop the wrapping of the link in the nav with the following css:
.nav a {
//other styles
white-space: nowrap;
}

I think I've got what you're after:
HTML (removed the border li's because the parent li of the dropdowns needs to be the full width you want the dropdown to be):
<nav class="bg">
<ul class="width nav">
<li>DropLink
<ul class="drop">
<li>LongerLinkName</li>
<li>LongLink WithSpace</li>
<li>Link</li>
</ul>
</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
CSS:
* {margin: 0; padding: 0; font-size: small; vertical-align: middle;}
a {color: #F00; text-decoration: none;}
.width {margin: 0 auto; min-width: 1000px; width: 84%; }
.bg {min-width:1000px;}
.bg, .drop {background: #000;}
nav>ul {width: 100%; text-align: justify; font-size: 0; position: relative;}
nav>ul:after {content: ""; width: 100%; display: inline-block;}
nav ul li {border-right: 1px solid #555; list-style: none; display: inline-block; position: relative; text-align:center; width:19%;}
nav ul li:first-child {border-left:1px solid #555;}
nav a {display: inline-block; background: rgba(0,0,0,0); transition: background 0.2s linear; padding: 8px;}
nav a:hover {background: rgba(0,0,255,1);}
.drop {position: absolute;left: -1000px;top: -1000px;opacity: 0;transition: opacity .5s, top 0 .25s, left 0 .25s;border-left: 1px solid #BBB;border-right: 1px solid #BBB;border-bottom: 1px solid #BBB;}
.nav li:hover .drop {left: 0;top: 100%;opacity: 1;transition: opacity .5s, top 0s, left 0s;}
nav ul ul {min-width:100%;}
nav ul ul li,
nav ul ul li a {border:0;display:block;text-align:left;white-space:nowrap;width:auto;}

Question 1: I'm not 100% sure what you're looking to do here, but the problem you're having appears to stem from the following:
.width{margin:0 auto;min-width:1000px;width:84%;}
Changing this line to the following resolves your issue, but may introduce other issues if you intentionally had the width set smaller:
.width{margin:0 auto;min-width:1000px;background:#000;width:84%;}
Question 2: I recently answered a very similar question at: Li element breaking content even with display block

Related

transparent navigation bar css

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;
}

Specifying heights in responsive layouts

I've been reading online and have come across numerous blogs and 'Professionals' that say you should not set heights and you should allow your content to fill the element instead. First of all.. why?
And also how can i allow my background colour to show on my header if i don't specify a height without using absolute or fixed position with top:0.
Here is my code:
HTML:
<header>
<div class="row-std">
<div class="logo">
<img src="images/logo.png">
</div>
<nav>
<ul id="navbar">
<li class="nav-item">LINK 1</li>
<li class="nav-item">LINK 2</li>
<li class="nav-item">LINK 3</li>
<li class="nav-item">LINK 4</li>
<li class="nav-item">LINK 5</li>
</ul>
</nav>
</div>
</header>
CSS:
header {
width: 100%;
background: #2f3842;
position: absolute;
top: 0;
}
header div.logo img {
float: left;
width: 20em;
margin-top: 1.5em;
margin-left: 1em;
}
header nav {
float: right;
}
header nav ul#navbar a {
text-decoration: none;
list-style-type: none;
color: #ebebeb;
border: 0;
transition-duration: .25s;
-webkit-transition-duration: .25s;
}
header nav ul#navbar a:visited {
color: #ebebeb;
}
header nav ul#navbar a:hover, header nav ul#navbar a:active {
color: #16a085;
}
header nav ul#navbar .nav-item {
display: inline-block;
padding: 0.3125em 0.3125em;
margin: 2.5em 1em;
font-size: 0.84em;
font-weight: 600;
}
As you can see the header currently has the absolute position with a top property value of '0'. This works for allowing the header to show the background colour and allow the element to be filled in terms of its height by its content but if i was to display an another element beneath this i cannot really do so as it will be displayed under it unless i use a margin-top of 5.5em perhaps to push the element down into its correct position which works fine, but this feels tacky. Is there a better way of doing this.
Having unnecessary heights on elements in responsive designs can result in overflowing content on different screen resolutions and it's generally a good idea to not specify heights and let your content dictate the height of an element.
That being said, there are always circumstances where you need to manually specify heights of elements (usually these circumstances are where elements have no intrinsic height, like when specifying background images on elements with no other content, but other cases do exist).
Exceptions prove the rule. Bottom line when developing responsive sites, don't specify heights...unless you have to :).

Trying to create a submenu that stretches across entire page

I'm trying to create a submenu that stretches across an entire page on http://jobcreatr.com
The problem is that the submenu is only stretching from the top menu item all the way to the right. I want it to go all the way across. Also, there's some weird padding on the submenu items, which I think is related to the border bottom on hover - which I don't even want on the submenu items.
How do I get the submenu to stretch across the entire page, and also get rid of that weird padding/border-bottom.
Here's the css I have:
.sf-menu.sf-horizontal.sf-shadow ul, .sf-menu.sf-vertical.sf-shadow ul, .sf-menu.sf-navbar.sf-shadow ul ul {
width: 100%;
background-color: #F6F6F6;
background: none;
list-style-type: none;
text-align: center;
margin-top:22px;
overflow: none;
display: none;
}
.sf-menu.sf-horizontal.sf-shadow ul a, .sf-menu.sf-vertical.sf-shadow ul a, .sf-menu.sf-navbar.sf-shadow ul ul a {
background-color: #000/*#F6F6F6*/;
width: 9999px;
}
.sf-menu.sf-style-whiteshadow li {
overflow: visible;
}
.sf-menu.sf-style-whiteshadow li:hover {
border-bottom: 4px solid #000;
}
.sf-menu.sf-style-whiteshadow .sf-depth-2 {
border-bottom: none;
}
Here's the HTML:
<ul id="superfish-2" class="menu sf-menu sf-main-menu sf-horizontal sf-style-whiteshadow sf-total-items-3 sf-parent-items-1 sf-single-items-2 superfish-processed sf-js-enabled sf-shadow">
<li id="menu-1299-2" class="first odd sf-item-1 sf-depth-1 sf-no-children">
<li id="menu-1300-2" class="middle even sf-item-2 sf-depth-1 sf-no-children">
<li id="menu-1301-2" class="last odd sf-item-3 sf-depth-1 sf-total-children-1 sf-parent-children-0 sf-single-children-1 menuparent">
<a class="sf-depth-1 menuparent sf-with-ul" title="" href="http://jobcreatr.com/products">
<ul class="sf-hidden" style="float: none; width: 12em; display: block;">
<li id="menu-1632-2" class="firstandlast odd sf-item-1 sf-depth-2 sf-no-children" style="white-space: normal; width: 9999px; position: absolute; float: left;">
<a class="sf-depth-2" title="" href="http://www.google.com" style="float: none; width: auto;">test</a>
</li>
</ul>
</li>
</ul>
Ideally if you want to make an element take up the whole width you should have it on the same level as your uppermost element which also takes up the whole width (for example body, if your body does not have any width set) and then position this element absolutely with a width of 100%.
However in your case you could use fixed position, try changing your css rules where you have defined width of 9999px to this:
.sf-menu.sf-horizontal.sf-shadow ul a, .sf-menu.sf-vertical.sf-shadow ul a, .sf-menu.sf-navbar.sf-shadow ul ul a {
background-color: #000/*#F6F6F6*/;
width: 100%!important;
position: fixed;
left: 0;
}
The reason why you have to add the !important to your width is because currently the width is being overwritten by javascript responsible for making the menu work. Using !important isn't best practice and if you want to do it properly you should change your javascript so that the width does not get set by it: then you do not need to use the !important rule.
As mentioned in my comment above, change this
.sf-menu.sf-style-whiteshadow li:hover {
border-bottom: 4px solid #000;
}
to this:
.sf-menu.sf-style-whiteshadow > li:hover {
border-bottom: 4px solid #000;
}
to get rid of the bottom border of your submenu item.

How to make border for UL if Li has style "float:left;"?

My css for ul is:
ul {list-style-type: none; margin:auto; border-top: 1px solid #0093a7; border-bottom: 1px solid #0093a7; margin: 20px 0;}
ul li {float:left; padding:5px;}
The UL tag:
<ul>
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
Now both borders are on the top of the UL.
How to make bottom border then?
You need to apply overflow:hidden to your ul so that your floats are cleared and are contained within the ul.
Currently your ul is collapsing since it contains only floated elements.
If you need to support IE6(?!) then you will need to make sure your container (ie. ul) hasLayout for the overflow trick to work. You can do this by applying a width.

Drop down menu shouldn't be transparent

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.)