Making a vertical nav using css sprite - css

Hi i am having trouble making a vertical navigation using a sprite as a .gif file.
I want to have it with a gray background and use my sprite to change as I hover. If you look at my sprite i have 2 pairs of each button, i want the faded icon to be there first then when hovered it moves it to the 100% opacity icon. Here is what i have so far...
link to view my sprite
my css:
#socialmedia {
margin: 0;
padding: 0;
list-style: none;
background:#666;
width:150px;
}
#socialmedia a {
display:block;
width:137px;
height:10px;
margin: 1em 0; padding:7px 0 10px 20px;
font: bold 14px/1 sans-serif;
color: #000;no-repeat;
text-decoration: none;
}
#socialmedia a:hover {
background-position: -157px 0;
color: #fff;
background: url("images/buttons.gif") 0 0
}
#socialmedia a:active {
background-position: -314px 0;
color:white;
}
my html:
<ul id="socialmedia">
<li>FB</li>
<li>TW </li>
<li>LI</li>
<li>GM</li>
<li>YH</li>
</ul>

I'd change a couple of things with your sprite to make it easier - the images should have no space between them and the icons should be aligned vertically, unless you want them to move horizontally when moused over in addition to changing opacity?
At any rate, you could do something like this:
#socialmedia {
margin: 0;
padding: 0;
list-style: none;
background:#666;
width:150px;
}
#socialmedia li a {
display:block;
width:137px;
height:10px;
margin: 1em 0;
padding:7px 0 10px 20px;
font: bold 14px/1em sans-serif;
color: #666;
background: transparent url("buttons1.gif") 0 0 no-repeat;
text-decoration: none;
}
#socialmedia li a:hover {
background-position: 0 -32px;
color: #fff;
}
#socialmedia li a.twitter {
background-position: 0 -63px;
}
#socialmedia li a.linkedin {
background-position: 0 -127px;
}
#socialmedia li a.google {
background-position: 0 -191px;
}
#socialmedia li a.yahoo {
background-position: 0 -255px;
}
#socialmedia li a.twitter:hover {
background-position: 0 -95px;
}
#socialmedia li a.linkedin:hover {
background-position: 0 -159px;
}
#socialmedia li a.google:hover {
background-position: 0 -223px;
}
#socialmedia li a.yahoo:hover {
background-position: 0 -287px;
}
Then in your html just add the correct classes:
<ul id="socialmedia">
<li>FB</li>
<li>TW </li>
<li>LI</li>
<li>GM</li>
<li>YH</li>
</ul>
Oh, and you'll need a different color for your link text - #000 won't work too well on top of black :)
I changed it to #666.

Related

ul li css issue for menu

