a:active background image? - css

At my website I would like to make the dots in the side change when I'm on the active div box. The hover works fine, but I can't get the active to work. The path for the image is worked fine, when I tried to put it under hover.
#nav{
z-index: 5;
position: fixed;
top: 50%;
right: 20px;
}
#nav li {
position: relative;
height: 20px;
width: 20px;
margin-bottom: 15px;
}
#nav li a {
display: block;
width: 20px;
height: 20px;
text-indent: -9999px;
background: transparent url('images/dot.png') no-repeat;
opacity: 0.80;
}
#nav li a:hover {
opacity: 1;
}
#nav li a:active {
background: transparent url('images/dotactive.png') no-repeat;
}

I don't think it's possible for the image to stay as the active background with just CSS alone. You will need to use a combination of javascript too.
With jQuery you could try something like the below.
.active{background: url('images/dotactive.png') no-repeat !important;}
$('#nav li a').live('click',function () {
$('.active').removeClass('active');
$(this).addClass('active');
});​
EDIT A Workign fiddle of your site keeping the active nav background images. http://jsfiddle.net/ukCG8/

try this out
background: url('images/dotactive.png') no-repeat;
no need for transparent
or use opacity also for tranparency

Try this:
<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/
var Lst;
function CngClass(obj){
if (Lst) Lst.className='';
obj.className='selected';
Lst=obj;
}
/*]]>*/
</script>
And modify the li items like this:
<li>
<a onclick="CngClass(this);" href="#">Test 1
</a>
</li>
I wish I could take credit for the fix; check it out in action here (yes, I'm cheating on stackOverflow with another web dev site!)

Related

Split image in CSS?

I'm trying to edit some CSS (on a tumblr page) and I'm having a problem with an icon. It's the Twitter icon on the far right of this image
Above appears as split in half on the page.
I used the code below for all four of the icons ((just a different url for each image), yet I'm not sure why the Twitter one is split like that.
What could be the reason and how can I fix it?
Code:
#above-nav-links a.twitter:before {
background-image: url(http://imgh.us/twitter_icon_blue.svg);
content: ' ';
display: inline-block;
width: 25px;
height: 25px;
margin-right: 3px;
repeat: no-repeat;
}
If you copy-paste the background-image url, you can see the image I used for the icon (it is not split). The pages I used for the other icons are similar (in terms of spacing, size, etc.).
As I havn't seen your code, you can change your code accordingly
<ul id="#icons">
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<style type="text/css">
#icons > li
{
display: inline-block;
list-style:none;
float:left;
}
#icons > li > a
{
background-image: url("icons.png");
width: 25px;
display: inline-block;
height: 25px;
repeat: no-repeat;
}
#icons > li:nth-child(1) > a
{
background-position:2px -8px;
}
#icons > li:nth-child(2) > a
{
background-position:-29px -8px;
}
#icons > li:nth-child(3) > a
{
background-position:-61px -8px;
}
#icons > li:nth-child(4) > a
{
background-position:-97px -7px;
}
</style>
Background-positions are set according to my icon image. You may need to udpate as per your image.

CSS hovering issue

Please refer this fiddle , http://jsfiddle.net/shrikanth/79AfQ/
After hovering header(h2), div element(popup) is displayed , which is as per design.
However I can't navigate to new div.(new div gets disappear soon after moving out h2 element)
Is there any fix for this , so that user can click on headrer then can click on contact of another div element?
HTML
<h2>What is CSS?</h2>
<div id="popup">
Contact
</div>
CSS
h2 {
position:relative;
top:22px;
left:44px;
width: 170px;
height:33px;
text-align:center;
}
#popup {
width: 240px;
background: #727272;
padding: 10px;
border-radius: 6px;
color: #FFF;
position: relative;
top:15px;
left:44px;
font-size: 12px;
line-height: 20px;
display:none;
}
h2:hover+ #popup {
display:inline-block;
}
h2:hover {
background-color:green;
}
#popup:before {
content:"";
display: block;
width: 0px;
height: 0px;
border-style: solid;
border-width: 0 15px 15px 15px;
border-color: transparent transparent #727272 transparent;
position: absolute;
top: -15px;
left: 92px;
}
Just change the hover pseudo-selector rule to include the #popup element, too (assuming your goal is just to be able to click the contact link in the #popup)
h2:hover+ #popup, #popup:hover{
display:inline-block;
}
If you want to use this approach, I suggest adding padding to the h2 element to allow your mouse to leave it without immediately deactivating the hover state, or wrapping it with a larger, invisible element.
Another way would be to add the #popup inside the h2 and absolutely position it.
This way, when you're hovering over the popup, you'll be hovering over the h2 as well.
One thing to note here is not to leave any spaces between h2 and the popup, like ReeceJHayward suggested.
<h2>What is CSS?
<div id="popup">
Contact
</div>
</h2>
DEMO:
http://jsfiddle.net/79AfQ/7/

<UL> displaying incorrectly - works fine in all browsers except Firefox 2 (screenshots included)

