Fixed position navigation bar width and overlap issue - html

Hello fellow community members,
I am currently having a problem where I have set my top navigation bar to be fixed so that it follows users as they scroll down my web page but I am currently faced with two issues.
The content of my site is overlapping my navigation bar and goes ontop of it making it look messy and not function as designed. (The background is not transparent but rather a solid image)
The website is fluid and I have been fiddling with this for hours now trying to get it to work but as I set a min-width and max-width it doesn't seem to obey the min-width and width as a percentage (100% of the container). Sorry if I am a little unclear in explaining this but I have attached some code in jsfiddle for people to see.
If you would like to see where I am stuck at right now you can do so at subnovaled.com (the blue bar along the top) also the jsfiddle link is as follows:
#navMainWrapper {
height: 32px;
font-size: 12px;
position: fixed;
min-width: 1000px;
max-width: 1280px;
width: 100%;
background: cyan;
}
http://jsfiddle.net/jXJMx/23/
Note: the above code was done in a rush, sorry
Thank you to anyone who is able to help me out!!

check this fiddle:
http://jsfiddle.net/jXJMx/26/
CSS:
#navMainWrapper {
height: 32px;
font-size: 12px;
position: fixed;
min-width: 750px;
max-width: 1280px;
width: 100%;
background: cyan;
}
#navMainSearch {
float:left;
width:120px;
}
#navMain {
float:left;
width:750px;
line-height:normal;
height:32px;
}
#navMain ul {
float:right;
list-style:none;
}
#navMain li {
display:inline;
}
#navMain a {
float:left;
text-decoration:none;
}
#navMain a span {
float:left;
display:block;
padding: 7px 15px 0 15px;
text-align:center;
width:90px;
cursor:pointer;
height:25px;
}
/* Commented Backslash Hack hides rule from IE5-Mac \*/
#navMain a span {
float:none;
}
/* End IE5-Mac hack */
#navMain a:hover {
background-position:0% -32px;
}
#navMain a:hover span {
background-position:100% -32px;
}
#content {
background:yellow;
min-width:750px;
width:100%;
height:768px;
position:relative;
margin-top:32px;
}

Update CSS as show
#navMainWrapper {
height: 32px;
font-size: 12px;
position: fixed;
min-width: 1000px;
max-width: 1280px;
width: 100%;
background: cyan;
}
#navMainSearch {
float:left;
width:120px;
}
#navMain {
float:left;
line-height:normal;
height:32px;
}
#navMain ul {
list-style:none;
}
#navMain li {
display:inline;
}
#navMain a {
float:left;
text-decoration:none;
}
#navMain a span {
float:left;
display:block;
padding: 7px 15px 0 15px;
text-align:center;
/*width:90px;*/
cursor:pointer;
height:25px;
}
/* Commented Backslash Hack hides rule from IE5-Mac \*/
#navMain a span {
float:none;
}
/* End IE5-Mac hack */
#navMain a:hover {
/* background-position:0% -32px;*/
}
#navMain a:hover span {
/* background-position:100% -32px;*/
}
#content {
background:yellow;
width:100%;
float:left;
height:1500px;
}

Related

How to properly set width of a div within li