I am trying to change from anchor tag to ul li but it doesn't seem to work.
Can you find out where I need to change CSS of my code?
Original link:https://codepen.io/arkev/pen/DzCKF
My code: https://codepen.io/SankS/pen/YRNzGK
<ul>
<li>Browse</li>
<li>Compare</li>
<li>Order Confirmation</li>
<li>Checkout</li>
</ul>
Minor changes in css and change 'active' class to li element
/*custom font*/
#import url(https://fonts.googleapis.com/css?family=Merriweather+Sans);
* {
margin: 0;
padding: 0;
}
html,
body {
min-height: 100%;
}
a{text-decoration:none;}
body {
text-align: center;
padding-top: 100px;
background: #689976;
background: linear-gradient(#689976, #ACDACC);
font-family: 'Merriweather Sans', arial, verdana;
}
.breadcrumb {
/*centering*/
display: inline-block;
box-shadow: 0 0 15px 1px rgba(0, 0, 0, 0.35);
overflow: hidden;
border-radius: 5px;
/*Lets add the numbers for each link using CSS counters. flag is the name of the counter. to be defined using counter-reset in the parent element of the links*/
counter-reset: flag;
}
.breadcrumb li {
text-decoration: none;
outline: none;
display: block;
float: left;
font-size: 12px;
line-height: 36px;
color: white;
/*need more margin on the left of links to accomodate the numbers*/
padding: 0 10px 0 60px;
background: #666;
background: linear-gradient(#666, #333);
position: relative;
}
/*since the first link does not have a triangle before it we can reduce the left padding to make it look consistent with other links*/
.breadcrumb li:first-child {
padding-left: 46px;
border-radius: 5px 0 0 5px;
/*to match with the parent's radius*/
}
.breadcrumb li:first-child:before {
left: 14px;
}
.breadcrumb li:last-child {
border-radius: 0 5px 5px 0;
/*this was to prevent glitches on hover*/
padding-right: 20px;
}
/*hover/active styles*/
.breadcrumb li.active,
.breadcrumb a:hover {
background: #333;
background: linear-gradient(#333, #000);
}
.breadcrumb li.active:after,
.breadcrumb li:hover:after {
background: #333;
background: linear-gradient(135deg, #333, #000);
}
/*adding the arrows for the breadcrumbs using rotated pseudo elements*/
.breadcrumb li:after {
content: '';
position: absolute;
top: 0;
right: -18px;
/*half of square's length*/
/*same dimension as the line-height of .breadcrumb a */
width: 36px;
height: 36px;
/*as you see the rotated square takes a larger height. which makes it tough to position it properly. So we are going to scale it down so that the diagonals become equal to the line-height of the link. We scale it to 70.7% because if square's:
length = 1; diagonal = (1^2 + 1^2)^0.5 = 1.414 (pythagoras theorem)
if diagonal required = 1; length = 1/1.414 = 0.707*/
transform: scale(0.707) rotate(45deg);
/*we need to prevent the arrows from getting buried under the next link*/
z-index: 1;
/*background same as links but the gradient will be rotated to compensate with the transform applied*/
background: #666;
background: linear-gradient(135deg, #666, #333);
/*stylish arrow design using box shadow*/
box-shadow: 2px -2px 0 2px rgba(0, 0, 0, 0.4), 3px -3px 0 2px rgba(255, 255, 255, 0.1);
/*
5px - for rounded arrows and
50px - to prevent hover glitches on the border created using shadows*/
border-radius: 0 5px 0 50px;
}
/*we dont need an arrow after the last link*/
.breadcrumb li:last-child:after {
content: none;
}
/*we will use the :before element to show numbers*/
.breadcrumb li:before {
content: counter(flag);
counter-increment: flag;
/*some styles now*/
border-radius: 100%;
width: 20px;
height: 20px;
line-height: 20px;
margin: 8px 0;
position: absolute;
top: 0;
left: 30px;
background: #444;
background: linear-gradient(#444, #222);
font-weight: bold;
}
.flat li,
.flat li:after {
background: white;
color: black;
transition: all 0.5s;
}
.flat li a {color:black;}
.flat li a:hover{background:none;}
.flat li:before {
background: white;
box-shadow: 0 0 0 1px #ccc;
}
.flat li:hover,
.flat li.active,
.flat li:hover:after,
.flat li.active:after {
background: #9EEB62;
}
<!-- a simple div with some links -->
<!-- another version - flat style with animated hover effect -->
<div class="breadcrumb flat">
<ul>
<li class="active">
Browse
</li>
<li>Compare</li>
<li>Order Confirmation</li>
<li>Checkout</li>
</ul>
</div>
<!-- Prefixfree -->
<script src="http://thecodeplayer.com/uploads/js/prefixfree-1.0.7.js" type="text/javascript" type="text/javascript"></script>
Try left floating the li tags to get the horizontal look:
.breadcrumb li {
float: left;
}
Try this, I think this will help you
.flat ul li{
float:left;
}

CSS - li element set height

I am trying to build a navigation menu. Here are some pieces.
#main-menu .nav-bar { list-style:none; margin-top: 40px;}
#main-menu .nav-bar li { display:inline; padding:0 10px;}
#main-menu .nav-bar li a {
text-decoration: none;
padding-left: 50px;
text-transform: uppercase;
color: #333;
display: inline-block;
text-shadow: 1px 1px 1px #ccc;
}
.nav-bar .nav-button-home a { background:url("home.png") no-repeat 0px -20px transparent;}
<nav id="main-menu">
<ul class="nav-bar">
<li class="nav-button-home">Home</li>
</ul>
</nav>
What happens is that li element is not tall enough to show the picture.
Any idea how I can increase a height li element so will show the whole picture?
Thanks
I don't think there's a way to make your li stretch dynamically to the size of your background image. You can easily do the reverse however, set a definite height to your li, then set your background to 'contain'. This scales the image down to fit inside your li without clipping.
Updated jsFiddle
css
li {
height:180px;
width:240px;
background-image: url("http://assets.worldwildlife.org/photos/2090/images/hero_small/Sumatran-Tiger-Hero.jpg?1345559303");
background-size: contain;
background-repeat: no-repeat;
border:1px solid #656565;
display:inline-block;
position:relative;
}
span {
position:absolute;
top:140px;
width:100%;
text-align:center;
background-color:rgba(255, 255, 255, 0.9);
padding:10px 0 10px 0;
border:1px solid #656565;
}
Remove background Property "transparent"
#main-menu .nav-bar { list-style:none; margin-top: 40px;}
#main-menu .nav-bar li { display:inline; padding:0 10px;}
#main-menu .nav-bar li a {
text-decoration: none;
padding-left: 50px;
text-transform: uppercase;
color: #333;
display: inline-block;
text-shadow: 1px 1px 1px #ccc;
}
.nav-bar .nav-button-home a { background:url("home.png") no-repeat 0px -20px;}
<nav id="main-menu">
<ul class="nav-bar">
<li class="nav-button-home">Home</li>
</ul>
</nav>
<style type="text/css">
body { font-family: sans-serif; }
#main-menu .nav-bar { list-style:none; margin-top: 40px; }
#main-menu .nav-bar li { display:inline; padding:0px 30px; }
#main-menu .nav-bar li a {
height:48px;
width:48px;
display: inline-block;
background-size: contain;
background-repeat: no-repeat;
text-decoration: none;
padding-left: 25px;
text-transform: uppercase;
color: #333;
text-shadow: 1px 1px 1px #ccc;
position:relative;
}
.nav-bar .nav-button-home a { background:url("commons/imgs/prism/home.png") 0px -0px; }
.nav-bar .nav-button-assets a { background:url("commons/imgs/prism/assets.png") 0px -0px; }
.nav-bar .nav-button-alarms a { background:url("commons/imgs/prism/alarms.jpg") 0px -0px; }
span {
position:absolute;
top:50px;
left:0px;
width:100%;
text-align:left;
padding:10px 0 10px 0;
}
</style>
<nav id="main-menu">
<ul class="nav-bar">
<li class="nav-button-home"><span>Home</span></li>
<li class="nav-button-assets"><span>Assets</span></li>
<li class="nav-button-alarms"><span>Alarms</span></li>
</ul>
</nav>
The only problem I have is that text center is not fully aligned with a center of an image.

Sprites not displaying

Sprite rollover images not displaying.
The goal is to have a row of icons with a rollover controlled by CSS.
Currently, the code below does not display any images...what am I missing?
CSS:
#social {
margin: 0;
padding: 0;
height: 15px;
}
#social li {
margin: 0 5px 0 0;
padding: 0;
list-style-type: none;
display: inline;
height: 15px;
float: left;
}
#social li.last{
margin-right:0px;
}
#social li a {
background-image: url("../images/icon_twitter.png") 0px 0px;
background-repeat: no-repeat;
display: block;
height: 15px;
width: 18px;
}
#social li#social-twitter a{
background-position: 0px 0px;
}
#social li#social-twitter a:hover {
background-position: 0px -15px;
}
#social li#social-youtube a{
background-position: -18 top;
}
#social li#social-youtube a:hover {
background-position: -18 -15px;
}
#social span {
display: none;
}
HTML:
<ul id="social">
<li id="social-twitter"><span>Twitter</span></li>
<li id="social-youtube" class="last"><span>Youtube</span></li>
</ul>
You are trying to set the background position within background-image.
Change this:
background-image: url("../images/icon_twitter.png") 0px 0px;
To this:
background-image: url("../images/icon_twitter.png");
background-position: 0px 0px;
Problem: You are using background-position with background-image property
Solution: Either use only background property or use background-position separately
background: color url(src) repeat position;
or
background-image: url(src);
background-position: position;
Your code should like this:
background: url("../images/icon_twitter.png") 0 0 no-repeat;
Note: You should use px (or any other unit) with non zero numbers and zero should be used without unit.

