Does the hoverable region extend beyond the text of the <span> element inside an <a> tag?

It appears that there is a rectangular border surrounding the text, making it also hoverable. I only want the characters themselves to be hoverable. I attempted using a 'span' element to correct this issue but it did not work as expected.

a:hover{
    color: #ff0000;
    text-shadow: 1px 1px 20px #ff0000;
}
#shrine{
    display: inline-block;
    font-family: 'aurora';
    text-shadow: 1px 1px 0px #ff0000, 1px -1px 0px #ff0000, -1px -1px 0 #ff0000, -1px 1px 0px #ff0000;
    transform: scaleY(1.6) scaleX(.9);
    padding: 0;
    margin: 0;
    font-size: 8vw;
    margin-bottom: 2vw;
}
<div class='maindiv'>
    <ul>
      <li>
        <a href=''><span id='shrine'>SHRINE</span></a>
      </li>
    <ul>
<div>

Answer №1

The reason for this behavior is the use of the transform property, which alters how the element appears on the screen.

When an inline element is transformed, its outline will still be based on its original position.

Check out the examples in the provided code snippet. When you apply a transform, the element's outline may try to incorporate both the transformed and original bounding box for event triggering purposes. If your goal is simply to increase text size, it's recommended to utilize the font-size property instead.

* {
    box-sizing: border-box;
}

a {
    outline: 1px solid #000;
}

a:hover{
    color: #ff0000;
    text-shadow: 1px 1px 20px #ff0000;
}

#shrine,
#shrineSmaller,
#shrineNoTransform,
#shrineRight {
    display: inline-block;
    font-family: 'aurora';
    text-shadow: 1px 1px 0px #ff0000, 1px -1px 0px #ff0000, -1px -1px 0 #ff0000, -1px 1px 0px #ff0000;
    padding: 0;
    margin: 0;
    font-size: 8vw;
    margin-bottom: 2vw;
}

#shrine {
    transform: scaleY(1.6) scaleX(.9);
}

#shrineSmaller {
    transform: scaleY(1.6) scaleX(.5);
}

#shrineRight {
    transform: scaleY(1.6) scaleX(.9) translateX(115%);
}
<div class='maindiv'>
    <ul>
        <li>
            <a href=''><span id='shrine'>SHRINE</span></a>
        </li>
        <li>
            <a href=''><span id='shrineSmaller'>SHRINE</span></a>
        </li>
        <li>
            <a href=''><span id='shrineNoTransform'>SHRINE</span></a>
        </li>
        <li>
            <a href=''><span id='shrineRight'>SHRINE</span></a>
        </li>
    <ul>
<div>

Answer №2

To ensure that only the text is hoverable, consider using an SVG path.

  • Start by visiting to generate the necessary SVG path code.
  • Next, substitute
    <a href=''><span id='shrine'>SHRINE</span></a>
    with the newly generated SVG path code.
  • Lastly, apply CSS for hover effects on the path element.
