Display Images Over List Item Menu Links - html

I need a cross-browser solution for having list item menu links with images. I'm using the default ASP.NET MVC 4 template and I have the following generated HTML:
<ul id="menu">
<li>
<a href="/Home/Item01">
<img src='/Images/MenuItem01.gif'/>
Menu Item 01
</a>
</li>
<li>
<a href="/Home/Item02">
<img src='/Images/MenuItem02.gif'/>
Menu Item 02
</a>
</li>
<li>
<a href="/Home/Item03">
<img src='/Images/MenuItem03.gif'/>
Menu Item 03
</a>
</li>
</ul>
The CSS:
ul#menu {
font-size: 1.3em;
font-weight: 600;
margin: 0 0 5px;
padding: 0;
text-align: left;
}
ul#menu li {
display: inline;
list-style: none;
padding-left: 15px;
}
ul#menu li a {
background: none;
color: #999;
text-decoration: none;
}
ul#menu li a:hover {
color: #333;
text-decoration: none;
}
Here's a Fiddle: http://jsfiddle.net/EY3ad/
I'd like to have each image above the text and centralized. I haven't done pure HTML and CSS in years so any help would be appreciated. :)

Are you looking for something like this?
The HTML:
<ul id="menu">
<li> <a href="/Home/Item01">
<img src='http://lorempixel.com/48/48'/>
<span>Menu Item 01</span>
</a>
</li>
<li> <a href="/Home/Item02">
<img src='http://lorempixel.com/48/48'/>
<span>Menu Item 02</span>
</a>
</li>
<li> <a href="/Home/Item03">
<img src='http://lorempixel.com/48/48'/>
<span>Menu Item 03</span>
</a>
</li>
</ul>
The CSS:
ul#menu {
font-size: 1.3em;
font-weight: 600;
margin: 0 0 5px;
padding: 0;
text-align: left;
}
ul#menu li {
display: inline-block;
list-style: none;
padding-left: 15px;
}
ul#menu li a {
background: none;
color: #999;
text-decoration: none;
position:relative;
}
ul#menu li a:hover {
color: #333;
text-decoration: none;
}
ul#menu li a img { display:block; margin:auto; }
ul#menu li a span{position:absolute; top:0; text-align:center;}

Try this:
ul.menu li{
background: url(images/<image-name>.gif) no-repeat;
list-style:none;
padding-left:4%;
margin-top:1%;
}

Related

How can I get my fixed 100% menu to align in the centre?

Everything was going well until I decided that I wanted my fixed navigation menu to be full width. I can't seem to find a way to get the ul to align in the centre, whilst having its parent container as 100%. It was centred until I added the 100% property to its parent
JS Fiddle :https://jsfiddle.net/u504xgey/
nav {
position: fixed;
z-index: 1;
background-color: #ff3300;
width: 100%;
}
nav a {
color: #ffffff;
text-decoration: none;
transition: color 2s;
}
nav a:hover {
color: yellow;
}
ul {
display: block;
margin: auto;
list-style: none;
}
li {
display: inline-block;
color: #ffffff;
margin: 10px 40px;
}
<header>
<nav>
<ul>
<li>
<a href="#landing">
<h3>Home</h3>
</a>
</li>
<li>
<a href="#about">
<h3>About</h3>
</a>
</li>
<li>
<a href="#projects">
<h3>Projects</h3>
</a>
</li>
<li>
<a href="#contact">
<h3>Contact</h3>
</a>
</li>
</ul>
</nav>
</header>
Just set your UL to text-align: center and the padding for your UL to '0'.
JSFiddle
Just add margin: 0 property to your body selector.
body {
background-color: #ffffff;
font-family: "objektiv-mk1", sans-serif;
color: #fffff;
margin: 0;
}
Or centering the UL text :
ul{
margin: auto;
list-style: none;
text-align: center;
}
li{
display: inline-block;
color: #ffffff;
margin: 10px 40px;
}

How do I center list items horizontally?

