Trapezium navigation menu mouse interaction - css

I have designed a navigation menu which uses trapeziums instead of rectangles. I have got something working but it doesn't behave properly. I have tried using a negative left margin of -15px to offset the link but this doesn't appear to work.
The following illustration demonstrates what I have working along with that desired. Given the same cursor position "Brokerage" should be highlighted instead of "Services" (with hover or click).
How can I fix this? Is there a better way to achieve this (baring in mind that I want compatibility with IE7+)
Here is the HTML structure of the navigation menu:
<nav>
<ul>
<li>Contact</li>
<li>Brokerage</li>
<li>Services</li>
<li class="first current">Home</li>
</ul>
</nav>
Here is the CSS:
nav ul li {
display: block;
float: right;
margin-left: -30px;
line-height: 69px;
text-align: center;
font-size: 16pt;
background: url(img/nav.png) no-repeat right -69px;
}
nav ul li:hover {
background: url(img/nav.png) no-repeat right -207px;
}
nav ul li.current {
background: url(img/nav.png) no-repeat right 0px;
}
nav ul li.current:hover {
background: url(img/nav.png) no-repeat right -138px;
}
nav ul li.first a {
background: url(img/nav.png) no-repeat left bottom;
}
nav ul li a {
display: block;
float: left;
padding: 0 26pt;
text-decoration: none !important;
color: #4e649f;
}
nav ul li:hover a {
color: #9e4e4e !important;
}
nav ul li.current a {
color: #fff !important;
}
Here is the img/nav.png image, please note that bottom strip of image contains a white triangle that is used to cover start of first navigation item.
^-----^ White triangle here - remainder is transparent (PNG-24)

I think that there are at least three solutions of which two use javascript:
Imagemap + hover event
You could use a transparent imagemap that lies over the navigation and use the href attribute on the area tags. The areas could be trapezoids like your navigation items.
RaphaelJS
You could use RaphaelJS to draw shapes over the navigation and bind to mouseover/click events.
Plain Javascript
You could just calculate the position of the cursor and trigger the appropriate link with plain javascript.

Related

How do I vertically align my list items with the bullets?

So I have an unordered list with custom bullet images. They are triangles pointing to the right at the list. I would like the point to be aligned with the vertical center of the first line of text in the list item. How can I achieve this?
This is what I am currently viewing:
<ul>
<li>Photography for events and portraits</li>
<li>Image editing and restoration</li>
<li>Video and audio production</li>
</ul>
main ul {
list-style-image: url(../img/bullet.png);
margin-top: 25px;
}
main ul li {
line-height: 35px;
}
The line-height doesn't seem to do anything.
you can use pseudo-element before \ after instead, take a look at this example below:
main ul {
margin-top: 25px;
}
main ul li {
list-style: none;
}
main ul li:before {
content: url("http://www.milksmarter.co.nz/images/basement_platform/grey_triangle_bullet_point_large.png");
position: relative;
top: 10px;
left: -10px
}
<main>
<ul>
<li>Photography for events and portraits</li>
<li>Image editing and restoration</li>
<li>Video and audio production</li>
</ul>
</main>
It's really hard to actually provide you with finalized code without access to your image, but try merging the following code with your own. The first Padding value (currently 3px) should be the item you need to update.
li {
background: url(images/bullet.gif) no-repeat left top;
padding: 3px 0px 3px 10px;
/* reset styles (optional): */
list-style: none;
margin: 0;
}
src: Adjust list style image position?

Breaking links text to bottom when using a sprite image background

This is my navigation:
<ul>
<li class="home">Home</li>
<li class="projects">Projects</li>
<li class="about">About</li>
</ul>
I use a sprite image that has simple and hover shapes for each link.
ul li a {
background-repeat: no-repeat;
background-image: url(../images/sprite.png);
display: inline-block;
outline: none;
text-decoration: none;
width: 51px;
height: 51px;
color: #a5a4a4;
}
ul li.home a {
background-position: 0px 0px;
}
ul li.home a:hover {
background-position: 0px -51px;
}
I want to break links text to bottom of each 51x51 pixel squares. Maybe it requires to increase the height of a tags, But the another part of sprite image should not be show.
Thanks
set padding-top: 51px; and place the background there. If other parts of the sprite is showing then you should make the images more separated.

Complex css menu