.maindiv svg > g > path:hover {
    fill: red;
    stroke: red;
}
<div class='maindiv'>
  <ul>
    <li>
      <svg width="255.8" height="70" viewBox="0 0 255.8 70" xmlns="http://www.w3.org/2000/svg"><g id="svgGroup" stroke-linecap="round" fill-rule="evenodd" font-size="9pt" stroke="#000" stroke-width="0.25mm" fill="none" style="stroke:#000;stroke-width:0.25mm;fill:none"><path d="M 195.1 68.1 L 195.1 70 L 160.9 70 L 160.9 68.1 L 167.5 68.1 L 152.6 41.7 L 136.7 68.1 L 147.3 68.1 L 147.3 70 L 126.6 70 L 126.6 68.1 L 133.3 68.1 L 150.8 38.7 L 129.9 2 L 124.5 2 L 124.5 0 L 158.2 0 L 158.2 2 L 151.4 2 L 164.9 26.2 L 180 2 L 169.6 2 L 169.6 0 L 190.1 0 L 190.1 2 L 183.5 2 L 166.6 29 L 189.3 68.1 L 195.1 68.1 Z M 66.8 2.2 L 66.8 0 L 118.8 0 L 119.8 19.8 L 118 19.8 A 67.919 67.919 0 0 0 115.61 14.629 Q 112.508 8.647 109.2 5.95 A 14.803 14.803 0 0 0 104.453 3.42 Q 100.776 2.2 95.7 2.2 L 92.2 2.2 L 92.2 33.1 L 95.6 33.1 A 10.151 10.151 0 0 0 103.094 29.98 A 12.683 12.683 0 0 0 103.5 29.55 A 17.096 17.096 0 0 0 106.329 25.162 Q 107.216 23.219 107.796 20.88 A 30.604 30.604 0 0 0 108 20 L 109.5 20 L 109.5 49.6 L 107.8 49.6 A 43.088 43.088 0 0 0 106.689 45.721 Q 105.372 41.871 103.587 39.632 A 10.977 10.977 0 0 0 102.95 38.9 A 10.075 10.075 0 0 0 97.44 35.96 A 14.764 14.764 0 0 0 94.6 35.7 L 92.2 35.7 L 92.2 67.8 L 96 67.8 A 25.565 25.565 0 0 0 104.39 66.468 A 22.33 22.33 0 0 0 111.65 62.3 Q 118.1 56.8 120.5 48.2 L 122.5 48.2 L 121.7 70 L 66.8 70 L 66.8 67.8 L 72.7 67.8 L 72.7 2.2 L 66.8 2.2 Z M 1 0 L 60 0 L 61 25.1 L 59.1 25.1 Q 54.709 11.827 51.314 6.97 A 17.41 17.41 0 0 0 51.3 6.95 A 10.911 10.911 0 0 0 43.334 2.207 A 15.276 15.276 0 0 0 41.5 2.1 L 40.3 2.1 L 40.3 67.9 L 48.8 67.9 L 48.8 70 L 12.3 70 L 12.3 67.9 L 20.8 67.9 L 20.8 2.1 L 19.5 2.1 A 12.906 12.906 0 0 0 14.943 2.871 Q 11.833 4.035 9.734 6.959 A 14.19 14.19 0 0 0 9.6 7.15 A 29.46 29.46 0 0 0 7.691 10.387 Q 5.851 13.948 3.837 19.465 A 169.507 169.507 0 0 0 1.9 25.1 L 0 25.1 L 1 0 Z M 195.8 0 L 254.8 0 L 255.8 25.1 L 253.9 25.1 Q 249.509 11.827 246.114 6.97 A 17.41 17.41 0 0 0 246.1 6.95 A 10.911 10.911 0 0 0 238.134 2.207 A 15.276 15.276 0 0 0 236.3 2.1 L 235.1 2.1 L 235.1 67.9 L 243.6 67.9 L 243.6 70 L 207.1 70 L 207.1 67.9 L 215.6 67.9 L 215.6 2.1 L 214.3 2.1 A 12.906 12.906 0 0 0 209.743 2.871 Q 206.633 4.035 204.534 6.959 A 14.19 14.19 0 0 0 204.4 7.15 A 29.46 29.46 0 0 0 202.491 10.387 Q 200.651 13.948 198.637 19.465 A 169.507 169.507 0 0 0 196.7 25.1 L 194.8 25.1 L 195.8 0 Z" vector-effect="non-scaling-stroke"/></g></svg>
     </li>
   </ul>
 </div>

Answer №3

When you scale the text, it may exceed the line-height of the li container, causing overflow. By setting li{overflow:hidden}, you can observe how much of the text height is considered overflow by the li.

As an illustration, adding

li {line-height: 350%; overflow:hidden}
to your CSS could make the line-height match the text size precisely (on my browser), resulting in a more defined hover area. However, I would not recommend this as it's just to demonstrate the issue.

a:hover{
    color: #ff0000;
    text-shadow: 1px 1px 20px #ff0000;

}
#shrine{
    display: inline-block;
    font-family: 'aurora';
    text-shadow: 1px 1px 0px #ff0000, 1px -1px 0px #ff0000, -1px -1px 0 #ff0000, -1px 1px 0px #ff0000;
    transform: scaleY(1.6) scaleX(.9);
    padding: 0;
    margin: 0;
    font-size: 8vw;
    margin-bottom: 2vw;
    
}
li {line-height: 350%; overflow:hidden}
<div class='maindiv'>
            <ul>
                <li>
                    <a href=''><span id='shrine'>SHRINE</span></a>
                </li>
            <ul>
<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

Dynamic CSS overlay based on database field content without requiring user interaction

Is there a way to automatically display overlays for specific options in a database field using Bootstrap code? The options are SOLD, CONTRACT, and NO. I need different overlays to appear for SOLD and CONTRACT, while no overlay is needed for the NO option ...

How Jquery Can Be Used to Dynamically Add Extra Rows in HTML Without Submitting Data via POST Requests

When using jQuery to dynamically add extra rows to an HTML table, I encountered an issue where the fields of the extra rows were missing in the $_POST array when submitting the form. Can you please review the code and provide a solution to fix this problem ...