Align an Icon and Feed Heading

I am trying to align an image with an , and I cannot get the heading to wrap around the image icon. I have a screen cap here: http://instagram.com/p/YNGBzrtAs8/
My CSS code is a mess because I keep trying everything, and it's getting messy. Here is the current mess state:
#deck-sub .news-feed { float: left; width: 90%; padding: 5%; margin: 0 0 15px 0; }
#deck-sub h1 { background: none; font: bold 2.0em Arial, Helvetica, sans-serif; color: #006586; margin: 0 0 -8px 0; }
#deck-sub .news-feed h2 a { color: #006586; text-decoration: none; font-size: 1.2em !important; margin: -33px 0 0 0;}
#deck-sub .news-feed ul {vertical-align: middle !important; background: none; padding: 5px 0 0 0; list-style: none; }
#deck-sub .news-feed ul li { vertical-align: middle !important; width: 100%; padding: 5px 0 5px 0; margin: 5px 0 0 0;}
#deck-sub .news-feed ul li a { vertical-align: middle !important; width: 100%; font: 0.8em/1.1em Arial, Helvetica, sans-serif; color: #555 !important; text-decoration: none; padding: 0px 0 0 0; margin: -5px 0 0 0; }
#deck-sub .news-feed ul li a:hover { background: none; color: #009fc7 !important; }
#deck-sub .new-feed ul li img { vertical-align: middle !important; }
#deck-sub .sfnewsListItem { vertical-align: middle !important; background: #ccc; }
#deck-sub .sfnewsMetaInfo { vertical-align: middle !important; padding: 0px; margin: 0px; background: #444;}
Any help would be greatly appreciated. I have run into this before, but my tricks are not working in this case. Thank you in advance.
I'm not sure what you mean by get the heading to wrap around...but I assume you want the image and the title to be beside eachother? vertical-align I don't believe works awesomely for this.
The best option is to remove the icon as an and instead put it into the CSS as a background image. Doing that gives you the ability to position it to the pixel.
It'd also let you sprite those two news\event icons into a single file to serve less resources.
http://www.w3schools.com/css/css_image_sprites.asp
Cheers!
Steve