I have an excerpt of code that I need centered in my header, (just the text and the actual padding). I'm new to coding so if this doesn't sound right don't be surprised. This is the code where I need my list items centered in. Try to make your answer as beginner-like as possible.
CSS:
#navcontainer ul {
list-style-type: none;
margin: 0;
padding: 0;
font-family:'Raleway', sans-serif;
font-size: 23px;
color: #800000;
}
#navcontainer ul li {
display: inline;
}
#navcontainer ul li a {
text-decoration: none;
padding: 0px;
margin: 40px;
}
#navcontainer ul li a:hover {
color: #fff;
background-color: #800000;
}
HTML:
<div id= "navcontainer">
<!-- BEGIN TABS -->
<ul>
<a id="index" class="page-logo" href="/">
<img src="slamlogo.png" alt="Logo">
<li>Jackpot</li>
<li>Profile</li>
<li>Market</li>
<li>Support</li>
</ul>
I know the li elements are messy but I do it so I can see it better. Sorry.
Add a text-align: center to the <ul>:
#navcontainer ul {
text-align: center;
}
Snippet
#navcontainer ul {
list-style-type: none;
margin: 0;
padding: 0;
font-family: 'Raleway', sans-serif;
font-size: 23px;
color: #800000;
text-align: center;
}
#navcontainer ul li {
display: inline;
}
#navcontainer ul li a {
text-decoration: none;
padding: 0px;
margin: 40px;
}
#navcontainer ul li a:hover {
color: #fff;
background-color: #800000;
}
<div id="navcontainer">
<!-- BEGIN TABS -->
<a id="index" class="page-logo" href="/">
<img src="slamlogo.png" alt="Logo">
</a>
<ul>
<li>
Jackpot
</li>
<li>
Profile
</li>
<li>
Market
</li>
<li>
Support
</li>
</ul>
</div>
Also, not a good idea to have anything other than <li> inside the <ul>. You have also omitted a </a>.
There were a few errors in your markup, I've gone ahead and fixed them for you. All that's required to center your list items is text-align: center if you're positioning them as inline elements.
<div id= "navcontainer">
<ul>
<li>
<a id="index" class="page-logo" href="/">
<img src="slamlogo.png" alt="Logo">
</a>
</li>
<li>Jackpot</li>
<li>Profile</li>
<li>Market</li>
<li>Support</li>
</ul>
</div>
#navcontainer ul {
list-style-type: none;
margin: 0;
padding: 0;
font-family:'Raleway', sans-serif;
font-size: 23px;
color: #800000;
text-align: center;
}
#navcontainer ul li {
display: inline;
}
#navcontainer ul li a {
text-decoration: none;
padding: 0px;
margin: 40px;
}
#navcontainer ul li a:hover {
color: #fff;
background-color: #800000;
}
http://jsfiddle.net/ruLns221/
Just to further explain the changes, you should only add li elements to an unordered list (ul) so I've nested your logo within a list item. I've closed some unclosed tags off as well.

Create menu using images using css in html

I'm new in HTML and CSS.
Want to create menu with image and also want to show menu separator, menu should be horizontally aligned.
when we hover mouse on menu item, image and text color should change.
It should be look like as per image.
sry I forgot to upload the code, uploading here.
but now I want to show some menu items on left side( left align) and others on right side( right align)
.mainmenu{
background-color: black;
}
.mainmenu {
margin-top: 20px;
display: inline-block;
position: relative;
width: 100%;
}
.mainmenu li a {
display: block;
position: relative;
text-decoration: none;
text-align: center;
font-size: 10px;
color: gray;
line-height: 32px;
font-weight: bold;
text-shadow: black 0 1px 0;
font-family: sans-serif;
border-right: 1px solid #030304;
border-left: 1px solid #36393C;
white-space: nowrap;
}
.mainmenu ul.menu {
margin: 0;
width: 100%;
}
.mainmenu ul.menu li {
float: left;
list-style: none;
width: 16.666666666666668%;
}
.mainmenu ul.menu li a:hover {
color: #76b900;
}
img {
border: 0;
vertical-align: middle;
max-width: 100%;
}
<div>
<div class="mainmenu ">
<ul class="menu">
<li>
<a href="#">
<img src="images/nav-icons/home.png">HOME</a>
</li>
<li>
<a href="#">
<img src="images/nav-icons/users.png">
USERS
</a>
</li>
<li>
<a href="#">
<img src="images/nav-icons/gallary.png">
GALLARY
<a/>
</li>
<li>
<a href="#">
<img src="images/nav-icons/community.png">
COMMUNITY
</a>
</li>
</ul>
</div>
Thanks
ul.menu {
list-style-type: none;
}
ul.menu li {
padding: 5px;
font-size: 16px;
font-family: "Trebuchet MS", Arial, sans-serif;
}
ul.menu li a {
height: 50px;
line-height: 50px;
display: inline-block;
padding-left: 60px;
/* To sift text off the background-image */
color: #3E789F;
background: url("../images/mySprite.png") no-repeat;
/* As all link share the same background-image */
}
ul.menu li.firefox a {
background-position: 0 0;
}
ul.menu li.chrome a {
background-position: 0 -100px;
}
ul.menu li.ie a {
background-position: 0 -200px;
}
ul.menu li.safari a {
background-position: 0 -300px;
}
ul.menu li.opera a {
background-position: 0 -400px;
}
<ul class="menu">
<li class="firefox">Firefox
</li>
<li class="chrome">Chrome
</li>
<li class="ie">Explorer
</li>
<li class="opera">Opera
</li>
<li class="safari">Safari
</li>
</ul>

CSS dropdown menu errors- can't target a specific element