What is the best way to show a label and select box side by side using Angular Material?

I have been trying to keep input and label in the same line using Angular Material, but I haven't found a solution yet. Most of the available solutions are in HTML and CSS, but I specifically need a way using Angular Material. The method I tried invo ...

Guide on grabbing characters/words typed next to # or @ within a div element

Within a div element, I have enabled the contenteditable property. My goal is to capture any text input by the user after typing '#' or '@' until the spacebar key is pressed. This functionality will allow me to fetch suggestions from a ...

Firing a jQuery event at precise mouse coordinates

I am facing a unique challenge with my website design - I have implemented a semi-transparent header and footer, and now I need to capture click and hover events in order to trigger the same event on a different DOM element at the exact mouse location. Wh ...

Having trouble with displaying the logo on the navigation bar (using bootstrap and django)?

Hello, I am struggling to include a logo in my navbar and it's not being displayed. Despite researching similar queries from others, I still can't figure out why the image won't show up. I'm uncertain whether the issue lies within my co ...

Challenges with the Task List Board

I'm facing a bit of a challenge with this task. As a newcomer to JavaScript, I've set out on a quest to create a task list board where users can input tasks along with dates and times. The goal is for these entries to appear inside a photo using ...

determining the number of td elements in a row of a table located within an iframe

When I interact with a cell in a table within an iframe, I want to determine the number of cells in that row. If a cell is actually a span element, I would like to consider it as part of the cell count. The iframe may contain multiple tables without any s ...

In my JavaScript code, I am looking to increase a value within a classList template string

Hey everyone, I've encountered a challenging situation with my blackjack game. I'm creating images of the cards using .PNG names from a list in an object, and now I want to add a class to these images so that I can use the classList.contains() me ...

Define a specific Css class within an ID

Is there a way to target classes within an id in my CSS file? In my html file, I have a simple label and textbox setup: <div id="User"> <div> <div class="left"> <asp:Label ID="Label1" runat="server" Text="User ...

Uploading an image directly from the canvas

Can anyone assist me? I'm new to using canvas in HTML and I have a question - is there a method of uploading an image from canvas to the server using multipart file upload during form submission? ...

Changing the hover background color and text color of Material UI Button

I recently developed a custom Appbar component using React.js that includes 3 buttons. I'm looking to enhance the user experience by changing the color scheme when users hover over these buttons. Currently, the background color is set to #3c52b2 and t ...

Is the utilization of javascript functions intertwined with the specific version of bootstrap being used?

I wrote a function that breaks down each letter in a paragraph to create a typing effect. However, after taking a break for a few days, I noticed that the effect was now the opposite – the letters were disappearing. To solve this, I decided to animate ...

Trouble encountered when attempting to override styles in Material UI's TableRow

I am attempting to customize Material UI's default styles in order to create a margin between each TableRow. Despite my efforts, it appears that the override is not being reflected in the user interface. ...

Developing a Chessboard Using JavaScript

Seeking help with a Javascript chessboard project. I have successfully created the board itself, but facing difficulty assigning appropriate classes (black or white) to each square. Managed to assign classes for the first row, struggling with the remainin ...

Uploader and viewer tool for HTML5 documents

My website is currently built using PHP and allows users to add and view documents. The current upload process is basic, requiring users to manually input information and then view the document with minimal formatting on a webpage. I am looking to upgrade ...

AngularJS allows for the submittal button to be adjusted accordingly when changes are made in

Currently, I am working on an app that involves an edit form. Initially, the save button is disabled, and it becomes enabled once text is inputted into the form (accomplished using $dirty). The problem arises when the form is "saved" (meaning the informat ...

Does the Fileupload jQuery event function differently when uploading from a mobile device compared to a desktop computer?

I am encountering an issue with this jQuery function. It works perfectly when I upload a file from my desktop computer, but it doesn't seem to fire when I try uploading a file from my mobile phone. Can anyone identify what might be causing this proble ...

Guide to centering a Material UI Table on a webpage

Is it possible to center the <Table> within a fixed width <div>, and have a scrollbar appear when the browser is resized, while maintaining the fixed width of the <Table>? Thanks in advance. This is my current setup: <div> ...

Determining the offsetWidth and scrollWidth for option elements within a select field containing the multiple attribute on Internet Explorer 11

My select input element has multiple attributes and a fixed width set. Unfortunately, due to the fixed width, the overflowing content in the x-direction is not visible. To address this issue, I have created a JavaScript function that uses the title attribu ...