OK, here's a screenshot of what it's SUPPOSED to look like:
And here's a screenshot of how it looks in Firefox 2 (on both Mac & PC)...
Every other browser gets it right (even IE6?!).
The source code is an Unordered List using Sprites with :hover effects. Here is some code for you:
The HTML:
<div id="votes">
<ul id="voteOptions">
<li id="labour">Labour</li>
<li id="conservative">Conservative</li>
<li id="libdem">Liberal Democrat</li>
</ul>
</div>
The CSS:
#votes {
width:653px;
position:relative;
top:-440px;
margin-left:auto;
margin-right:auto;
}
ul#voteOptions li a{
height: 75px;
float: left;
text-indent: -9999px;
margin-bottom:50px;
}
ul#voteOptions li#labour a{
width: 653px;
background: url('votes.png') no-repeat 0px -2px;
}
ul#voteOptions li#labour a:hover{
background: url('votes.png') no-repeat 0px -77px;
}
ul#voteOptions li#conservative a{
width: 653px;
background: url('votes.png') no-repeat 0px -152px;
}
//...
//(etc. etc - code repeats for conservative and libdem, you get the idea).
So what am I doing wrong? I've tried lots of stuff but can't seem to get this darn thing to work in FF2.
Jack
Is ul#voteOptions li { clear: both; } fixing the issue?

CSS Roll Over with Sprites & Sliding Door

Trying to find an example that has css rollover using sprites & sliding door techniques combined.
I am not css literate, so a complete example or link to a complete example would be appreciated.
All I am trying to do is to have <a href> buttons that are not fixed width with a nice rollover effect and the possibility to add an icon (similar to web outlook).
The following is based on this article (http://www.filamentgroup.com/lab/update_styling_the_button_element_with_css_sliding_doors_now_with_image_spr/), but adapted for use with the a tag.
It is similar to #xijo 's answer, with a couple of minor tweaks.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" >
<html>
<head>
<title>Test</title>
<style type="text/css">
/* REQUIRED BUTTON STYLES: */
a {
border: 0;
padding: 0;
display:inline-block;
}
a span {
display: block;
white-space: nowrap;
cursor: hand;
}
/* OPTIONAL BUTTON STYLES for applying custom look and feel: */
a.submitBtn {
padding: 0 15px 0 0;
margin-right:5px;
font-size:2em;
text-align: center;
background: transparent url(btn_blue_sprite.gif) no-repeat right -140px;
}
a.submitBtn span {
padding: 13px 0 0 15px;
height:37px;
background: transparent url(btn_blue_sprite.gif) no-repeat left top;
color:#fff;
}
a.submitBtn:hover, button.submitBtnHover { /* the redundant class is used to apply the hover state with a script */
background-position: right -210px;
}
a.submitBtn:hover span, button.submitBtnHover span {
background-position: 0 -70px;
}
</style>
</head>
<body>
This is a bunch <span>Submit</span> of text.
</body>
</html>
We did something like this and you perhaps could find it useful. In the anchor we used a span and assigned the following css to them:
html:
<span>echo</span>
css:
a, a:visited {
background: url(left.png) no-repeat scroll left;
}
.tabContainer a span {
background: url(right.png) no-repeat scroll right;
margin: 0 0 0 21px;
padding: 0 21px 0 0;
float: left;
}
and then hover them like this:
.a:hover {
background-position: -45px;
}
.a:hover span {
background-position: -45px;
}
The left and right must look proportionataly of course! :)
Hopes this helps you to solve your css issues! ;)
With just CSS there is not real rollover or sliding effect. Basically both of those techiques are based on "background-position".
Maybe this will help you:
http://kailoon.com/css-sliding-door-using-only-1-image/
But with javascript you could achive so much better looking rollover effect... :) Check out my test page and click on "click to show little bit advanced hover ;)" to see it ;)
www.arvag.net/test/jquery/
If you want something like that just say and i will try to explain it.
Well, depending on exactly what you want this is very variable, but say you want a button that changes colour when the mouse is over it, and has a little image that appears next to it, this is the sort of thing you'd need:
HTML:
<ul>
<li>home<img src="sprite.png" width="16px" height="16px" alt="tinypic" /></li>
....
</ul>
CSS:
ul li img {
display: none;
}
ul li {
background: #FFFFFF;
}
ul li:focus, ul li:hover, ul li:active {
background: #000000;
}
ul li:focus li img, ul li:hover li img, ul li:active ul li img{
display: inline;
margin-right: -16px; // should stop the button expanding
}
But as I said, that's a very basic stripped down answer

Insert image after each list item

What would be the best way to insert a small image after each list element? I tried it with a pseudo class but something is not right...
ul li a:after {
display: block;
width: 3px;
height: 5px;
background: url ('../images/small_triangle.png') transparent no-repeat;
}
Thanks for any help!
The easier way to do it is just:
ul li:after {
content: url('../images/small_triangle.png');
}
Try this:
ul li a:after {
display: block;
content: "";
width: 3px;
height: 5px;
background: transparent url('../images/small_triangle.png') no-repeat;
}
You need the content: ""; declaration to give your generated element content, even if that content is "nothing".
Also, I fixed the syntax/ordering of your background declaration.
For IE8 support, the "content" property cannot be empty.
To get around this I've done the following :
.ul li:after {
content:"icon";
text-indent:-999em;
display:block;
width:32px;
height:32px;
background:url(../img/icons/spritesheet.png) 0 -620px no-repeat;
margin:5% 0 0 45%;
}
Note : This works with image sprites too
I think your problem is that the :after psuedo-element requires the content: property set inside it. You need to tell it to insert something. You could even just have it insert the image directly:
ul li:after {
content: url('../images/small_triangle.png');
}
ul li + li:before
{
content:url(imgs/separator.gif);
}
My solution to do this:
li span.show::after{
content: url("/sites/default/files/new5.gif");
padding-left: 5px;
}

Resources