Mouseover event for UL

I am trying to do an image change for a mouseover, in a ul navigation. I can't seem to try to get it to work. Here is my code:
<ul id="nav">
<li>Home</li>
<li>About</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
and the css:
ul#nav {
width: 940px; list-style: none; overflow: hidden; margin: -134px auto 25px auto;}
ul#nav li {width: 126px; height: 33px; float: left; padding: 13px 0 0 0;
font-weight: bold; text-align: center; text-transform: uppercase; }
ul#nav li:nth-child(1) {
margin: 0 60px 0 0;
}
ul#nav li:nth-child(2) {
margin: 0 316px 0 0;
}
ul#nav li:nth-child(3) {
margin: 0 60px 0 0;
}
ul#nav li:nth-child(4) {
margin: 0;
}
ul#nav li a {
color: white; text-decoration: none;
}
ul#nav li a:hover {
color: #660066;
}
basically where I have "home" "about" "portfolio" and "contact" I want to replace with an image that then does a mouseover to a different image, is this possible???
Without javascript, you're going to have to use the background css attribute, and then use the :hover pseudoclass to change the image source.
This website gives a fairly comprehensive overview of using the background attribute.
Basically it will be something like:
#nav li {
background: url(images/image1.png) 0 0 no-repeat;
}
#nav li:hover {
background-image: url(images/image2.png);
}

Resources