Combining SVG files with hover effects can cause issues with link functionality

I am looking to accomplish the following

  • Text and svg elements should move when hovered over
  • Color should be reversed on hover.
  • Link should be opened

This is the HTML code I have:

<div class="btn_ol">
    <a href="http://google.com/" target="_blank"></a>
    <span>Google<object class=ol_svg data="../assets/images/common/icon_ol.svg" type="image/svg+xml"></object></span>
</div>

This is my CSS styling:

.btn_ol {
    padding: 2.3rem 1.8rem;
    border: 2px solid #0c5a9d;
    cursor: pointer;
    width: 604px;
    display: block;
    margin: 35px auto;
    outline: none;
    vertical-align: middle;
    text-align: center;
    position: relative;
    overflow: hidden;
    background-color: transparent;
    color: #0c5a9d;
    transition: background-color 300ms ease-out;
    z-index: 1;
}

.btn_ol:hover {
    background: #0c5a9d;
    border-color: #0c5a9d;
    color: #fff;
}

.btn_ol a{
    position: absolute;
    display: block;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
}

.btn_ol span {
    display: inline-block;
    position: relative;
    font-size: 1.8rem;
    margin: 0 auto;
    transition: all 300ms ease-out;
    will-change: transform;
    font-weight: bold;
}

.btn_ol:hover span {
    transform: translate3d(-1rem, 0, 0);
}

.btn_ol .ol_svg {
    position: absolute;
    margin: auto 5px;
    top: 25%;
    width: 1.1em;
    right: -0.5rem;
    opacity: 0;
    transition: all 300ms ease-out;
    will-change: right;
}

.btn_ol .ol_svg * {
    stroke-width: 5;
}

.btn_ol:hover .ol_svg {
    opacity: 1;
    right: -3.5rem;
}

@media screen and (max-width: 720px) {
    .btn_ol { 
        width: 100%;
        padding: 2.3rem 1.1rem;
        margin: 20px auto;
    }
    .btn_ol span {
        line-height: 1.8rem;
        font-size: 1.4rem;
    }
    .btn_ol .ol_svg {
        top: 15%;
        right: 0rem;
    }

    .btn_ol:hover .ol_svg {
        right: -2.5rem;
    }
}

In this CSS, our goal is to achieve the following: - Text and svg elements should move when hovered over - Color should be reversed on hover. - Link should be opened

While everything worked fine on desktop, I encountered an issue with the mobile site operation.

When using a tablet, it takes two taps to follow the link. The first tap triggers hover state and the second tap opens the window.

It seems that removing

.btn_ol:hover .ol_svg {
    opacity: 1;
}

would allow the link to open on the first tap, but I'm unsure how to maintain the SVG view in this scenario.

Please assist me :)

Answer №1

Feel free to give this code a try.

<div class="btn_ol">
    <a href="http://google.com/" target="_blank">
        <span>
             Google<img src="../assets/images/common/icon_ol.svg" type="image/svg+xml"> 
        </span>
    </a>
</div>

It's currently working for me.

Answer №2

Using images as links is a popular practice, just make sure to enclose them in the appropriate tag.

<div class="btn_ol">
    <a href="http://google.com/" target="_blank">
        <span>Google<object class=ol_svg data="../assets/images/common/icon_ol.svg" type="image/svg+xml"></object></span>
    </a>
</div>

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

Ways to customize the color surrounding a slider image with the help of Bootstrap

I just started working with bootstrap design, and I encountered an issue with my slider images. There is a gray color around the slider images that I want to change, but my attempts are not yielding results. Here is what I tried: https://i.sstatic.net/xnsF ...

Tips for setting the textfield value in JSP using Javascript

I am in need of a way to create a random number that will be displayed in the textfield once the user clicks on the "Generate" button. Can someone guide me on how to assign the value of the "output variable" to the "randomNum" textfield? Sample HTML code: ...

Responsive navbar in Bootstrap collapses and closes again after opening on a small screen

Although the navbar functions properly on larger screens, it collapses back after pressing the collapse icon when viewed on a mobile screen. <!DOCTYPE html> <html lang="en"> <head> <!-- Required meta tags --> <meta charse ...

Retrieve the final h1 tag preceding the clicked element

When a visitor interacts with an element on a webpage, I am tasked with locating the nearest h1 heading above the clicked element and extracting its HTML content. Consider the following HTML snippet: <div> <h1>This is header 1</h1> ...

