Difficulty with CSS background divider - html

I have made a basic navigation bar with four 'buttons' and I am using a background image as a divider. The problem I am having is when I create a :hover state, the background covers up the divider. How can I fix this so that the divider image always shows?
Here is the markup:
<div>
<ul class="main">
<li>Home</li>
<li><a class="divl" href="#">Item1</a></li>
<li><a class="divl" href="#">Item2</a></li>
<li><a class="divl" href="#">Item3</a></li>
</ul>
</div>
ul.main {
margin: 0;
padding: 0;
list-style: none;
width: 1000px;
background: url(grad.png) repeat-x;
overflow: hidden;}
ul.main li{
float: left;}
ul.main a {
padding: 0 3em;
line-height: 3em;
text-decoration: none;
display: block;
color: white;}
.divl {
background: url(a.png) repeat-y top left;}
ul.main a:hover,
ul.main a:focus{
background: rgba(0,200,0,0.1);}
Thank you.

You can apply the divider background-image to the li elements instead:
ul.main li {
float: left;
background: url(http://dummyimage.com/1x100/f0f/fff) repeat-y top right;
}
See: http://jsfiddle.net/825cK/

How about you take the divider outside of the background image and place a div inside the list item? Then you can style the divider as you like without the :hover background getting in the way.
Something like:
<li>link here<div class="divider"></div></li>
-or-
Put the divider in the list item as a background.

In my opinion, you have a more fundamental problem with the overall structure of your backgrounds. If the user magnifies the text on their browser, the text will overlap with your borders on your background image no matter what way you spin it.
It's hard because I can't see what the background is supposed to be, but if your background just a vertical linear gradient, you would probably be better off slicing it up and making it as a single background for each List Item instead of the entire Unordered List.
This will allow you the flexibility to fix the problem you initially posted with use of margins, and also make your job much easier if you ever need to add another 'button.'

Related

creating a list of clickable elements

I'm trying to create a bar for social media icons that looks like this
But I'm really stuck.
I tried creating it like this:
<div class="social-media">
<ul>
<li class="facebook">facebook</li>
<li class="instagram">instagram</li>
<li class="twitter">twitter</li>
<li class="youtube">youtube</li>
</ul>
</div>
.social-media ul li {
display: inline-block;
}
.social-media ul li.facebook:after {
content: url('../images/facebooklogo.png');
width: 21px;
height: 21px;
}
And so on for each li.class
But the issue was that the images ignored the width and height I specified here, and were huge. I just couldnt seem to target them
The second thing is, I didnt know how to make them whole thing clickable, when I tried using an "a" tag, it didnt target the image specified by the li:after, only the text inside the li
Am I just going about this the wrong way? is it better to use a bunch of nested divs, and use onclick to make the whole thing a link?
Any help would be great, I'm pretty confused.
I would use
<li><a class="facebook" href="thisIsYourFacebookPage.html">My Facebook page</a></li>
And give the image you want with
a.facebook:before {
background: url("to/the/path/to/my/image");
width: 21px;
height: 21px;
display: inline-block;
content: " ";
}
Like this: http://jsfiddle.net/gVp2P/1/
You can't specific a url for content, as far as I know. But you don't need to use pseudo elements here. Just specific the background-image of each <li>
.social-media ul li{
display:inline-block;
width: 21px;
height: 21px;
}
.social-media ul li.facebook {
background-image: url('../images/facebooklogo.png');
}
If you want them to be clickable links, you really don't even need the ul li. Just use <a> directly, give it a class, facebook, linkedin, etc, then the following CSS.
.social-media a {
display:inline-block;
width: 21px;
height: 21px;
}
.social-media a.facebook {
background-image: url('../images/facebooklogo.png');
}
You should also consider the icons as font's instead of images.
The reason is they scale better, lookin really nice even if your users zoom or use retina displays, and you can just add css colors, shadows and so on just as you would do styling your text.
read on here:
http://icomoon.io/

Cleanest and easiest way to have a rounded rectangle show up behind a navigation link on hover?

Best way to understand what I want is to watch this short six second video. Please ignore the font change in the video. http://www.youtube.com/watch?v=7KM78DKoVZU
What's the best way to go about making that rounded rectangle to show up behind the navigation link on hover? On hover, I could have the navigation button's background change to a background image with a rounded rectangle in the image, but before I go about that, I want to ensure there's no cleaner or easier way to go about this.
Thoughts? Thanks!
The rectangle isn't really showing up behind the nav link. What's really happening is the nav link's style is changing during the hover state.
#menu {
list-style: none;
display: inline-block;
background: #eee;
margin: 0;
padding: 0;
}
#menu li {
float: left;
padding: 10px 5px;
margin: 4px;
color: #222;
cursor: pointer;
}
#menu li:hover {
background: #ccc;
border-radius:6px;
}
Check out the jsFiddle for a live example.
http://jsfiddle.net/kGa67/
EDIT- I suppose the cleanest way is style both the ul and li as inline-block instead of floating the the li like I did. Use ems if you have a responsive design but beware that it doesn't always scale perfectly on very small and very large widths.
Check out this fiddle: http://jsfiddle.net/8PqkH/
It's easy to do.
nav a:hover{
background: #902;
color: #fff;
border-radius: .5em;
}