Trying to make just the services link orange on hover with a gray background- can't do it without changing all the menu items.
I can't click on the examples link after hovering over services.
.menu
{
margin:0;
padding:0;
}
.menu ul {
padding-top: 40px;
padding-left: 0px;
line-height: 0px;
margin-bottom: 0px;
float: right;
}
ul li {
display: inline;
}
ul li a:visited {
text-decoration: none;
}
ul li a:hover, .menu ul li .current{
color: #f7823b;
}
ul li {
display: block;
position: relative;
float: left;
}
li ul { display: none; }
ul li a {
float: left;
font-size: 20px;
display: block;
text-decoration: none;
color: #ffffff;
padding: 20px;
margin-left: 1px;
white-space: nowrap;
}
li:hover ul {
display: block;
}
li:hover li {
float: none;
font-size: 11px;
}
ul ul li:hover a { background: #818285; }
/*li:hover li a:hover { background: #818285; width:100%; }*/
ul ul {
position: absolute;
z-index: 500;
margin:0;
padding-top: 0px;
}
ul ul li a
{
padding: 20px 0px 20px 5px;
width: 100%;
background: #818285;
}
<div class="socialmedia">
<img class="button" src="http://lifeafterclass.com/cyclone/images/header/facebook.png" <="" img="">
<img class="button" src="http://lifeafterclass.com/cyclone/images/header/twitter.png" <="" img="">
<a href="http://www.stumbleupon.com/stumbler/CyclonStrategies">
<img class="button" src="http://lifeafterclass.com/cyclone/images/header/stumbleupon.png" <="" img=""></a>
<a href="http://www.linkedin.com/company/cyclone-strategies-llc">
<img class="button" src="http://lifeafterclass.com/cyclone/images/header/linkedin.png" <="" img=""></a>
</div>
<div class="menu">
<ul id="menu">
<li>Home</li>
<li> About</li>
<li class="special"> Services
<ul>
<li>Digital Advertising</li>
<li>Promotion Management</li>
<li>Social Media</li>
</ul>
</li>
<li>Examples</li>
<li> Blog </li>
<li> Contact Us</li>
</ul>
</div>
<div style="clear:both"></div>
</div>
I've tried everything- any help is appreciated. Thanks!
http://jsfiddle.net/8ARm5/
Since the li containing services has a class special you can use this to target the element upon hover.
.special:hover{
color: orange;
background: grey;
}
Try to add hover on li not a element:
li:hover > a {
color: #f7823b;
}
Doing so the link keeps style definition even if you points links in submenu.
Take a look: http://jsfiddle.net/8ARm5/5/

Google Chome with custom menu doesn't register clicks?

I have a custom menu that is built using standard LI and ULs. It has one level of submenus. When I click on these submenus in Google Chrome, the click event isn't fired. This works in IE, but, does not in Chrome.
This problem cropped up recently, and I'm pretty sure all was good just a little while ago.
Here is the HTML:
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<style type="text/css">
#navMenu {
width: 900px;
position: absolute;
}
#navMenu ul {
padding: 0;
margin: 0 9px;
}
#navMenu li {
margin: 3px 2px 0;
float: left;
list-style-type: none;
}
#navMenu li a {
display: block;
color: #000;
border: 1px solid #000;
background: #E1DFD0 top left repeat-x;
height: 15px;
line-height: 1.154em;
text-decoration: none;
font: normal normal bold 0.985em/normal arial, sans-serif;
float: left;
padding: 0px 6px 3px;
}
#navMenu li a {
float: none;
}
#navMenu li a:hover, #navMenu li a.on{
color: #FFF;
background: #740404 top left repeat-x;
}
/*Sub-Menus*/
#navMenu li ul{
margin: 0 0 0 -2px;
padding: 0;
display: none;
visibility:hidden;
position: absolute;
}
#navMenu li:hover ul{
display:block;
visibility:visible;
width: 10em;
}
#navMenu li li{
display: list-item;
clear: both;
list-style: none;
margin: 0;
}
#navMenu li li a{
text-decoration: none;
width: 150px;
}
#navMenu li li a:hover{
color:#fff;
}
</style>
</head>
<body>
<div class="position:relative; top:0">
<div id="navMenu">
<ul>
<li>
<a href="#" >Menu 1</a>
</li>
<li>
Menu 2
<ul>
<li>
Menu 2.1
</li>
<li>
Menu 2.2
</li>
</ul>
</li>
<li>
Menu 3
<ul>
<li>
Menu 3.1
</li>
<li>
Menu 3.2
</li>
</ul>
</li>
<li>
Menu 4
<ul>
<li>
Menu 4.1
</li>
<li>
Menu 4.2
</li>
</ul>
</li>
</ul>
</div>
</div>
<script type="text/javascript">
$('#navMenu li>a').click(function() {
console.log("clicked a link");
});
</script>
</body>
</html>
There is also a fiddle for it here.
I'm at a loss to explain this, any help would be much appreciated!
Thanks