enter image description here
Hello im very new to this. I have created a webpage with links running horizontally across the page. When i hover over each title it has a background colour. However the hover size is a fixed size. I want to know how i can get the hover to automatically adjust depending on link length.
/* change the link color to #272727 on hover */
li a:hover
{
background-color:#272727;
max-width:200px;
}
thanks for any help
It looks to me that the "max-width: 200px;" CSS property isn't required. So try:
li a:hover
{
background-color:#272727;
}
Without specifying an explicit max width, your link elements will size to the width of their parent li. So when you set the background colour on hover, the entire word will be highlighted, without any overflow.
But if you could provide a fiddle to confirm, that'd be really helpful!
If m not wrong then i think i got your solution. You are asking that how can you give background color on hover without changing the size or might be you are facing issue with size of li while hovering so please see this fiddle
I have used padding for normal a tag and remove fix width from hover. So now m just changing the background color and it will applied automatically on text/link. Please let me know if you are facing any issue. Thank you
HTML
<div>
<ul>
<li>Home</li>
<li>About</li>
<li>RESCUES</li>
<li>Help</li>
<li>VEHICLES</li>
<li>VOLUNTEERS</li>
<div style="clear:both;"></div>
</ul>
</div>
CSS
div{background-color:teal;width:100%;}
li a:hover{background-color:#272727; color:#fff;}
li a{ padding:6px;}
ul li{list-style-type:none;float:left;padding:6px;}
li a {text-decoration:none;}
Related
I have a CSS problem I need help solving.
I have an ul for showing a column. I've hardcoded the width of this ul to 220px. Inside it, I have li's. Each li has a text link.
Problem is, because I have hardcoded the ul width to 220px, the li are inheriting this, even though they don't need so much width. If I see the space each li text is taking, this is what I see:
How can I make each li text ONLY take as much space as it needs for the text itself ?
I want to do this because I have a picture in the background which has a map on it .. The extra space taken by li's means that the map isn't working in areas where it should work (because li's are on top of the map) ..
Use display:inline-block; Or display:inline;.
Or:
Use float:left; on each li then have a clear:both; element after each li.
You can use display:inline-block;
add float:left to your <li>s.
& put a <div style="clear:both;"></div> after each.
so I am running WordPress, with a premium theme.
I wish to change the navigation bar size, and so I added
li
{
float:left;
}
a
{
display:block;
width:60px;
}
When I add this, the navigation bar changes size, and becomes as I want to. HOWEVER, also the posttitles changes layout, and becomes really ugly.
I am looking for some input
If you're targeting li elements globally, it may be affecting more than just the nav area. Try adding more specificity to your rule.
i.e. ".nav li" (.nav being whatever the class or id of your nav is) instead of just "li"
sounds like float is affecting other elements. Using clear:both should fix this.
<ul>
<li>....</li>
</ul>
<div class="clearfix"></div>
and .css
.clearfix{
clear:both;
}
Sorry if this is a really stupid question, but I'm a developer and my design skills are minimal at the minute, I'm working on a personal site and I'm stuck with a minor issue.
I have a top nav with a ul and li items. These items contain link <a href... and within these tags I have a <span>.
The span only displays when the link is hover over.
CSS
div#topnav a span {display: none;}
div#topnav a:visited span {display:none;}
div#topnav a:hover span {display: block;}
The problem is, the span has quite a bit of text in, and when it displays it makes the link width large, thus pushing the rest of the top nav to the right.
Is there something I can do to tell the a tag to ignore the spans width and not change when the span is displayed but not affect the width being automatically set by the links text (non span)?
HTML
<div id="topnav">
<ul>
<li>Example<span>this is a link to google</span></li>
<li>Another EG<span>this is another link that goes to bbc!</span></li>
</ul>
</div>
It's worth noting, this text in the span appears below the nav, so I need it all to be displayed.
well, if you want you can simply remove the span out of the flow and they will stop affecting the links in any way by just giving an absolute position to the span and a relative position to the a. You also don't need the :visited I think, since I'm guessing that it will prevent the link from showing up if already visited. Like this:
div#topnav a {position:relative;}
div#topnav a span {display: none;}
div#topnav a:visited span {color:purple;}
div#topnav a:hover span {display: block;postion:absolute;bottom:-50px;}
You can change the bottom value to fit your needs, or add left/right properties to position them further. You may consider adding a width to the span as well. position:relative on the a is required so that the span will know from where to go 50 px downwards.
Edit: added the visited class, since it may help the ux to a degree by just changing the text color.
Simply set a width on the span/link so that it won't automatically determine it by the length of the content.
div#topnav a span { width: 50px; }
Note: 50px is an example, you can set it to whatever you want.
Try using div tag outside "a" tag which has fixed width so that your content doesnt go across the specified width.
i have a ul style menu looking like this:
<ul>
<li>
<span>Hem</span>
</li>
etc.. etc..
</ul>
the li element has an image as background that changes on hover. i do not want to display the text inside the container and therefore it has visibility: hidden.
Fun thing now; you are still able to click the link in IE and FF but in safari only the mouseover works, but you can't click the link. Changing the visibility of the span container does make it possible to click the link.
Question now is how to change the css code so that it behaves like IE and FF?
I don't want to show the text, but i do want to be able to click the menu - duh!
Rather than setting the visibility of the anchor to hidden consider the following:
ul li a
{
display:block;
width:100%;
height:100%;
text-indent: -9999px; // Hide the text
}
Working Example
I have this problem with CSS round corners. The link to example is here: http://www.xplus.dnawrot.nazwa.pl/
As you can see at the top on the dark blue background is a dropdown menu. The problem concern hover state on the first ul li list(items: oferta, klienci, akademia) wchih has children. As you will notice if you make mouse focus on the oferta item it display round corners properly, but if you go down to second ul li list (drop down - "rozwiazania branzowe", "produkty", etc) right side of round corner disapperas. And it's logical becouse there is CSS style for li element and a element, and if the mouse leaves an a element the hover is removed. Does anyone has a solution for this problem?
If the description is not clear let me know and I'll try to explain more detailed.
Regards,
Dave
Maybe you could try to wrap "a" and "ul" in a "span" tag and then use css to control span:hover instead of a:hover.
<li class="">
<span>
<a class="sf-with-ul" title="Klienci" href="http://www.xplus.dnawrot.nazwa.pl/pl/klienci">
<ul style="display: none; visibility: hidden;">
</span>
</li>
I haven't tested it but you could give it a try.