I have a menu:
<div class="headerMenu">
<ul>
<li>Home <span>Home Page<span></li>
<li>About <span>About My Website<span></li>
<li>Contact <span>Get in touch<span></a></li>
</ul>
</div>
My current CSS is as follow:
.headerMenu{
width: 100%;
}
.headerMenu ul{
margin: 0;
padding: 0;
float: left;
}
.headerMenu ul li{
display: inline;
}
.headerMenu ul li a{
float: left;
color: white;
padding-top:25px;
padding-left:50px;
font-size:24pt;
}
.headerMenu ul li a:visited{
color: white;
}
.headerMenu ul li a:hover, .menu ul li .current{
color: #fff;
background: url(../../Content/Images/menu-selector.png) repeat-x; /* 25x10 arrow/*
}
And now for the question:
How can i get the content in the span tag to be below the Main text.
When i hover over the anchor, How do i add the hover image as shown in screen shot
The Mockup i created in Photoshop looks like this:
I know this would be easily achievable by making use of images, but my solution requires that menu to be created dynamically.
1) How can i get the content in the span tag to be below the Main text.
You need to use display: block on the span to have it appear on a new line:
.headerMenu ul li a span {
display: block;
}
2) When i hover over the anchor, How do i add the hover image as shown in screen shot
Try to center the arrow to the top. This might work:
.headerMenu ul li a:hover, .menu ul li .current {
color: #fff;
background: url(../../Content/Images/menu-selector.png) no-repeat center top;
display:block;
/* also make sure that you use display block with correct height
so that you can positionate the arrow on the correct place... */
}
Add the following code for problem 1:
.headerMenu ul li a span {
display: block;
}
This sets the <span> to display as a block level element, therefore occupying the full parent container width by default.
For problem 2, there are multiple ways to do this. However, my suggestion would be to add the array to the <li> and use the :hover pseudo class. Note: that this will only work in IE for 7+.
.menu ul li:hover{
background: url(../../Content/Images/menu-selector.png) repeat-x;
}
See it in action - http://jsfiddle.net/kxqx8/1/ (I changed the colors to help display)

Buttons clickable area

What css styles to be applied to make the clickable area of button to the exact shape of the button.Could you please tell me
If you use HTML you have to use a somewhat obsolete technique - Image maps - to get a clickable area that's not in the shape of a square. If you use Flash, you have more options. This reply addresses HTML/XHTML up to version 4, I haven't read the the specs for HTML 5 wich may have more ways of solving this (probably in combination with Javascript).
If I wish to style links in a menu I use an unordered list. You need to use display:block to make the whole list item click-able. I have included example css and html below.
In my stylesheet:
#menu {
width: 800px;
height: 40px;
}
#menu ul {
list-style-type: none;
margin:0;
padding:0;
}
#menu li {
display: inline;
margin-right: 10px;
float: left;
background-color: #FC0;
}
#menu a {
text-decoration: none;
font-size: 1.2em;
color: #006;
display:block;
padding: 5px 10px 5px 10px;
}
#menu a:hover,
#menu a:active {
color: #009;
background-color: #F90;
}
In my html:
<div id="menu">
<ul>
<li>Home</li>
<li>Blog</li>
<li>Articles</li>
</ul>
</div>
This will give you a horizontal menu of three yellow boxes/buttons which will change to orange on hover. The a is displayed as a block and so the hover affect takes affect when the mouse hovers anywhere within the yellow box, rather than just over the text.
Hope this helps :o)

anchor link nested in a li

I'm creating a horizontal menu in my website and everything is OK but one thing. I have a link in each <li> and the color is set to white and li has no background, but in hover I want to set li background to white and links text color to black. The problem is that the width of <a> tags is not the same as <li> and when the mouse is over the part that is in <li> but not in <a> both become white.Anchor links can not have width property as far as I know, and I try different type of tricks but no success.Any idea?
#primary-menu ul li {
list-style-type: none;
float: left;
background-image: url('menu-sep.png');
background-repeat: no-repeat;
background-position: right;
}
#primary-menu li a:hover {
color: black;
}
#primary-menu li:hover {
background-color: white;
color: black;
}
#primary-menu li a {
color: white;
text-decoration: none;
padding-right: 8px;
margin-right: 8px;
width: 100%;
height: 23px;
}
`
Check your <li> styling. They probably have padding. Remove it and the anchors should occupy the entire available space. Also, change the margin on the <a> tag to padding. Padding counts as part of the tag (ie, hovering over the padding makes it trigger the :hover pseudoselector), while margins do not.
as you have written above that should be worked but you are saying that is not working then try by making class refered to only text like.
.liText
{
color:white;
}
.liText:hover
{
color:black;
}
hope this will work.
use class attribute with your tag.
like
<a class="liText"> // for single class
if you want to use two or more classes for one tag then use another class after giving space as i mentioned below.
<a class="firstClass SecClass ThirdClass">

Resources