Show an SVG overlay when hovering over an image

Is there a way to create a hexagon shape around an image when it is hovered over using CSS only, even if the image itself has a circular border-radius of 50%?

Answer №1

If you want to use an SVG hexagon image as the background of a div, you can hide it initially and then reveal it when needed. You can also display your own image within that div, and on hover, show the hexagon image in the parent div.

To achieve this, you can utilize CSS similar to the following:

.parent-div .svg-img{
display:hidden;
}

.child-img:hover .child-img:parent img{
display:block
}

Answer №2

Utilizing CSS allows for the integration of a background featuring an SVG image:

span {
  display: inline-block;
  padding: 50px;
  float:left;
  pointer-events:none;/* to trigger events only on img:hover */
}
img {
  display: block;
  border-radius: 100%;
  pointer-events:auto;/* catch mouse events so are parents seeing it too */
}
span:hover,
span +img:hover {
  background: url(data:image/svg+xml;base64,PHN2ZyBpZD0iY29sb3ItZmlsbCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB2ZXJzaW9uPSIxLjEiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjMwMCIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPg0KICANCiAgPHBvbHlnb24gY2xhc3M9ImhleCIgcG9pbnRzPSIzMDAsMTUwIDIyNSwyODAgNzUsMjgwIDAsMTUwIDc1LDIwIDIyNSwyMCI+PC9wb2x5Z29uPg0KICANCjwvc3ZnPg==);
}
span + img {
  padding: 50px;/* those extra 50px catch hover too */
  
}
<span><img src="http://dummyimage.com/200x200&text=span-img"/></span>

<img src="http://dummyimage.com/200x200&text=img-alone" />

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

Get the docx file as a blob

When sending a docx file from the backend using Express, the code looks like this: module.exports = (req, res) => { res.status(200).sendFile(__dirname+"/output.docx") } To download and save the file as a blob in Angular, the following code snippet i ...

Looking for help understanding a basic piece of code

$('#ID').on('click', function() { if(!CommonUtil.compareDateById('startDt','endDt',false, false, true)) { return false; } var cnt = 0; if(!CommonUtil.isNullOrEmptyById('startD ...

Accessing fields from other sources in ng-repeat can be accomplished by utilizing special syntax within the ng-repeat directive

I have a unique challenge where I need to utilize the firstkey from one AngularJS model, firstcollection, as an index value in another collection called anothercollention. Essentially, I want to iterate over the values in anothercollention based on the k ...

Extracting Text from a Span Element Using XPath in Selenium

Here is the HTML code snippet: <div class="a-row a-spacing-small a-size-small"> <div class="a-row"> <a class="a-link-normal a-declarative g-visible-js reviewStarsPopoverLink" href="#" data-action="a-popover" data-a-popover="{"closeButton":" ...

Styling Tip: Aligning text to the baseline of a height-adjusted input field using CSS

As per the information from the Mozilla documentation, it states that I can align the text in an input field to the baseline if the element's display property is set to inline-block. I have made adjustments to the height of several input elements, bu ...

Include onload to element without running it in Puppeteer

I am currently developing a web scraping tool using Puppeteer. Once the webpage is fully loaded, I need to update the HTML code and include an onload event for certain elements. The issue is that in Puppeteer, the onload event is actually triggered automa ...

JavaScript will not prevent PHP form submissions from executing

I am currently facing an issue with JavaScript where it displays an error window, but surprisingly does not prevent the form submission. I have been trying to figure out what exactly is causing this problem without much success. Below is the code I am work ...

Resolving redundancy in Typescript Material-UI Table codebases

Apologies for the ambiguous question title, it was difficult to come up with something more specific. I am currently exploring the Typescript implementation of Material-UI tables, specifically focusing on the table section titled "Sorting and selecting". ...

Bootstrap navigation bar collapsing horizontally instead of vertically

My Navbar is collapsing correctly, but when I click the toggle icon after it's collapsed, the items appear in a horizontal row instead of the intended vertical block. I have checked the code on the Bootstrap 5 example page and tried to replicate it, b ...

How can I trigger an event in Vue.js when a selection is made in a dropdown menu?

Here is an illustration fiddle: https://jsfiddle.net/40fxcuqd/ Initially, it shows the name "Carl" If I choose Carol, Clara, etc., an event will be triggered and data will be logged to the console. However, if I click on the dropdown and select "Carl" ...

How to Send Data to ASP.NET MVC Controller Using AJAX Request with jQuery

I am trying to send parameters to a controller from jQuery, but I am struggling with it. The call works fine without parameters when the URL is just /SurveySection/EditLocalization. Shouldn't it be something like this: /SurveySection/EditLocalization? ...

Tips for implementing two functions to run within the onClick event handler in React

I am looking to simultaneously execute two functions handleClose and saveData within the onClick method. The specific location where I want this execution to happen: <Button variant="contained" onClick={saveData}&g ...

Latest Version of Bootstrap (v5.0.1) - Issue with Hamburger Menu not Auto-closing when Clicking on Anchor Links on

Hello fellow developers, I'm facing an issue with the hamburger menu in a responsive layout using Bootstrap v5.0.1. The problem is that the menu doesn't automatically close when clicking on anchor links within the same page, even though collapse ...

Associate the ng-model with ng-options value and label

I'm currently using ng-options to create a select tag that displays location options. The labels represent the location names, while the values indicate the corresponding location ID as stored in the database. In addition to binding the value (locati ...

Refreshing JWT Authentication in Angular

I am currently following a tutorial on Egghead.io, which can be found here. However, I am adding a MongoDB to fetch my users which is causing me some issues. I have managed to get everything working except for the part where it mentions that the /me route ...

What is the best way to calculate the total sum of the first element in each index of an array when using ng

I am looking to calculate the sum of the first elements from all indexes of an array using ng-repeat in AngularJS. My goal is to declare a variable and increment its value with each iteration of ng-repeat, then display that variable at the end. Below is ...

React: Dynamic input field that removes default value as the user begins typing

Imagine a scenario where we have a text box in a React application with Formik and Material UI that accepts a price as a floating point number. By default, the field is set to 0. However, once the user manually enters a number, the default value should be ...

``There Seems to be an Issue with Loading Content in Tabs

Hey! I'm encountering an issue with my jquery tabs. The first tab content loads fine, but when I select another tab, the content doesn't display. Then, when I try to go back to the first tab, it doesn't load either. Here's the HTML cod ...

Angular Typescript filter function returning an empty arrayIn an Angular project, a

I have a filtering function in Angular that is returning an empty array. Despite trying similar solutions from previous questions, the issue persists. The function itself appears to be correct. Any assistance would be greatly appreciated. gifts represents ...

The checkbox that is dynamically added within a jQuerymobile list view is experiencing rendering issues

Having trouble with rendering dynamically added checkboxes inside a jQuerymobile list view. Here is the unordered list I am working with, including a sample list item in the HTML: <ul data-role="listview" id="ul_address_list" > <li data-icon=" ...