When a hover effect occurs beyond the button's boundaries

Currently, my code is producing a black bar element that appears both above and below my link. The bottom bar is always there, while the top bar only appears when the link is hovered over.

Although my code is functional, the hover effect seems to trigger whenever the cursor is aligned with the link, making it seem like the 'hit' box extends the entire width of the screen even though the button consists of just the text.

#contact-btn a {
    position: relative;
    font-family: 'Montserrat', sans-serif;
    display: inline-block;
    font-size: 3em;
    letter-spacing: 1px;
    font-weight: 400;
    color: #4d4d4d;
}

#contact-btn a:after, #contact-btn a:before { 
    display: block;
    position: absolute;
    content: '';
    margin: 0 auto;
    background-color: #4d4d4d;
}

#contact-btn a:after { 
    height: 2px; 
    width: 100px;
    bottom: -15px; 
    left: 0; right: 0; 
}

#contact-btn a:before { 
    height: 2px; 
    width: 0;
    top: -15px; 
    left: 0; right: 0; 
}

#contact-btn:hover a:after, #contact-btn:hover a:before { 
    width: 175px; 
    height: 2px; 
}

HTML

<div id="contact-btn">
    <a href="mailTo:..."> Click here </a>
</div>

Answer №1

No specific styling has been applied to the contact-btn div. To enhance its appearance, consider incorporating the following CSS:

#contact-btn {
   display: inline-block;
   position: relative; 
}

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

Is there a way to position a video towards the right side of the screen?

I'm working with an HTML5 video that has a height greater than its width. I've set the video to have 100% in height and 100% in width so it scales automatically based on my window size. However, I want the video to be positioned on the right sid ...

Find the parent element using its XPath

Here is the code snippet I'm working with: <div class="different"> <input id="distinctId" type="checkbox"> <label for="distinctId">a unique label</label> </div> I know how to select the input element using its i ...

Display a div using jQuery when it reaches halfway the height of another div

I have a code snippet that hides the .wp-filter when reaching the bottom of the .wpgb-layout jQuery(window).bind('scroll', function() { if(jQuery(window).scrollTop() >= jQuery('.wpgb-layout').offset().top + jQuery('.w ...

Reduce the size of the header in the Sydney theme for WordPress as you scroll

Currently, I am attempting to reduce the size of the header once scrolling down. My focus is on refining the child theme. Displayed below is a screenshot illustrating the appearance of the header at the top of the page: https://i.stack.imgur.com/wojGf.pn ...

Having trouble with tabs in jQuery?

I'm having trouble setting up tabs in a reservation form with 3 tabs that include text boxes for user input. I can't seem to get it working properly and I'm not sure where I've gone wrong. Could it be due to the placement of the content ...

Attaching an SVG chart to a node causes it to malfunction, indicating a fundamental element is absent

I've been attempting to display a d3fc graph on an svg node within my react.js component and return the entire structure. However, it crashes when I try to apply .datum(my_data) to the d3 selection. I suspect that I'm overlooking something fundam ...

Nginx forwards static content to a subdirectory within the main root directory

I have an application running at http://192.168.0.2:8080/. The main index.html page is located in the /web directory and it fetches static files, such as css, from the /css folder. My aim is to use nginx as a reverse proxy to redirect myapp.mydomain.com t ...

Can anyone explain why my inner div's display is set to block and it is being pushed down when its parent div has

Below is a sample of my HTML+CSS code: <div> <div class="first">text</div> <div>more text</div> </div> div { display: inline; } .first { display: block; } What's interesting is that when the first ...

Add the cordova plugin multi-image-picker with the following command

onDeviceReady: function() { window.imagePicker.getPictures( function(results) { for (var i = 0; i < results.length; i++) { alert('Image URI: ' + results[i]); } }, function ...

What adjustments can be made to the Bootstrap code to prevent it from causing layout issues with the Signin Form and Footer?

Recently, I've encountered some challenges with the footer formatting on my website's home page and the sign-in form on a separate page. It appears that the Bootstrap framework at the top of the page is affecting these elements exclusively. How c ...

Is it possible to change the color of specific days of the week (like Mondays, Tuesdays, etc.) in JQueryUI's datepicker?

Is it possible to customize the appearance of specific weekdays (such as all Mondays, all Tuesdays for the entire year) in the JQueryUI datepicker by changing their color? While there are existing methods to select certain dates and disable holidays, I h ...

Implementing text overlays on images within a Bootstrap 4 navigation bar

I am struggling to grasp the flex structure in Bootstrap. I'm attempting to overlay text on an image within the navbar, but it seems the container of the navbar is causing issues. Perhaps my containers are not set up correctly. Any assistance would be ...

What is the proper usage of main.js and main.css within the skeleton portlet project that is created by the Liferay 6.0.6 plugin SDK?

Is it a good practice to include portlet-specific JS or CSS in them only if <portlet:namespace /> works within them? Should I rely on unique function/variable names or class names instead? ...

Confirm that only the days of the present month are eligible for selection

I have been given the responsibility of validating a date field that is populated when an invoice is created. The date field consists of a text box and three button objects allowing users to select a date from a calendar, input today's date, or remove ...

I am attempting to display the Δ symbol on my website, however, it is not appearing on the webpage

In my attempt to display my company logo on the website, I encountered an issue where the Δ symbol is not appearing correctly in the browser. strong class="footer-logo">KyΔnsys</strong To address this problem, I have implemented unicode charset=" ...

Unpredictable spacing in a row arrangement thanks to Tailwind`s randomized

https://i.sstatic.net/QkqVo.png I am facing difficulty in creating a 2-column fixed layout with precise width control. The layout I have currently seems almost perfect, but there is some strange padding on the top-left element. Parent <Layout> ...

What is the best way to choose CSS class attributes using Mootools and the getStyle()

Seeking to duplicate an object, I am trying to figure out how to retrieve class CSS attributes from Mootools. css: .card { width: 109px; height: 145px; } html: <div id="cards"> <div class="card" id="c0"> <div class="face fron ...

Creating uniform row heights in CSS Grid Layout

It seems that achieving this using Flexbox is impossible because each row can only be the minimum height required to fit its elements. However, I'm curious if this can be done using the newer CSS Grid. Just to clarify, I am looking for equal height f ...

Obtaining the element ID with Selenium WebDriver in cases of dynamic IDs

I am encountering an issue with the drop-down image element. I have attempted various methods to select the element, but none of them seem to be working. This may be due to the fact that both elements are identical and their IDs are dynamic. I did manage ...

Is there a way to access the font characteristics of a website?

I'm currently in the process of customizing my WordPress theme and I'm looking to adjust the font sizes for certain elements such as pagination. However, I'm finding the style.css file to be quite convoluted and I'm having trouble ident ...