Switching Images with Rounded Border on Hover Effect

After carefully crafting a rounded box/button and slicing its first corner, the middle bar (which repeats horizontally to adjust the width of the button text/content), and the last corner, I utilized the following markup:

<div id="left-corner"></div>
<div id="middle-bar">About Us</div>
<div id="right-corner"></div>

Each of these divs corresponds to images in the CSS and is floated to the left. Together, they form a seamless rounded button with the text "About Us," which looks great.

However, a new obstacle has arisen:

While I managed to create three slices of hover images, I am unsure how to implement the hover effect on these buttons without causing the corner images to also trigger the hover effect. One possible solution is to use fixed-width buttons and slice them entirely, but I prefer to avoid that route.

Answer №1

Is it possible for you to group those three divs within a larger div? Here's an example:

<div id="button_wrapper">
    <div id="left-corner"></div>
    <div id="middle-bar">About Us</div>
    <div id="right-corner"></div>
</div>

You can then add hover effects to the enclosing div like so:

#button_wrapper:hover #left-corner {}
#button_wrapper:hover #middle-bar {}
#button_wrapper:hover #right-corner {}

Alternatively, have you thought about using border-radius? While it may not work on Internet Explorer, it is easy to implement and degrades gracefully. You can learn more about it here:

-webkit-border-radius: 1px;
-moz-border-radius: 1px;
border-radius: 1px;

Answer №2

Enclose it within an <a> tag (consider using spans for semantic HTML).

<a href="#" class="button">
   <div id="left-corner"></div>
   <div id="middle-bar">About Us</div>
   <div id="right-corner"></div>
</a>

CSS:

.button:hover #left-corner { /* add your styles here */ }
.button:hover #middle-bar { /* add your styles here */ }
.button:hover #right-corner { /* add your styles here */ }

Edit:

Due to limitations with the :hover pseudo selector in IE6, we need to utilize an <a> element.

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

Steps for updating a text section beneath a carousel

I'm looking to enhance my webpage with a bootstrap carousel, which is pretty standard. However, I want the content under each slide to change dynamically, but I'm struggling to make it work. As a newbie, I could use some guidance. I've atte ...

Entering text into a field / Inserting data into a MySQL database / Presenting

I am facing a challenge that I'm uncertain how to resolve. The issue lies with a textarea on my form that permits the user to input data in the following format: Windows XP Home and Professional<br />(32 and 64 bit) Windows 7 Home and Professi ...

PHP POST data not displaying in output

Having an issue with displaying the chosen value from a database enum in a text field on my website. The enum table has options like Bachelor of Science, Master of Science, Bachelor of Education, and Master of Education. I want to show the selected option ...

Hiding scrollbars in a component: The ultimate guide

I am seeking a way to completely hide scrollbars from an HTML component using CSS styles within a VueJS component. I have tried the solution of using overflow-y: hidden; within the component as well as within a specific subclass in the CSS, but neither com ...

unitary incline division assemblage

I noticed a particular element in the design that is currently displayed with an image (png). However, I am facing limitations due to needing to make it adaptive. Can a gradient be used as a sub-element instead? background-image: linear-gradient(to left, ...

Using the mpdf addPage function generates new empty pages

Hey there, I'm facing an issue where using $mpdf->addPage() within a for loop results in creating blank pages instead of adding content. My goal is to generate a new page when a certain condition is met and then populate it with the required conten ...

Separation between inline elements with a line break

I am faced with the challenge of placing the a tag on a new line while maintaining center alignment, without being able to modify the HTML. The display:block option extends the clickable area beyond the text. See the screenshot below for the desired outco ...

Revamped Web Presentation: The Dynamic Blend

I'm struggling to arrange a section in the same way as shown in this image. https://i.stack.imgur.com/QVDHn.png I have been using bootstrap 4 and have experimented with rows and columns, but haven't been able to achieve the desired layout. Curr ...

What is the best way to ensure the width of the div is adjusted to fit the table it contains?

What is the best way to adjust the width of a div containing a potentially wider-than-screen table? Despite setting padding: 10px for the div, the right padding disappears when the table exceeds the screen width. Below is an example code snippet: <div ...

Ways to extend the length/size of the HTML5 range input type

Is there a way to adjust the length or size of the HTML5 range input for it to appear longer or bigger? <!DOCTYPE html> <html> <body> <form action="/" method="get"> Points: <input type="range" name="points" min="0" max="10"& ...

Adding event listener to a dynamically created video element

Could you provide any insight as to why I'm encountering an error message "Can't create event listener on null" when using the following code: var my; my.newVidObj = document.createElement('video'); my.newVidObj.src = "vid- ...

As the width decreases in animation, the content gradually disappears until it reaches zero

My issue involves red and black divs; when I hover over the parent element, the red div should appear by expanding to its full width. However, a problem arises when the width is set to 0px as the content still shows. Can someone provide assistance on how t ...

Using Javascript's OnChange event to dynamically update data

Attempting to achieve a seemingly straightforward task, but encountering obstacles. The goal is to trigger a JavaScript onChange command and instantly update a radar chart when a numerical value in a form is altered. While the initial values are successful ...

What are the steps to vertically aligning rows in bootstrap?

I've been exploring different solutions to vertically center my rows within the container. Adding d-flex and align-items-center did work for centering them vertically but caused the rows to appear side by side. I'm curious if there's an alte ...

Header and footer set in place with customizable height paired with a dual-module sidebar

I'm working on a layout that includes a fixed footer and header. My goal is to make the height of the "info-box" div variable, while having the "scrolling-div" fill the remaining vertical space in the right column. The issue arises when setting the he ...

How to horizontally center an element using HTML and CSS

I am encountering an issue while trying to create a navigation bar or header. The problem lies in centering an h1 element. Here is the HTML code I am using: body { margin: 0; padding: 0; } header { display: flex; justify-content: space-between; ...

Showing a PDF from a shared folder on a network using AJAX in HTML5

I'm facing a challenge with displaying a PDF on the web. The layout includes a dropdown menu on the left with various PDF file names, and upon selection, the chosen PDF should be displayed on the right using an ajax call. Since my PDFs are stored in a ...

Bespoke Video Player using HTML5 with "Nerdy Stats" Feature

I have been given the task of creating a streaming video testing framework for internal metrics and measurement purposes. Essentially, I am looking to develop an HTML5 player that can handle streams and provide performance data related to: - Average Bitr ...

Choose everything except for the list and its heading

I have a portion of HTML code on my hands. <div class="ProductDescriptionContainer"> <p>This handsome Clergy Shirt has a trim low neckband with two reinforced buttonholes, one at the front, one at the back, to align with Ziegler's Collare ...

What is the proper location to place the CSS I wish to implement for a module?

As I embark on creating my inaugural DotNetNuke website, I find myself faced with the task of adding an HTML module to a page. To style the text within it, I have been advised to utilize CSS classes. I'm curious about where .css files should be place ...