CSS Sprites, puzzle - html

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

Related

Smaller underline effect [duplicate]

This question already has answers here:
Title with bottom border smaller than width
(7 answers)
Closed 8 years ago.
I came across interesting underline effect that looks like this:
It's simple, but I can't think of a way to achieve it without using additional html elements in markup, that will be not semantic. I am wondering if it is possible to achieve it using css and without having any additional elements. Effect is essentially an underline / bottom border that is smaller than element and centered under it.
Here is my markup for navigation, where this effect will be used on current page links.
<nav id="navigation" class="right">
<ul>
<li> Home </li>
<li> About </li>
<li> Work </li>
<li> Blog </li>
<li> Contact </li>
</ul>
</nav>
try this one - http://jsbin.com/lumasive/1/
#navigation li a { position:relative; }
#navigation li a:after {
content: '';
position:absolute;
bottom:0;
left: 30%;
right: 30%;
height: 2px;
background:red;
display:block;
}
same as others , the use of a pseudo , but in the flow: DEMO
li ,a {
display:inline-block;
color:#EE7972;
font-size:40px;
font-variant:small-caps;
text-decoration:none;
}
a {
margin:1em;
}
a:after {
content:'';
display:block;
height:0.2em;
width:35%;
margin:auto;
border-bottom:solid ;
}
a:hover {
color:turquoise;/* change color of text and mini-border*/
}
Without additional HTML:
jsFiddle
You can use the "after" css property:
a:after {
display: block;
position: absolute;
content:"__";
width: 100%; top: 10px;
text-align: center;
left: 0;
}
You can use an :after pseudo-element to append extra markup your a elements:
Like all the other answers, but perhaps a little less CSS required.
a:after {
display: block;
content: "";
width: 60%;
margin: 0 auto;
border-bottom: solid 1px steelblue;
}
http://codepen.io/anon/pen/qebHo
use "after" property to achieve this. : jsFiddle
CSS:
.right ul li a{
position:relative;
text-decoration:none;
}
.right ul li a:after{
content: '';
position:absolute;
bottom:0;
left: 30%;
right: 30%;
background:black;
height:1px;
}
You can as well use linear backgrounds: DEMO or DEMO 2
CSS demo 1
a {
margin:1em;
padding-bottom:0.2em;
background:linear-gradient(
to left,
transparent 33%,
#EE7972 33%,
#EE7972 66%,
transparent 66%
)
bottom no-repeat;
background-size: 100% 3px;
}
CSS demo 2
a {
margin:1em;
padding-bottom:0.2em;
background:linear-gradient(
to left,
#EE7972 ,
#EE7972
)
bottom no-repeat;
background-size: 1em 3px;
}
Possible animation with this border: border animated

Horizontal menu in center

doing this for the first time so please be gentle. :) I am aiming for navigation menu in the centre, horizontal, with image in the middle list item. Image will be much bigger as the bottom half is name of the my company and top of the picture might be touching the top. My first problem is that the li elements are only as big as the text, whitch doesnt serve the center-thing purpouse and the second one related that it stretches the whole menu when hoovered on. Please I'm looking for solution where the text is in the middle of li and img sits down on bottom. Thanks so much for help!
<div id="menu">
<ul>
<li><span>Link 1</span></li>
<li><span>Link 2</span></li>
<span><li style="text-algin:bottom;"><img src="Linbach_tuzka.png" height="175px" alt="Domu"></li></span>
<li><span>Link 4</span></li>
<li><span>Link 5</span></li>
</ul>
</div>
body {
width: auto;
background-image: url(blue4.jpg);
background-size: cover;
margin: 2px 0 0 0;
}
#menu {
height:210px;
line-height:36px;
margin:0 auto;
text-align:center;
width:800px;
padding:0;
}
#menu ul {
display: inline;
-webkit-padding-start: 0px;
-webkit-margin-before: 2x;
-webkit-margin-after: 0px;
margin:0;
font-size: 0;
}
#menu ul li {
text-algin:center;
display:inline;
font-family:Arial,sans-serif;
font-size:40px;
padding:0;
margin:0;
text-decoration:none;
background-image:url(../Pics/Buttons/Menu/Menu.gif);
min-width:100px !important;
}
#menu a {
text-decoration:none;
color:#000000;
margin:10px 0;
padding:0;
}
#menu a:hover {
font-weight:bolder;
}
span {
width:100%;
font-size:30px;
}
the only option is left is width to <a> tag : DEMO
I have removed the direct <span> from UL and have added class 'widthAuto' so that it will not affect your logo.
#menu a {
text-decoration:none;
color:#000000;
margin:10px 0;
padding:0;
min-width:100px !important; display:inline-block;
}
Note : Menu will stretch on hover if text exceed min-width.

Wont remove divider lines on mouse over

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.

how to apply same declaration to many different objects?

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.

CSS sprite rollovers showing up vertical instead of horizontal

I am trying to make a simple rollover image for this page - www.radioandweb.com. The CSS Sprite code I've used works fine until I put it into the actual page structure. It then changes from being horizontal to being vertical. I am guessing this is because of interfering with other CSS properties.
Can someone suggest an easy fix for this? The image in question is in the top right corner (facebook, twitter, linkedin). Here is the CSS code:
ul#socialnavigation {
width:109px;
height:34px;
margin-left:auto;
margin-right:auto;
}
ul#socialnavigation li {
position:relative;
float:left;
text-indent:-9999px;
list-style-type:none;
}
ul#socialnavigation li a {
border:0;
display:block;
text-decoration:none;
background:transparent url('http://www.radioandweb.com/wp-content/themes/u-design/styles/style1/images/socialnetworkrollovers.png') no-repeat;
}
li#facebook a {
width:36px;
height:34px;
}
li#twitter a {
width:37px;
height:34px;
}
li#linkedin a {
width:36px;
height:34px;
}
li#facebook a:hover, li#facebook a:focus {
background-position:0px -34px;
}
li#twitter a:link, li#twitter a:visited {
background-position:-36px 0px;
}
li#twitter a:hover, li#twitter a:focus {
background-position:-36px -34px;
}
li#linkedin a:link, li#linkedin a:visited {
background-position: -73px 0px;
}
li#linkedin a:hover, li#linkedin a:focus {
background-position: -73px -34px;
}
And here is the HTML code:
<ul id="socialnavigation">
<li id="facebook">Facebook</li>
<li id="twitter">Twitter</li>
<li id="linkedin">Linked In</li></ul>
Thanks, any help is really appreciated!
In your text.css file you have
li {
margin-left: 30px;
}
which is conflicting with your sprite css. If you just update your "ul#socialnavigation li" to include something like "margin-left:auto" it should fix it.
Long live the okanagan! :)
The parent container isn't wide enough therefore your li's aren't floating left.
ul#socialnavigation{
width: 200px;
}