issue with border in hover effect on navigation menu

I'm looking to replicate a menu design similar to the one shown in this image.

My main issue lies with the hover effect, specifically changing the vertical images on both sides. I've made some progress so far and you can view it here: http://jsfiddle.net/cgEab/

Any suggestions on how I can achieve changing both left and right images on hover?

Here is the CSS code:

#topmenu{
    float: right;
    position: relative;    
}
ul#topnav {
    right: 0px;
    margin: 0;
    padding: 0; 
    list-style: none;   
    font-size: 1em;    
    background-color: #ccc;
}
ul#topnav li {
    float: left;
    margin: 0; padding: 0;
}
ul#topnav li a {
    padding: 10px 22px;
    display: block;
    color: #777777;
    text-decoration: none;
    background-image: url('http://s11.postimg.org/az4oag1in/menu_bar_vertical.jpg');
    background-position: right;
    background-repeat: no-repeat;
    display: block; 
}
ul#topnav li a.lastitem {
    background-image:none;    
}
ul#topnav li a:hover {
    color: red;
    background-image: url('http://s11.postimg.org/xch0azru7/menu_bar_vertical_hover.jpg');    
}

And here is the HTML:

<link href='http://fonts.googleapis.com/css?family=Dosis:400,700' rel='stylesheet' type='text/css'>
<div id="topmenu">
<ul id="topnav">
    <li><a href="#">HOME</a></li>
    <li><a href="#">SERVICES</a></li>
    <li><a href="#">CUSTOMERS</a></li>
    <li><a href="#">ABOUT US</a></li>
    <li><a class="lastitem" href="#">CONTACT</a></li>
</ul>

Answer №1

I made adjustments to the border image by changing it to a double on both sides and also corrected the margin for positioning purposes.

http://jsfiddle.net/Q3pQx/

ul#topnav li a {
    margin-left:-2px; <-- FIX
    padding: 10px 22px;
    display: block;
    color: #777777;
    text-decoration: none;
    background-image: url('http://s11.postimg.org/az4oag1in/menu_bar_vertical.jpg');
    background-position: right;
    background-repeat: no-repeat;
    display: block; /* make the link background clickable */
}

ul#topnav li a:hover {
    color: red;
    background: url('http://s11.postimg.org/xch0azru7/menu_bar_vertical_hover.jpg'), url('http://s11.postimg.org/xch0azru7/menu_bar_vertical_hover.jpg'); <-- FIX
    background-position: left top, right top; <-- FIX
    background-repeat: no-repeat, no-repeat; <-- FIX
}

I refined the fiddle with some minor adjustments http://jsfiddle.net/LhFkf/

Answer №2

When using 'background-image' property, you can actually specify multiple images at once. Here's an example:

background-image: url(...), url(...);

background-position: left, right;

Answer №3

Would it be a good idea for me to give this a shot?

http://jsfiddle.net/cgEab/7/

CSS

 #topmenu{
    float: right;
    position: relative;    
}
ul#topnav {
   /* position: absolute;*/    
    right: 0px;
    margin: 0;
    padding: 0; 
    /*width: 640px;*/
    list-style: none;   
    font-size: 1em;    
    background-color: #ccc;

}
ul#topnav li {
    float: left;
    margin: 0; padding: 0;
    /*border-right: 1px solid #555;*/
}
ul#topnav li a {
    padding: 10px 22px;
    display: block;
    margin-left:-2px;
    color: #777777;
    text-decoration: none;
    background-image: url('http://s11.postimg.org/az4oag1in/menu_bar_vertical.jpg');
    background-position: right;
    background-repeat: no-repeat;
    display: block; /* make the link background clickable */
}
ul#topnav li a.lastitem {
    background-image:none;    
}
ul#topnav li a:hover {
    color: red;


    background: url('http://s11.postimg.org/xch0azru7/menu_bar_vertical_hover.jpg'), url('http://s11.postimg.org/xch0azru7/menu_bar_vertical_hover.jpg');
background-position: left top, right top;
background-repeat: no-repeat, no-repeat;


    }

Answer №4

I have made some adjustments to the image placement within the li, previously it was within the li a.
This tweak utilizes a css3 hack. Ideally, this solution is optimized for browsers IE 8 and above.

#topmenu{
    float: right;
    position: relative;    
}
ul#topnav {
   /* position: absolute;*/    
    right: 0px;
    margin: 0;
    padding: 0; 
    /*width: 640px;*/
    list-style: none;   
    font-size: 1em;    
    background-color: #ccc;

}
ul#topnav li {
    float: left;
    margin: 0; padding: 0;
    background-image: url('http://s11.postimg.org/az4oag1in/menu_bar_vertical.jpg');
    background-position: left;
    background-repeat: no-repeat;  
}

ul#topnav li:hover,
ul#topnav li:hover + li {
    background-image: url('http://s11.postimg.org/xch0azru7/menu_bar_vertical_hover.jpg')
    /*border-right: 1px solid #555;*/
}
ul#topnav li a {
    padding: 10px 22px;
    display: block;
    color: #777777;
    text-decoration: none;
    /*background-image: url('http://s11.postimg.org/az4oag1in/menu_bar_vertical.jpg');
    background-position: left;
    background-repeat: no-repeat;*/
    display: block; /* make the link background clickable */
}
ul#topnav li:first-child {
    background-image:none;    
}
ul#topnav li a:hover{
    color: red;
}

