Tips to maintain the integrity of "text-decoration: underline" when adding positioning to the child <span> element

Explaining the rationale behind it, I have opted for relative positioning on <span> within <a> to make a slight adjustment in the text position enclosed by <span> (raising it 2px higher than its default placement). However, this causes the text-decoration: underline; to break and the text below my <span> also shifts 2px higher. You can view an example on this fiddle: http://jsfiddle.net/8qL934xv/

I am seeking a way to ensure that the underline of the <a> extends beneath the <span>, remaining intact and ideally utilizing only HTML/CSS.

The Issue's Origin:

In constructing a bilingual website, English terms sometimes persist in secondary language content. To address this, I encase these terms with <span lang="en"> and employ a specific font-family using the following method:

* [lang="en"]
{
    font-family: 'Ropa Sans', helvetica;
}

However, the font-family utilized for secondary language headers and 'Ropa Sans' do not harmonize well together, appearing disjointed. This led me to implement relative positioning on my <span> elements. For instance:

h1 span {
   position: relative;
   top: -2px;
}

This remedy functioned effectively until the disruption it caused to underlined links came into realization. While I could refrain from applying text decorations to such links, I prefer to ascertain if there exists a straightforward CSS solution that has eluded me.

Answer №1

It may seem impossible, but there is a creative workaround:

a {
    display: block;
    border-bottom: 1px solid transparent;
    text-decoration: none;
}

a:hover {
    text-decoration: none;
    border-bottom: 1px solid blue;
    display: inline-block;
}

Surprisingly, this solution actually works!

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

What is the best way to ensure uniform height and width of images within a thumbnail in Bootstrap?

I am struggling to maintain consistent image sizes within my Bootstrap gallery. How can I ensure all images are uniform in both height and width? You can view the code on jsfiddle- here. Apologies for the lack of image visibility as I'm currently wor ...

Tips for integrating Iftop into Django framework

I am facing an issue with integrating iftop into Django. Even though it works fine on the command line, I do not get any output when trying to incorporate it into Django. Strangely, there are no errors displayed either. views.py def packets(request, temp ...

Guide on attaching an onclick event to a button created with a string in Next.js?

<div onClick={(event) => this.addToCart(event)}> <ReactMarkdownWithHtml children={this.props.customButton} allowDangerousHtml /> </div> In my current situation, I am facing an issue with the code above. The button is being rendered ...

What is the best way to include a specific stylesheet for Blackberry Curve devices based on certain conditions

Is there a method to include a custom style-sheet specifically for the 'Blackberry curve 2007'? Or perhaps implement a redirect that can identify this device and direct them to a different .html page? I'm looking to create a simplified versi ...

tips on adjusting margins or paddings in option select

How can I use the margin or padding options for my select dropdown? I tried using &nbsp; <select class="select"> <option value="100"></option> <option value="250">$593</option> ...

Dividing the content: A two-column CSS layout

I am currently redesigning a layout that is using tables for a two-column design but I have encountered some issues. <div id="frame"> <div id="leftcol"> <div id="1">blah</div> </div> <div id="leftcol"> <div ...

Type in the input box using JavaScript within an HTML document

With a website containing a text box next to several buttons, the goal is for users to click on a button and have specific text populate the text box before submitting the form. An example of this setup in code form: <form action="send.php" method="pos ...

Utilizing XSLT 1.0 to encase text and elements within paragraphs

After successfully solving a problem using XSLT 2.0, I now face the challenge of achieving the same outcome in XSLT 1.0 due to the requirement of using a processor compatible with XSLT 1.0. My task involves handling various types of XHTML and XML, each wi ...

Using CSS units such as vw, vh, or percentage to specify height is not possible

In my Ionic app, I am adjusting the width and height of a div based on the viewport dimensions. This setup functions correctly on the browser and Android 4.4 devices. However, it does not work as expected on Android 4.2 (the height is constrained to the te ...

Discovering the technique to display data in PHP only from the database that is specific to the authenticated user

When creating a to-do list, I want the user (not admin) to only see tasks assigned to them. This should be indicated under the assignee column with their name. https://i.stack.imgur.com/WP5C8.png However, currently the user named Lala can see not only th ...

Creating a unique Bootstrap Navbar design with vertically staggered elements

https://codepen.io/bencasalino/pen/NWPLLYQ <div class="collapse navbar-collapse" id="navbarSupportedContent"> <ul class="navbar-nav ml-auto nav-flex-icons"> <li class="nav-item"> <a class="nav-link p-0 color-white" h ...

The vertical scrollbar is shifting the content to the side, causing a horizontal scrollbar to

Currently, I am working on a web page located at this link: My main focus at the moment is positioning an image in such a way that it appears to be coming out of the right side of the screen. Progress so far is looking promising. However, I have noticed ...

In Angular/CSS, setting the height of all parent elements to 100% does not necessarily ensure that the child element

I have a page where I've set all parent elements to a height of 100%, including the root of the app. However, when I reach a component in the body, it seems to be ignoring the height settings. Even though my dev tools show that the direct parent of ". ...

Error: Attempted to export 'e', however it was not defined in the module (located at vite.js?v=d59cec13:236:3) - occurring in the three.js/vite combination

After dabbling in javascript, I decided to explore three.js and found it quite intriguing. However, after hours of setting everything up, I encountered a roadblock. When I attempted to create geometry and render it, the code stopped working. Upon investiga ...

Applying a CSS Class to EditorFor in an ASPX C# view engine is not supported

I have created a user interface using basic HTML attributes and the Bootstrap framework. I am now looking to integrate Html.EditorFor() in place of <input type="text" class="form-control" />. This is how I attempted to add it: <%= Html.EditorFo ...

What is the best way to initially hide a div using slide toggle and then reveal it upon clicking?

Is there a way to initially hide the div tag and then animate it in a slide toggle effect? I attempted using display:none on my '.accordion_box' followed by show() in slideToggle, but this results in adding the CSS property display: block. My goa ...

What is the best way to add the SO-style <kbd> effect to my presentation made with HTML?

I'm currently utilizing reveal.js to construct an HTML-based presentation. My goal is to incorporate keyboard symbols like the ones found on SO and Github using the <kbd>SPACE</kbd> syntax, resulting in this glyph: SPACE. Despite attempti ...

Adding a sibling inline can be accomplished by simply using the "+"

$("#sibling").prepend("#sibling2") <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="sibling">First sibling</div> <div>Another component</div> <div id="sibling2">Seco ...

What is the process of incorporating a select form within a component?

I am currently working on creating a user registration form. Once the form is filled out and the submit button is clicked, I need the values from the form to be displayed in a specific <p id="data></p> component. Can anyone assist me with this ...

"Despite encountering an error, the jQuery AJAX request remains active and continues to

Check out this code snippet I created. early_face_detect=$.ajax({ type: "POST", url: "earlydetect.py", timeout: 15000, success: function(respond) { var s=grab_early_details(respond); }, error: function(xmlhttprequest, textstatus, message) ...