Enhanced button effect: image shaded on hover

Can someone help me figure out how to make the button and image darker when hovered over? I tried something but it didn't work...

Here is a demonstration: http://jsfiddle.net/h2o8w5y6/

<!--- example code snippet -->
    <div class="col-lg-4">
        <div class="home-images">
            <img src="http://www.alessioatzeni.com/wp-content/tutorials/html-css/CSS3-Hover-Effects/images/1.jpg">
        </div>
        <div class="home-images-content">
                    <h3>Lacobel</h3>
                    <a href="#" class="choose-home">Select</a>
        </div>
    </div>
    <!--- end of item -->

Answer №1

If you're looking to achieve this effect, a simple tweak to your HTML and some css positioning is all it takes.
You can utilize the css adjacent selector (+), which targets only the element immediately following another element.
In this situation, you need to position your <a> element right before the <img> tag like so:
HTML:

<!--- item -->
<div class="col-lg-4">
    <div class="home-images">
        <h3>Lacobel</h3>
        <a href="#" class="choose-home">Choose</a>
        <img src="http://www.alessioatzeni.com/wp-content/tutorials/html-css/CSS3-Hover-Effects/images/1.jpg" />
    </div>
</div>
<!--- item -->   

CSS:

.choose-home:hover + img {
    -webkit-filter: grayscale(100%);
    -moz-filter: grayscale(100%);
    -ms-filter: grayscale(100%);
    -o-filter: grayscale(100%);
    filter: grayscale(100%);
    filter: url(grayscale.svg);
    /* Firefox 4+ */
    filter: gray;
    /* IE 6-9 */
    ;
}
.home-images h3 {
    color:#fff;
}
.choose-home {
    background:url('../images/ok_icon.png') #00b9ee no-repeat;
    background-position:10% 50%;
    padding-left:60px;
    padding-top:12px;
    height:45px;
    width: 125px;
    display:block;
    color:#fff;
    border-radius:5px;
    position: absolute;
    top: 300px;
}
.choose-home:hover {
    background:url('../images/ok_icon.png') #ff0042 no-repeat;
    background-position:10% 50%;
    display:block;
    text-decoration:none;
    color:#fff;
    border-radius:5px;
}
.choose-home:focus {
    text-decoration:none;
    color:#fff;
}   

Your css targets the .choose-home:hover + img element, while structuring your link below the image with position: absolute; top: 300px;.

JSFiddle Link

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

Does HTML5 officially provide the speechsynthesis API for users?

Can someone clarify if speech synthesis is officially supported by HTML5 for converting text-to-speech? ...

The JavaScript function is not functioning properly, whereas another function is working as intended

I have created a HTML form with 2 buttons and a table. Each row in the table consists of a checkbox and 2 text fields. The buttons allow users to add and remove rows from the table. The remove button only applies to rows where their checkbox is checked. T ...

Is there a way to open an HTML file within the current Chrome app window?

Welcome, My goal is to create a Chrome App that serves as a replacement for the Chrome Dev Editor. Here is my current progress: background.js chrome.app.runtime.onLaunched.addListener(function() { chrome.app.window.create('backstage.html', { ...

Manipulating links using JQuery: avoiding the binding of new links

I need to update a website with 50 pages that currently doesn't use ajax, making it cumbersome to make edits since changes have to be made on all 50 pages individually. After removing duplicate HTML from all 50 pages, I'm facing some issues: fu ...

Animating multiple elements in Angular 2 using a single function

Currently, I am delving into Angular and faced a challenge while attempting to create a toggle categories menu. Within my navbar component, I have an animation trigger set up as follows: trigger('slideCategory', [ state('opened&apo ...

Prevent IonContent from scrolling to the bottom or top when using Ionic framework

In my Ionic app, I have a long text page with 2 buttons that trigger the actions scrollToBottom and scrollToTop. Due to the length of the page, I have set the scroll duration to be 30 seconds. I am facing two issues here: How can I stop the scrolling ...

When the onclick function is triggered, two or more characters will be displayed

Functionality: To input name and email, users must click on the virtual keyboard displayed on the screen. Characters entered will be shown in the input box. Implementation: The HTML keyboard interface and associated script have been developed successful ...

Are cookies always included in client requests?

With every interaction between the server and browser, cookies are exchanged back and forth. However, what happens when an image is requested? <img src='myPic.jpg' /> Is the browser also sending cookies during this type of request? If i ...

Data modifications in polymer are not being accurately displayed

I need help with hiding/unhiding a UI element using a button in Polymer. Despite having the necessary elements and code set up, it is not working as expected: <button id="runPredictionButton"> <i>Button text</i> </button> <p ...

Creating a tiled grid layout using Bootstrap 3

I’m grappling with a masonry layout issue while using Bootstrap. In my code, I have 5 divs but I’m struggling to get Div 4 and 5 to move up as shown in the attached image. While using margin-top is a quick fix, it disrupts the responsive design. Any su ...

Display words on screen and then alter hue using HTML and CSS

Is there a way to dynamically change the color of text inside <a> tags from black to red after a specific time interval and keep it permanently red? do { document.getElementById("code").innerHTML +="<a>Hello World</a><br>"; awa ...

Switching the Vue image on Routerlink's isExactActive feature

Is there a way to display different images based on whether a link is active or not? <router-link to="/"> <img src=" :active = isExactActive ? pic_active.png : pic_inactive.png}}" /> //Something along these lines ...

update the markers on a leafletjs map

I am aiming to create a dynamic map with markers that update every 10 minutes. The marker positions are stored in a spreadsheet document that is regularly updated. After successfully retrieving the data from the spreadsheet and positioning the markers in ...

The art of uploading images with HTML and CSS

Looking for guidance on how to convert this image bubble so that users can upload their images during account creation. When the user hovers over the image bubble, it should display "Upload profile image" and prompt them to upload an image upon clicking. A ...

PHP form does not seem to be vulnerable to cross-site scripting attacks

On one of my web pages, I have a form with an action php page using the following html syntax: <form name="form" action="test.php" method="get"> I decided to make it more secure by modifying it to: <form name="form" action="<?php echo htmlsp ...

Can data be transferred between browsers, such as from Google Chrome to Mozilla Firefox?

I have a dilemma with two separate pages—one for Admin and the other for User. The Admin page is named index.html <!DOCTYPE html> <html lang="en"> <head> <style> * { padding: 0; ...

I'm looking to adjust the position of an image inside a div without affecting the position of the entire div

When creating a horizontal navigation bar with an image, I encountered an issue where the image link did not align with the rest of the links on the navigation bar. I wanted to drop it down by a pixel or two without affecting the position of the other link ...

What is the best way to position my NavBar items to the right using the Bootstrap v5.2 framework?

I am working on a project for my course and need some help. My goal is to have the brand stay aligned to the left, while other items align to the right. I have been able to achieve this without a toggler using justify-content-end, but with a toggler, I a ...

Reposition div when clicked

I have encountered a challenge where I am unable to perform a small task. My goal is to have the position of "div1" change upon clicking on "div2", taking into account that "div2" is nested inside "div1". Additionally, when clicking on "div2" again, "div1" ...

I am interested in displaying the PDF ajax response within a unique modal window

With the use of ajax, I am able to retrieve PDF base64 data as a response. In this particular scenario, instead of displaying the PDF in a new window, is it possible to display it within a modal popup? Any suggestions on how this can be achieved? $.ajax ...