I'm doing some hacks in CSS to accommodate our old template infrastructure in a new layout. Our menu has an 'active' state, correspondingly to the section I'm in.
Trying to accomplish this I wrote:
div#left-col ul li.cidades.Cidades a, div#left-col ul li.amizade.Amizade a, div#left-col ul li.encontros.Encontros a,div#left-col ul li.idade.Idade a {
display:block;
background:transparent url(http://bp.i.bol.com.br/v11/menu-esq-a.png) no-repeat scroll -161px -4px;
color:white;
width: 166px;
}
but it just don't work! the style is applied to only one of the elements. and I ended up writing this code to correct the problem:
div#left-col ul li.cidades.Cidades a {
display:block;
background:transparent url(http://bp.i.bol.com.br/v11/menu-esq-a.png) no-repeat scroll -161px -4px;
color:white;
width: 166px;
}
div#left-col ul li.amizade.Amizade a {
display:block;
background:transparent url(http://bp.i.bol.com.br/v11/menu-esq-a.png) no-repeat scroll -161px -4px;
color:white;
width: 166px;
}
div#left-col ul li.encontros.Encontros a {
display:block;
background:transparent url(http://bp.i.bol.com.br/v11/menu-esq-a.png) no-repeat scroll -161px -4px;
color:white;
width: 166px;
}
div#left-col ul li.idade.Idade a {
display:block;
background:transparent url(http://bp.i.bol.com.br/v11/menu-esq-a.png) no-repeat scroll -161px -4px;
color:white;
width: 166px;
}
But I don't understand the problem nor the solution....
EDIT: here is the HTML code I'm trying to apply this style:
<div id="left-col">
<ul>
<li class="amizade Idade">Amizade</li>
<li class="cidades Idade">Cidades</li>
<li class="encontros Idade">Encontros</li>
<li class="idade Idade">Idade</li>
</ul>
</div>
Note that I want to have the style applied only when 2 repeated words appears in a class.
EDIT 2:
I solved the problem by moving the correct declarations (the ones with the many elements followed by commas) above this one:
div#left-col ul li a{outline: 0px dashed red;display:block; background:transparent url(menu-esq-a.png) no-repeat scroll 0px -4px; height:22px; padding:8px 0 0 23px; margin:0; font-family: Arial, Sans-serif; font-weight: bold; font-size: 14px; text-decoration:none; color:#00574a}
which was supposed to be the "default" status for my 's. Weird, since I thought the most specific declaration would won over the lesser.
You already have a common css class applied to all items (it's Idade, and it's a part of each element's class atttribute).
This means that it is sufficient (and recommended) to declare the style for that class only:
div#left-col ul li.Idade {
display:block;
background:transparent url(/v11/menu-esq-a.png) no-repeat scroll -161px -4px;
color:white;
width: 166px;
}
As a side note, a different name may be more appropriate for a common class, since only one of your elements' contents matches this name. Name like menuItem would be much more descriptive than Idade IMO.
Related
i've been designing an menu for my website. i've reached an issue with converting in to html/css. The idea is to have an divider line on each side of the text and on mouse over the navigation lines will disappear and show the hover image. but whatever i do the line is still there on one of the sides.
An image of my navigation menu
nav-lnie.png: is just only the line
hover.png is the whole mouseover image
does anybody have a solution or an explanation how to do this?
css looks like this:
.navigation{
width:370px;
float:left;
position: absolute;
left: 300px;
background:url(../images/nav-lnie.png) repeat-y 0 0;
padding:0 0 0 4px; font-size:14px;
font-family:Arial, Helvetica, sans-serif;
color:#fff; text-shadow:1px 1px 1px #333
}
.navigation ul li{background:url(../images/nav-lnie.png) repeat-y right 0;
margin:0 2px 0 0;
}
.navigation ul li a{
display:block;
float:left;
width:90px;
height:38px;
padding:70px 0 0 0;
text-align:center;
color:#fff;
text-decoration:none;
}
.navigation ul li a:hover{
background:url(../images/hover.png) repeat-x;
}
And html like this:
<div class="navigation">
<ul>
<li>Videos</li>
<li>Top Videos</li>
<li>Upload</li>
<li>FAQ</li>
</ul>
</div>
It's most likely due to the margin code you have here:
.navigation ul li{
background:url(../images/nav-lnie.png) repeat-y right 0;
margin:0 2px 0 0;
}
Since there's a 2px margin on the right of each menu item, the left margin won't get hidden if you mouse over the next element. If the margin isn't really needed, you can remove it and it should work fine, given that there's enough space. If it's necessary, then on the hover command, you can change the spacing on the element:
.navigation ul li a:hover{
background:url(../images/hover.png) repeat-x;
margin-left: -2px;
padding-left: 2px;
}
Of course, it's a rough hack to fix the problem. Spacing can be adjusted on both ends as well.
I am trying to create a navigation menu that is evenly spaced regardless if the menu item is 1 line or 2 lines of text. I have this working with 1 line of text but the vertical spacing of the text is off if an item hits more than one line.
My code that I have so far is below. Any help would be awesome. Thanks in advance.
jsfiddle: http://jsfiddle.net/wnfUC/
Style:
#pageNavigation {
background-image: url('../Images/TIBC_Base/nav-bg.png');
background-repeat: repeat-y;
margin:5px 0;
padding:5px 15px 5px;
min-height:125px;
}
#pageNavigation_bottom
{
clear:both;
background-image: url('../Images/TIBC_Base/nav-bg_bottom.png');
background-repeat: no-repeat;
margin:-5px 0 0 -1px;
min-height:8px;
}
#pageNavigation .navContent{ width:240px; margin:0 -10px; }
#pageNavigation ul { list-style-type: none; margin:0; padding:0; }
#pageNavigation ul li { display: block; height:57px; border-top:0px #E1E1E1 solid; border-bottom:1px #E1E1E1 solid; text-align:center; overflow:hidden; }
#pageNavigation a {
color:#485963;
font-size:16px;
text-decoration:none;
text-shadow: 0px -1px #EEEEEE;
display:block;
height:57px;
}
#pageNavigation a:hover
{
background: #FAE2AD;
color: #485963;
}
#pageNavigation a.NavigationSelected
{
color:#F9F9F9;
background: #A5B5BE;
text-shadow: 1px 1px #485963;
font-weight: normal;
}
HTML
<div id="pageNavigation">
<ul class="navContent">
<li>Services</li>
<li>Analysis</li>
<li>Strategic Planning</li>
<li>International Market and Competitor Research</li>
<li>Budgeting and Forecasting</li>
<li>International Cultural Liaison</li>
</ul>
</div>
You can use CSS table layout (not HTML table element, eh!) to achieve this: http://jsfiddle.net/PhilippeVay/ZszJm/
ul is displayed with the same algorithm as a table, links with the same algorithm than cells and here li are displayed as rows as it's vertical. And then you can play with vertical-align as much as you want :) (in your case middle value)
You can add table-layout: fixed to ul and then browsers will use the other algorithm for displaying tables, the one that doesn't try to adapt widths and heights of cells to their content but will stick to what CSS rules say.
Compatibility: IE8 and above. It won't be centered in IE7 and 6, not a big deal.
EDIT: with this method, you don't need to know in advance which items are longer than others. Browsers will figure that.
Vertical alignment of text is generally accomplished using line-height: http://jsfiddle.net/Shmiddty/wnfUC/1/
#pageNavigation a {
...
height:57px;
line-height:57px;
}
#pageNavigation a.two-line{
line-height:20px;
padding-top:10px;
}
Note that I added the class two-line to the anchor element that spanned two lines.
You could use this method: http://css-tricks.com/vertically-center-multi-lined-text/
There are also some other methods you could use, but they require extra HTML markup, which this one does not.
I am pretty new at CSS but have been learning, doing my moms small business website to save her money but I'm having a little CSS trouble with my nav bar.
Basically if you go here: http://area25dallas.com/s and look at the nav bar, I'm having trouble with the il listing to have the images line up vertically (instead of aligning with the top which is what they currently do) with the text, also for some reason the images are going on top of each other instead of sitting next to each other (I don't want them in separate lists like the text links because the margins are too spread out).
I have been playing around with the CSS and also googled the hell out of this but still haven't found a solution. Is there any quick fix to this?
Thanks!
EDIT:
Here is the HTML and CSS blips though if you are using chrome I feel just inspecting the elements are the easiest way to see what's going on
<div id = "header">
<div class = "container">
<ul id = "main-menu">
<li class = "active">home</li>
<li>about</li>
<li>gallery</li>
<li>press</li>
<li>contact</li>
<li><img src="images/twitter_newbird_boxed_ white.png" />
<img src="images/Pinterest_Favicon white.png" /></li>
</ul>
</div>
</div>
and the CSS
#main-menu
{
float: right;
position:relative;
top:122px;
right:150px;
}
#main-menu li
{
float: left;
margin: 30px 12px 15px 12px;
padding:0;
height:23px;
list-style:none;
line-height:20px;
}
#main-menu li:hover, #main-menu li.active { background-position: 0 -23px;}
#main-menu li:hover a, #main-menu li.active a{
background-position: 100% -30px;
}
#main-menu li a
{
display:block;
padding:0px 15px 5px 10px;
font-size:17px;
color:#fff;
text-decoration:none;
}
The images are broken onto multiple lines because they reside inside an <a> tag which has been styled as a block level element. Change the style to something like:
#main-menu {
float: right;
position: relative;
right: 75px; /* Changed */
top: 122px;
}
#main-menu li a {
color: #fff;
display: inline-block; /* Changed */
font-size: 17px;
padding: 0 15px 5px 10px;
text-decoration: none;
}
/* New */
#main-menu li a img {
position: relative;
top: -10px;
}
The new rule at the bottom moves the images up a little bit. You can play around with your css and get the same results in a lot of different ways - I went with a method that didn't involve many changes to the existing work.
Thanks for the tips, guys, this helped me out too with images in my css navigation.
I'd also recommend some added code to alleviate your spacing issue ...
#main-menu li a img {
position:absolute;
background:inherit;
top: 0px;
margin-bottom:auto;
max-height: 33px;
}
I am trying to do a custom bullet list. However, I want to use the same background-image, but changing the background-position (to give a cool effect)
The CSS I have is:
#sidebar ul{
width:190px;
list-style:none;
margin:0;
padding:0;
}
#sidebar li{
border-top:1px dashed #ddd;
background:#FAFAFA url('./images/bullet.png') no-repeat 15px 9px;
}
#sidebar li:hover{
background-color:#fff;
background-position:15px 0px;
}
#sidebar li a{
display:block;
padding:5px 20px 5px 26px; /*26 to give extra 6px for the bullet*/
}
The bullet changes correctly, and everything is ok. Except that both bullets are always visible :(
I want to know if there is a way to hide the other bullet.
An option could be to spread the images very far away (more than the height will ever be), but this is just a bad idea, and I don't want to have a big image size.
I am open for other methods, if the way I am trying to do is just not good and you know a better way, please tell me.
I think it would be better to do something like this. Adjust values to your needs.
<li><span></span></li>
.
li { position: relative; }
li span {
position: absolute;
left: 0;
width: 16px;
height: 16px;
margin-right: 16px;
background: url('img.jpg') 0 0 no-repeat;
}
li:hover span { background-position: 0 -16px; }
May be this seems silly question for you guys.. Its about CSS Sprites. I have a navigation which contains 4 menus like.. HOME COMPANY SERVICES SUPPORT although I used a css sprite that have 3 mode/state for static, hover and selected(class called 'current'). I used to call them like..
ul#top-nav-links {list-style:none; background:url(../images/nav-bg.png) no-repeat scroll 0 0; width:508px; height:35px; float:left; margin-left:80px; margin-top:33px; padding-left:4px; margin-right:23px;}
ul#top-nav-links li{float:left; position:relative; z-index:99999;}
ul#top-nav-links li a.home01{background:url(../images/nav.png) no-repeat scroll 0 0; display:block; width:100px; height:31px; text-indent:-999px; float:left;}
ul#top-nav-links li a.company01{background:url(../images/nav.png) no-repeat scroll 0 0; display:block; width:150px; height:31px; text-indent:-999px; float:left; background-position:-100px 0px;}
ul#top-nav-links li a.services01{background:url(../images/nav.png) no-repeat scroll 0 0; display:block; width:140px; height:31px; text-indent:-999px; float:left; background-position:-250px 0px;}
ul#top-nav-links li a.support01{background:url(../images/nav.png) no-repeat scroll 0 0; display:block; width:115px; height:31px; text-indent:-999px; float:left; background-position:-390px 0px;}
ul#top-nav-links li a.current{background:url(../images/nav.png) no-repeat scroll 0 -62px; display:block; width:100px; height:31px; text-indent:-999px; float:left;}
and here is the image I used
so I need to display the middle colored one on hover state, although the last one for the current state, of course the current state wasn't need hover effect..
I know, It should call like this..
ul#top-nav-links li a.company01:hover{background-position:-100px -31px;}
but I curious if somehow that code should be shortened by avoiding to call each menu as separate instead like this...
ul#top-nav-links li a:hover(background-position:0px -31px;}
the above one I tried but the horizontal positioning of the image wasn't possible..
Any thoughts?
drop down a comment, if this question was confused.. :)
I'm not positive about cross-browser support, but this at least works in Chrome 15.
http://jsfiddle.net/tkZMB/
li:hover {
background-position-y: -31px;
}
You could combine this to simplify your overall CSS too.
/* General list item declaration */
li {
width: 130px;
height: 30px;
border: 1px solid gray;
float: left;
background: url(http://i.stack.imgur.com/m5HOI.png);
}
/* For each child move menu over */
li:nth-child(2) {
background-position-x: -100px;
}
/* On hover slide the background up. */
li:hover {
background-position-y: -62px;
}
Sorry, just modified your code to this, though I hope this will help you to produce efficient markup (semantically-correct) and style sheet codes: hopeful that will also solve browser inconsistencies in your codes.
HTML:
<ul class="section">
<li class="home current">
Home
</li>
<li class="company">
Company
</li>
<li class="services">
Services
</li>
<li class="support">
Support
</li>
</ul>
CSS:
.section li {
display: inline;
}
.section a {
background: url(../images/nav.png) no-repeat;
display: inline-block;
}
.section .home a {
background-position: left top;
}
.section .company a {
background-position: -100px 0;
}
.section .services a {
background-position: -250px 0;
}
.section .support a {
background-position: -390px 0;
}
.section .current a {
background-position: 0 -62px;
}