Display an image with text that appears on hover along with a change in opacity

Is there a way to make the hover effect on an image display with opacity while keeping the text inside unaffected by the opacity style? The image is housed within an input tag, and when clicked, a bootstrap modal will appear with an input form.

.img_wrap:hover 
 #updateImg{ opacity: 0.7; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div class="img_wrap">
     <input type='image' id='updateImg' src='http://placehold.it/350x150'>
       </input>
       <span></span><p class="imgText">Click here to change your image</p>
     </div>

Answer №1

To manage the opacity of each child element individually, it is necessary to handle them separately. If you want these elements to overlap, one of them (the text in this example) needs to be positioned absolute, and its parent should be positioned as relative.

Does the following example demonstrate what you are trying to accomplish? If not, please provide clearer instructions.

.img_wrap {
  position: relative;
  display: inline-block;
}
.img_wrap input[type="image"]{
  opacity: 1;
  display: block;
  transition: opacity .3s cubic-bezier(.4,0,.2,1)
}
.img_wrap:hover input[type="image"] {
  opacity: .3;
}
.img_wrap .imgText {
  position: absolute;
  height: 100%;
  width: 100%;
  left: 0;
  top: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  opacity: 0;
  transition: opacity .3s cubic-bezier(.4,0,.2,1)
}
.img_wrap:hover .imgText {
  opacity: 1;
  pointer-events: none;
}
<div class="img_wrap">
  <input type='image' id='updateImg' src='http://placehold.it/350x150' />
  <div class="imgText">Click here to change your image</div>
</div>

Notes:

  • <input> is a self-closing tag, so <input></input> is invalid.
  • <input type="image"> is meant to replace a submit button with an image. It acts like a button but resizes itself to fit the image ratio. To upload an image to the server using <input>, consider using <input type="file" />

Answer №2

Here is the content you seek

.image_container{
    display: inline-block;
    position: relative;
}
.image_container:hover #updateImage{
    opacity: 0.7;
    position: relative;
}
.image_container:hover .imageDescription{
    position:absolute;
    top:0;
    bottom: 0;
    left: 0;
    right:0;
}

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

Conceal the column title for order items in the WooCommerce admin panel

I've been attempting to hide certain columns within the administrative section of Woocommerce, but have had no success with the code I'm using. I'm currently stuck and my question is: Is there a way for me to conceal specific column names i ...

Guide to making a toggle button with a Light/Dark mode functionality

I have implemented a light/dark toggle button and now I want to integrate the functionality for switching between light and dark themes on my webpage. The switch should toggle the theme between dark and light modes when clicked. Some basic styling has been ...

Suggestions for resolving the issue of my header being truncated on mobile browsers?

I am facing an issue with my header and need assistance in fixing it. The problem occurs when scrolling down, as it cuts off a part of the header, but returns to normal when scrolling back up. I suspect the hamburger menu might be causing this issue becaus ...

Utilizes an external CSS font file for eBay advertisement

After researching numerous answers, I am still unable to identify what I may be doing wrong. I have designed a collection of custom fonts using iconmoon, and after downloading the css and font files, I uploaded them to a directory on my website. I am attem ...

Guide on displaying Adsense ads specifically for mobile devices

Can anyone provide me with a proper method to show/hide my AdSense ads on both mobile and desktop? I am currently using a method that results in 2 console errors. Here is the current approach: We are utilizing two classes, "mobileShow" and "mobileno," t ...

What is causing the extra space on the right side of the box?

I've been struggling to align text next to an image inside a box. Desired outcome CSS: #roundedBox { border-radius: 25px; background: #363636; width: auto; height: auto; margin: 10%; display: flex; position: relative; ...

What is the best way to place tfoot at the top of the table

Below is the structure of my table: https://i.stack.imgur.com/QmlVn.png In the table, there are search input fields at the bottom of each column. I would like to move them to the top, right after the <thead> </thead>. The basic HTML code for ...

What are some effective methods for overriding materialui styles?

Here is the CSS style for a checkbox in Material-UI that I captured from the console: .MuiCheckbox-colorPrimary-262.MuiCheckbox-checked-260 I attempted to override this style using the following code, but it was unsuccessful: MuiCheckBox: { colorP ...

How to apply gradient colors to borders using CSS

Is it possible to create a simple border bottom color with a gradient effect? div{ border-bottom:10px solid linear-gradient(#FF4000, transparent); height:20px; width:auto; background:#ccc; } <div></div> ...

Place the application bar at the bottom of the screen

I am working on a project aimed at monitoring employees, and I have developed a user interface that allows for modifications within the site. However, there is an issue with the "bottom App Bar" section at the bottom of this interface which has a blue back ...

Creating equal height for two element children using CSS

As I construct a pricing table, I'm faced with the challenge of ensuring that the child elements within each row are of equal height. The website is built on WordPress and utilizes a page builder, resulting in the row fields being positioned different ...

Spring load without CSS

Upon successful login, I am redirected to my main site using the following controller: //Login Success @GetMapping("/login-success") public ModelAndView loginSuccess() { return new ModelAndView("/cont/home.html"); } The URL for this redirection i ...

Displaying a Facebook tab exclusively within the Facebook platform

Hello Everyone I have been utilizing woobox to generate Facebook tabs for my pages and I have a query: I have created an HTML page on my personal server, which I am using as a Facebook tab (created with the help of woobox). Now, is there a method whe ...

Eliminating the vertical scroll on a webpage with the help of Bootstrap 5's responsive design capabilities

I've been tasked with converting a Figma design into an HTML page using Bootstrap 5. Take a look at the Figma design: https://i.sstatic.net/jo5Si.png However, there's an issue causing a vertical scroll bar to appear on the page. The culprit see ...

Activate the toggle menu

Hi there! I'm currently working on a menu and I want the clicked item to become active, switching the active state to another item when clicked. However, my current implementation is not working as expected. Any assistance would be greatly appreciated ...

Setting up CSS Flexbox so that the first child element is the same height as the

I am striving to ensure that when the layout switches to mobile, the image block matches the height of the title and content blocks. The layout is quite complex; it functions correctly in desktop view with the title block at the top full-width. I suspect ...

The functionality of the CSS transform property seems to be malfunctioning

My HTML and CSS code displays texts in two blocks within a dl element. I attempted to change the ▶ symbol to a different shape using the css transform scale property. However, some browsers only show the triangle in the first column. Why is this happenin ...

Ways to widen the header to fit the entire page?

I'm having trouble stretching my header to fill the entire page. I've tried using margin-left and right, but it's not working as expected. My Header CSS: background: green; height: 70px; width: 100%; display: flex; just ...

Creating a unique card component with React and custom Tailwind CSS styling

I am working on creating a project component using React: Despite my efforts, I have not been able to find the correct documentation for assistance. Additionally, I am facing challenges in utilizing next/image to ensure that it is the correct size. This ...

Align the headers of columns to the right in the AgGrid widget

Is there a way to align the column headers to the right in AgGrid without having to implement a custom header component? It seems like a lot of work for something that should be simple. You can see an example here: https://stackblitz.com/edit/angular-ag-g ...