SVGs are not resizing correctly in Internet Explorer and there is unnecessary blank space around them

Recently, I made the decision to switch to using SVG symbols for one of my projects. However, I encountered a challenge as I needed these SVGs to be responsive. My main objective was to minimize the number of HTTP requests, leading me to explore the option ...

What is the best way to showcase various types of files such as images, documents, Excel sheets, and PDFs in the

Looking for help to display different file types like images, documents, Excel files, and PDFs in the preview-image box. Any assistance would be greatly appreciated! *{margin:0px; padding:0px;} #container{width:20%; padding:2%; box-shadow:0px 0px 10 ...

responsive position absolute to the auto width of position absolute

Here is an example of my CSS code: https://jsfiddle.net/80e4u0dd/ When you hover over the orange box, the a element gets underlined. The orange box needs to stay above the "long text" in the green box, just like it is currently. The issue is that the oran ...

The jQuery "form-row" for dynamic input generation in Bootstrap is experiencing technical difficulties

When I click the Add Wings/Blocks button, dynamic fields are created using jQuery which are Bootstrap components. I want to arrange 3 fields from (left to right) in a single row. Although I have written code for it, the "form-row" is not arranging the fie ...

An unconventional layout of columns in Twitter's Bootstrap design

I've encountered an issue and I'm currently struggling to find a suitable solution. My goal is to achieve the following layout (for screen sizes greater than or equal to medium): Within black boxes, there will be images displayed. The white spac ...

Is it possible to eliminate the black bars from YouTube HQdefault image using only CSS?

(After searching extensively, I couldn't find the exact same question and answer) I have a dilemma with displaying YouTube's hqdefault thumbnails on my page. It seems that they are 480 by 360 pixels, resulting in black bars at the top and bottom ...

Guidance on dynamically changing the primary color in Ionic 5

Currently, my app-component routes to a split-layout which then navigates to other pages. When I want to change the accent color in the settings page, I use the following workaround: changeAccentColor() { console.log('Accent-color changed to: &apo ...

How to align text at the top vertically and add a label using Bootstrap

Align text vertically at the top with a label in a bootstrap table cell, where the label text should wrap around. <td> <span>16/12/2018 00:00:00</span> <p class="label label-danger" style="width:100px;line-height:normal;word-wra ...

What's the best way to format my blog post with HTML in Django?

I am looking to integrate HTML formatting directly into my blog post from the admin page. In the models.py file, you can see that the description field is set as a TextField. My goal is to have the ability to include HTML tags in my blog post content on th ...

The process of embedding a .js file into an HTML document involves

The question appears to be straightforward. The common approach is to simply utilize this code snippet: <script src='https://code.angularjs.org/1.0.0rc9/angular-1.0.0rc9.js' type='text/javascript'/> Alternatively, in Jsfiddle, we ...

Issue with Cascading Dropdowns in jQuery

I am currently experiencing issues with a piece of code on my website (also accessible via this link). The code consists of 2 select fields that should display different data based on the selection made. However, I have identified 2 bugs within the code. ...

Mobile devices are having issues with CSS rendering

I've encountered an issue with my CSS code. It seems to be working fine until the @max-width:767 media query, but then it stops working on the resolution immediately below it, which is @425. However, it starts working again on resolutions below that. ...

Implementing an efficient data prefetching strategy for external JSON files

Is there a way to preload a JSON file from a URL and access it later in my JavaScript file? How can I pass the prefetched JSON data to the JS file? For example, could I include something like this in the HTML head: <link rel="prefetch" href=& ...

Java Array Index Size Mismatch

After discovering a Java application on Google Code that has been working well for me, I encountered a situation where it was not functioning properly. As a newcomer to Java, I attempted to resolve the issue myself but quickly realized that it was beyond m ...

Place in the Middle of a Bootstrap Container

Struggling with aligning the elements of a Bootstrap well in the center? The badge is off to the side instead of below the arrows, and the vote buttons are not centered within the well. Check out the code snippet below: HTML: <div class="col-md-1 ...

<p> appears below the <img> element without the need for a <br> tag

<img src="http://cdn.akamai.steamstatic.com/steamcommunity/public/images/avatars/d1/d1a6cabea45b1f34f639b4f3dba8dd7af91072d4.jpg"><p>text 1</p>&nbsp;&nbsp;&nbsp;<p>text 2</p> Instead of using the <br> tag, I ...