I'm trying to give my div inside a li a width value and the div's border has the width I want, but the text I have in that div is ignoring that width and it seems to be inheriting the container width. It's just the text that is doing that, though.
I don't usually work with li tags, so I don't really know what the problem is.
This is basically the HTML I'm working with:
<div id="container">
<div class="inner">
<ul>
<li>
<a class="img" href="..."></a>
<div class="desc">
...
</div>
</li>
</ul>
</div>
</div>
This is the CSS:
#container {
margin:0 auto;
width: 900px;
height: 500px;
box-sizing:border-box;
position:relative;
right: 160px;
-webkit-user-select: none;
user-select:none;
}
#container div.inner {
position:relative;
overflow:hidden;
padding:0;
margin:0;
}
#container div.inner ul {
white-space:nowrap;
position:relative;
left:0; top:0;
list-style:none;
font-size:0;
padding:0;
margin:0;
float:left!important;
width:auto!important;
height:auto!important;
}
#container ul li {
display:inline-block;
margin-top:20px;
margin-bottom:200px;
margin-left:-45px; margin-right:-30px;
-webkit-transform:scale(0.6);
transform:scale(0.6);
-webkit-transition:-webkit-transform 0.5s;
transition:transform 0.5s;
box-sizing:content-box;
text-align:center;
vertical-align:middle;
padding:0;
position:relative;
list-style:none;
backface-visibility:hidden;
}
#container ul li.active {
-webkit-transform:scale(1);
transform:scale(1);
background-color:transparent;
}
#container ul li.active .desc {
display: block;
}
.desc {
display: none;
width: 310px!important;
height: 200px;
border: 1px solid #fff;
position: relative;
right: 350px;
top: 275px;
color: #fff;
font-family: Arial;
font-size: 11px;
padding: 15px;
text-align: justify;
}
#container .img {
width: 200px;
height: 320px;
background-size:contain;
background-repeat:no-repeat;
background-position:center center;
display:block;
position:absolute;
font-size:0;
cursor:inherit;
transition:all linear 0.4s;
}
There seems to be a lot of CSS here that is conflicting. Are you sure you need to use '!important' in so many places?
It's hard to tell what's happening but my feeling is that using position:absolute and float is breaking things.
Also, your div inside the li ("desc") is set to display:block at some point.
Try changing it to inline or inline-block depending on what you need it to look like.
#container ul li.active .desc {
display: block;
}
Then after this you are trying to set a width when it is display:none...
.desc {
display: none;
width: 310px!important;
...
This is probably not showing up because if the display:block taking precedence, because you have been more specific with your selectors. Try doing the same for the .desc section:
#container ul li .desc {
display: none;
width: 310px!important;
...
If you can supply a working Jsfiddle or code snippet so we can see what you are trying to achieve that would help.
I'd also like to rewrite this for you so that you can see there is probably a much easier way to accomplish your layout without all of the conflicts.
in your .desc {} is the second from the bottom padding: 15px;
Try deleting that one.

Inline-Block For Center Aligned Navigation Not Displaying Horizontal in IE 11+

So, I'm trying to create a centered horizontal menu in a fixed-width parent container. I set both the ul and li elements to display as inline-block and the parent to text-align and center. This method works in FF and Chrome, but in IE, the list is centered, but displaying vertically. This is with IE 11.
Here's the breakdown:
.menu {
width: 700px;
height: 35px;
background-color: #767676;
text-align:center;
}
.menu ul {
list-style:none;
display:inline-block;
padding:0px;
margin:0px; }
.menu li {
display:inline-block;
background-color: #B9E9A8;
width: 120px;
height: 35px;
text-align: center;
color:#4F4F4F;
font-size:18px;
line-height:35px;
}
.menu li a {
color:#3A3A3A;
text-decoration:none;
display:block;
}
.menu li a:hover {
color:#fff;
background-color:#507B28;
}
Any ideas? Thanks!
try:
.menu {
width: 700px;
height: 35px;
background-color: #767676;
text-align:center;
}
.menu ul {
list-style:none;
display:block;
text-align: center;
padding:0px;
margin:0px; }
.menu li {
display:inline-block;
background-color: #B9E9A8;
width: 120px;
height: 35px;
text-align: center;
color:#4F4F4F;
font-size:18px;
line-height:35px;
}
.menu li a {
color:#3A3A3A;
text-decoration:none;
display:block;
}
.menu li a:hover {
color:#fff;
background-color:#507B28;
}
All I have done is to keep the ul a block element. By making it inline-block, it is only going to have the width of its contents which are all inline elements too, meaning it will just fill up from the left. By making it a block, it will fill in the whole line, and text-align center will then center the inline-block contents.

Layout breaks on browser resize

Got a weird problem,i.e,Layout of webpage breaks on resize of the browser/when accessed through mobile device/when switched to lower resolution ( 800*600 / 1024*768 )
Temporary link : http://krishnaspirit.hostoi.com/
P.S : Its a full-width website & Works fine on 1366*768.
CSS :
* { padding:0px; margin:0px; }
p,h1,h2,h3,h4,h5,h6,a{ font-family: 'Armata', sans-serif; }
/*header*/
.header { z-index:5000; position:fixed; top:0px; width:100%; min-width:960px; height:100px; background-color:#4E4E56;}
.header #nav li:last-child { margin-right:0px; }
.header #nav li { transition:1s ease all;line-height:40px;
display:inline-block; margin-right:3px; width:116px; height:40px;text-align:center; border-radius:5px;}
.header #nav li a { font-size:15px; color:#DCD0C0; display:block; height:100%; text-decoration:none; }
.header #nav li:hover { background-color: #DA635D; }
.header #nav li a:hover { color:#fff; }
.header #nav { position:absolute; right:10px; top:35px; width:600px; }
.current {background-color: #DA635D; cursor:none;}
.header #nav .current a { color:#fff; }
.header .logo img {width:100px; height:95px; position:absolute; top:5px; left:12px; line-height:100px; font-size:40px; color:#fff;}
.header .logo .name { font-size:40px; color:#ccc;
font-family: 'Armata', sans-serif; position:absolute; left:110px;top:29px; }
/*sub-head*/
.sub-header .top-logo { float:left; }
.sub-header .top-name { float:right; font-size:30px; padding-top:120px; color:#003366; }
.sub-header { width:85%; text-align:center; margin:150px auto; }
/*main-body*/
.content { float:left; }
.news { float:right; margin-right:5px; }
.news { box-shadow:3px 3px 5px #ccc; padding:0px; border-radius:3px; }
.news p { font-weight:bold; font-size:15px; padding-bottom:20px;}
.news { border:1px solid #ccc; width:27%; min-width:27%; padding:5px; height:300px;}
.news .news_body { padding:3px; text-align:center;}
.content { box-shadow:3px 3px 5px 0px #ccc; width:70%; height:300px; border-radius:3px; margin-left:5px; border:1px solid #ccc; font-size:15px; padding:5px;}
.content .sub-main { margin-top:15px; text-align:justify; padding:10px; }
.content #myMenu { width:100%; text-align:center; height:30px; }
.content #myMenu{ list-style-type:none; }
.content #myMenu li { border-bottom:1px solid #ccc; color:#999; display:inline-block; width:30%; line-height:30px;}
.content #myMenu li:hover { font-weight:bold; }
.content #myMenu li a { display:block; width:100%; }
.content #myMenu li a:hover { border-bottom:5px solid #DA635D; color:#DA635D; cursor:pointer;}
.body_wrapper { margin-bottom:500px; margin-top:70px; background-color:#ccc; }
/*footer*/
footer { width:100%; height:50px; line-height:50px; background-color:#4E4E56; }
footer p a{ color:#DA635D; text-decoration:none; font-weight:bold;}
This is not a weird problem. You need to use #media query to fix the problem.
The image on left side is large enough to occupy almost half of total screen width at a resolution 1024x768. You need to define style sheet on different screens using media query.
Example -
#media screen and (max-width: 1024px){
.main .sub-header .top-logo{
width: 250px;
}
.main .sub-header .top-logo img{
width: 100%;
}
}
This snippet will only take action in device screen width less than or equal to 1024px.
As you can see, for this type of device resolution I have reduced the width of .top-logo to make sure it can fit properly in small screen. You need to define .top-name and other elements accordingly to fit them properly for different device width. Hope you get the idea.
Another thing causing this problem is when one #media query has a missing closing brace }.
For example if your CSS has something like:
nav {
position: relative;
width: 95%;
margin: 10px auto 0 auto;
height: auto;
background-color: var(--magnolia);
font-family: Roboto;
}
#media screen and (min-width: 860px) {
nav {
margin: 0 auto;
}
<----------------- /* A closing brace "}" is missing here ! */
.navbar {
display: flex;
list-style-type: none;
flex-flow: row wrap;
justify-content: space-between;
align-content: center;
align-items: center;
margin: 0 auto;
padding: 0;
height: auto;
}
etc.
etc.
This makes all CSS below it revert to default, e.g. width: 100%.
Overflow abounds in such a situation.
Since W3C CSS Validator may not detect this, you have to closely read through all #media queries before the breaking elements looking for missing closing braces. Just one of these can screw up everything below that part of the web page. Fix it and everything is suddenly fine.

Fixed width div

I set my div to be fixed position and when I scroll page to very bottom or if I use smaller screen like smartphone or tablet my fixed div float over my footer. How can I fix this?
This is my fixed div:
.infoItem{
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
border: 1px #e4e4e4 solid;
width: 227px;
background:#f8f6f7;
position: fixed;
}
and this is my wrapper:
.wrapper {
min-width:954px;
}
I also try to wrap my infoteam div in another div and set new div to be position: absolute but that also didn't work.
Fixed div html
<div class="box-collateral box-up-sell">
<div class="infoItem">
<p class="heading">Add to your </p>
<p class="content">
<div class='upsellContainer'>
<div>
</div>
</div>
</p>
</div>
</div>
footer css
.footer { background:url(../images/footer-top-border.png) repeat-x;}
/* .footer-container { border-top:15px solid #b6d1e2; }*/
.footer { width:904px; margin:0 auto; padding:30px 10px 50px; }
.footer .store-switcher { display:inline; margin:0 5px 0 0; color:#fff; }
.footer .store-switcher label { font-weight:bold; vertical-align:middle; }
.footer .store-switcher select { padding:0; vertical-align:middle; }
.footer a {text-decoration:none; }
.footer a:hover { text-decoration:underline; }
.footer .bugs { margin:13px 0 0; }
.footer .bugs a { text-decoration:underline; }
.footer .bugs a:hover { text-decoration:none; }
.footer address { margin:0 0 20px; }
.footer address a {text-decoration:underline; }
.footer address a:hover { text-decoration:none; }
.footer ul { display:inline; }
.footer ul.links { display:block; }
.footer li { background:url(../images/bkg_pipe2.gif) 100% 60% no-repeat; padding:0 7px 0 4px; }
.footer li.last { background:none !important; padding-right:0 !important; }
.footer-container .bottom-container { margin:0 0 5px; }
Use clear:both inside the footer div or apply clear:both in css like:
#footer{
clear: both;
}
Add another div right after your div and before your footer like this:
<div style="clear:both"></div>
This will force any element below it down. You also want to make sure that the footer has clear:both as well (this should always be true of footers)

How to make a CSS horizontal navigation menu?

I need to make a css navigation according to the following style:
DESIRED LOOK
Below are the designs that I have done:-
1)Exhibit A - made using sprites
Note: Ignore the arrangement of the menu items
Pros: works well and has the desired look
Cons: if there is a need to add another menu item, another image must be manually made for that particular menu item. ie. not extensible
2)Exhibit B
Pros: very extensible. If another menu item must be added, new extra images need not be made. Only the menu name need to be typed in the html code.
Cons: the hover effect is not the same as the desired look.
My Requirement
Is to use Exhibit B, along with the hover effect from Exhibit A, but without having to add extra images when a menu item is created(this is what happens in Exhibit A, although it has the desired hover effect).
My approach:
Start working with Exhibit B
For the hover effect in the case of a single menu item use 3 images
a)left most edge
b)repeating slice of the middle area
c)right most edge
Is this correct ?
Is this possible ?
Is there a better way? A link to a tute would be fine.
Thanks
1] css code for Exhibit A
#charset "UTF-8";
* {
margin:0;
padding:0;
list-style: none;
}
ul {
list-style: none;
margin: 0;
padding: 0;
}
img {
border: none;
}
.clear {
clear:both;
}
.nav-container {
width: 960px;
}
#navMenu{
display: inline;
margin: 0;
padding: 0px;
position: relative;
z-index: 5;
}
#navMenu li{
float: left;
display: inline;
}
#navMenu li.navRepeat{
float: left;
display: inline;
background-image:url("../images/navigation_repeat.gif");
width:425px;
height:40px;
}
#navMenu li.navRepeatEnd{
float: right;
display: inline;
background-image:url("../images/navigation_repeat_end.gif");
width:1px;
height:40px;
}
a.navReservations{
display:block;
float:left;
width:89px;
height:40px;
background-repeat:no-repeat;
background: url("../images/reservations.gif")
}
a.navReservations:hover{
background: url("../images/reservations.gif") 0 40px;
}
a.navRentals{
display:block;
float:left;
width:62px;
height:40px;
background-repeat:no-repeat;
background: url("../images/rentals.gif")
}
a .navReservations {
float: left;
display: inline;
height: 100px;
width: 400px;
}
a.navRentals:hover{
background: url("../images/rentals.gif") 0 40px;
}
a.navTariffs{
display:block;
float:left;
width:59px;
height:40px;
background-repeat:no-repeat;
background: url("../images/tariffs.gif")
}
a.navTariffs:hover{
background: url("../images/tariffs.gif") 0 40px;
}
a.navFleet{
display:block;
float:left;
width:64px;
height:40px;
background-repeat:no-repeat;
background: url("../images/fleet.gif")
}
a.navFleet:hover{
background: url("../images/fleet.gif") 0 40px;
}
a.navTools{
display:block;
float:left;
width:56px;
height:40px;
background-repeat:no-repeat;
background: url("../images/tools.gif")
}
a.navTools:hover{
background: url("../images/tools.gif") 0 40px;
}
a.navReports{
display:block;
float:left;
width:71px;
height:40px;
background-repeat:no-repeat;
background: url("../images/reports.gif")
}
a.navReports:hover{
background: url("../images/reports.gif") 0 40px;
}
a.navSystem-Management{
display:block;
float:left;
width:133px;
height:40px;
background-repeat:no-repeat;
background: url("../images/system_management.gif")
}
a.navSystem-Management:hover{
background: url("../images/system_management.gif") 0 40px;
}
2] css code for Exhibit B
#navigation {
width: 959px;
height: 36px;
margin: 0;
padding: 0;
background-image: url(images/navigation-bg.gif);
background-repeat: no-repeat;
background-position: left top;
border: 1px solid #CCC;
}
#navigation ul {
list-style: none;
margin: 0;
padding: 0;
}
#navigation ul li {
display: inline;
margin: 0px;
}
#navigation ul li a {
height:27px;
display: block;
float: left;
color: #000;
text-decoration: none;
font-family: Arial;
font-size: 12px;
font-weight: bold;
background-image: url(images/navigation-separator.gif);
background-repeat: no-repeat;
background-position: right center;
padding-top: 6px;
padding-right: 15px;
padding-left: 15px;
vertical-align: 10%;
padding-bottom: 4px;
}
#navigation ul li a:hover {
color:#FFF;
background-image: url(images/navigation-hover.gif);
background-repeat: repeat-x;
background-position: left top;
}
#navigation ul li#active a {
color:#363636;
background: url(images/navigation-hover.png) repeat-x left top;
}
Well you technically only need two sprites, a wide left + body of the tab and a right side. By wide, I mean, 400px or some arbitrarily wide size that you don't anticipate hitting. You're trading a kb for easy of use. You can accomplish this by having markup like:
<ul class="list">
<li>Text</li>
</ul>
with css like:
ul.list
{
list-style-type: none;
margin: 0;
}
ul.list li
{
float: left;
background: url(leftpluswide.png) top left no-repeat;
}
ul.list li a
{
background: url(right.png) top right no-repeat;
}
The only caveat is that since the right.png will be overlapping the background on the li, you'll need to make sure that it doesn't have any transparency.
Also for completeness sake, you might need to apply a height to the li and the a (which will potentially require a display:inline-block or a line-height to take it) to make everything line up well.