Fiddle

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can a Vue component be created with a template that solely consists of a property's text?

Looking for a way to incorporate plain text within a Vue component template area? The current method involves wrapping the text in a div, but this causes layout issues when concatenating components with other text fragments. This results in awkward spacing ...

Embedded video player is failing to display and play the video file

Currently, I am in the process of developing a PHP backend for my mobile application. One specific requirement involves displaying and playing a video file that is hosted. This is the approach I have taken: $data[$i]['video'] = '<vide ...

What is the approach to initiating a jquery function once HTML content is dynamically added through an AJAX call?

<div id="timeline"> <ul class="grow" id="grown"><li>One</li><li>Two</li><li>Three</li><li>Four</li><li>Five</li><li>Six</li><li>Seven</li><li>Eight< ...

JavaScript validation for basic "select" isn't functioning as expected

I need assistance with my simple "select" validation using JavaScript. The issue I am facing is that when validating the "select" element, it does not display the select options to users after a validation error occurs. "The select option is not re-enabl ...

"Rearrange elements on a webpage using CSS and HTML to position one

Can we utilize CSS/HTML to visually move a full width element that is positioned below another one so that it appears above without altering the markup order? <div id="first">first</div> <div id="second">second</div> #first {…} ...

The ng-change event fails to trigger when the date change event is activated

Hey there, I'm new to working with AngularJS. I have a scenario where I want a method to be triggered when I change the date, opening a modal. However, when I use the ng-change event, the method is not called upon date change. If I switch to using ng- ...

Why is the query outputting a variable with additional values attached to it?

$currentFile = $_SERVER["SCRIPT_NAME"]; $img = array_pop(explode("/", $currentFile)); $fileName = basename($img, ".php").PHP_EOL; echo $fileName; Echo'd results: placementName $query = "SELECT * FROM image_Name WHERE name = '" . mysql_real_ ...

What is the method for absolutely positioning an element with separate targets for the `left` and `right` properties?

Seeking a complex CSS result that may seem impossible. Consider the following scenario: <div class="div1"> <div class="div2"> <div class="div3"> <div class="div4"></div> ...

updating dropdown options based on user input with PHP

I need help with implementing a code for two dropdown boxes. The first dropdown should display main category values dynamically, and when a value is selected, the second dropdown should appear with corresponding sub-category values. How can I achieve this ...

The navigation menu dissolves into hiding at the uppermost part of the page upon scrolling upwards on iOS devices

I am currently working on creating a navigation menu that will automatically hide when scrolling down and reappear when scrolling up. This functionality works perfectly fine on desktop and Android browsers, but I have encountered an issue specifically with ...

The process of redirecting a web page using htaccess and incorporating URL parameters

I have a directory where I store HTML pages. Using the PHP include function, I am adding these pages to my index.php file by referencing them with a URL parameter value. The URL parameter "xpage" corresponds to the page names stored in another folder, whil ...

How come my dimensions are not returning correctly when I use offset().top and scrollTop() inside a scrolling element?

Currently in the process of developing a web app at , I am looking to implement a feature that will fade elements in and out as they enter and leave the visible part of a scrolling parent element. Taking inspiration from myfunkyside's response on this ...

Steps for creating a basic JQuery function for dividing integers

My website constantly updates with real-time data from our PI server, refreshing every 10 seconds. I've been given the task to take two existing data points already on my page and calculate their division, then visualize the new result on a graph. Due ...

Unable to download the jQuery Plugin

I am looking to install a gallery without using flash, and I came across this jQuery plugin called Grid-A-Licious. However, I am having trouble figuring out how to install and use it since it is distributed as a .zip archive with two .js files but no index ...

Animating ng-switch transitions within a div element

Utilizing bootstrap 3 panel along with ng-switch for a sliding animation: Check out the Plunker here I am facing an issue where the animation extends past the borders of the panel instead of staying within it. How can I fix this in my Plunker? The desire ...

Why does the content not appear again when switching between tabs?

Hello! I'm facing an issue with toggling between two sets of content on my page. Initially, the correct content shows up, but when I switch tabs, the new content doesn't appear. Furthermore, if I click back to the first tab, that content disappea ...

Show a table with rows that display an array from a JSON object using JavaScript

My current code includes JSON data that I need to display in table rows, but I'm struggling to understand how to do so effectively. The output I am currently seeing is all the rows from the array stacked in one row instead of five separate rows as in ...

Website loses its css after printing

I'm having trouble printing a website with a simple layout featuring two columns, each containing tables. The website I want to print is located at the following link: . However, when I try to print it using the JavaScript function window.print(), the ...

Adjust the transparency of a navigation bar independently from the transparency of the text within the navigation bar

Seeking assistance on adjusting the opacity of this navbar without affecting the text within it. Any tips on changing the text color as well? <nav class="navbar navbar-expand-lg navbar-light bg-light"> <a class="navbar-brand" href="#" ...

Choosing more than one item to submit may pose an issue - the POST request will be empty

One of the challenges I'm facing is with a multiple select feature like the one below: This allows for selecting various options, such as 3 sports in this case. Successful form submission occurs when items are selected correctly. However, if no spor ...