Creating menu in html and css

I want to create menu like this:
I want to see red square on acitve page and after hover. Menu is created by:
<div id="menu">
<ul>
<li><a href="#"><span>Home</span><a></li>
<li><a href="#"><span>About</span><a></li>
<li><a href="#"><span>Contact</span><a></li>
</ul>
</div>
I am trying to create this for 2 hours and nothing:( Can you give me an advice?
Here is a working jsfiddle for you:
http://jsfiddle.net/6sCZh/
li { list-style: none; float: left; background: url(http://getpersonas.cdn.mozilla.net/static/9/0/66090/preview_small.jpg) repeat-x; background-position: 0px 10px; }
ul { }
li a { display: block; color: #fff; text-decoration: none; margin: 14px; }
li a.active, li a:hover { background-color: brown; padding: 11px; margin: 3px; }
I've added a css class "active", which should be set server-sided with your php code or by setting it static in the html markup. Unfortunately I don't know a better way. Also a "clear"-tag would be nice because of the float :)
But maybe it helps a bit ;-)
The easy way to do this is to give your anchor tags (or, better, their parent li elements) a class when they are selected.
Then create a rule that targets li.selected and li:hover which places the red box.
I cannot be more specific without seeing your HTML AND CSS.
For the gradient you'll need CSS3 or image. I used gradient generator for the demo - http://www.colorzilla.com/gradient-editor/
The idea is the active link to be higher that the menu and with negative top and bottom margins which compensate for the height difference. And don't put overflow: hidden to the menu :)
http://jsfiddle.net/23zZE/

How do I fix my CSS menu with rounded image background

I want to show the rounded image on the left and right menu. You can see the example here. The background image is:
<ul>
<li><a class="current" href="">Home</a></li>
<li>Faq</li>
<li>About</li>
</ul>
Let me know the trick on CSS to achieve my goal without cutting the current image.
The result should be like this
Here is the final result using sliding doors technique
You should use border-radius:5px and background: linear-gradient(startcolor, endcolor);
For IE support use the CSS3PIE
example at http://jsfiddle.net/gaby/9DENH/4/
Use sliding doors technique.
And your main problem is that <li>s are floated so <ul> has 0 height. You can either float ul also, or give it overflow:hidden
http://jsfiddle.net/9DENH/3/
================================
UPDATE:
sorry speed read will kill me one day :)
Here is my updated answer: http://jsfiddle.net/9DENH/5/
Add this to css:
li {
padding-left: 10px;/* to create gap that will not be overlapped with <a> background */
background:url(http://i.stack.imgur.com/yLgZA.png) no-repeat left top #000;
}
li a, li a.current {
background:url(http://i.stack.imgur.com/yLgZA.png) no-repeat right top #000;
text-indent: -10px; /* same as li padding, to realign centered text */
}
This is basic you should add hover states.
You can use the CSS rounded corners and it works just fine w/ the background image you have there (although you don't need the image's corners to be rounded and the image doesn't have to be so wide - 10px wide is just find since it repeats-x.
li a:link, li a:visited {
background-image: url('../images/navBg.jpg');
background-repeat: repeat-x;
background-position: top left;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
-khtml-border-radius: 5px;
}
li a:hover, li a:active{
background-position: bottom left;
}
Do you try to use the images as a sprite?
If so you have to choose diffrent positions on the background,
and you also will have to define a height and width for each element.

How to include a separator image on a menu built with ul and li?

I am trying to include a small image as a separator in my menu and I am having the time of my life (sarcasm). In order to create a menu like below I am using the code under the image.
<ul id="div-menu">
<li class="current">
<div class="menu-fill fill">
<div class="menu-left left">
<div class="menu-right right">
Home
</div></div></div>
</li>
<li>
<div class="menu-fill">
<div class="menu-left">
<div class="menu-right">
About Us
</div></div></div>
</li>
My problem is that I am not able to add the little separator image between the li elements. Any ideas?
list-style plays up on different browsers. the best way to do it is
ul#div-menu li { background: url(/images/seperator.gif) no repeat 0 0; }
the first-child pseudo-class doesn't work on all browsers, so you can apply a 'first' class to the first li and set background to none for that
ul#div-menu .first { background: none; }
note: you will need to use some amount of padding on the li to push the text away from the background image. you can adjust the position of the background image using the last two parameters (which i've set to 0). the first digit is x-axis and the second one is y-axis. so to move the background image 2px to the right and 2px up
ul#div-menu li { background: url(/images/seperator.gif) no repeat 2px -2px; }
Maybe you could set the separator image as the list image:
ul#div-menu li
{
list-style-image: url("/images/separator.gif");
}
ul#div-menu li:first-child /* Disable for the first li */
{
list-style: none;
}