style of placing a space between objects

Is there a way to create space between the border (underline hover effect) and have the color of the line be red?

a {
  text-decoration: none
}

li {
  display: inline;
}

li:hover {
  text-decoration: underline;
}
<li><a href="">
  abc
</a></li>
<li><a href="">
  def
</a></li>
<li><a href="">
  ggg
</a></li>
<li><a href="">
  hello
</a></li>

Answer №1

Consider using border-bottom and padding as an alternative approach

a {
  text-decoration: none
}
li {
  display: inline-block;
}
li:hover {
  border-bottom: 1px solid red;
  padding-bottom: 10px;
}
<li><a href="">
  abc
</a>
</li>
<li><a href="">
  def
</a>
</li>
<li><a href="">
  ggg
</a>
</li>
<li><a href="">
  hello
</a>
</li>

Answer №2

To achieve a customized line effect instead of the default line created by text-decoration, you can use border-bottom. This allows you to change the colors, line size, and padding for spacing between elements.

a {
  text-decoration: none
}

li {
  display: inline;
}

li:hover {
  border-bottom:1px solid blue;
  padding-bottom:8px;
}
<li><a href="">
  apple
</a></li>
<li><a href="">
  banana
</a></li>
<li><a href="">
  cherry
</a></li>
<li><a href="">
  date
</a></li>

Answer №3

It seems that the underline in the white space is caused by the closing </a> tag being on the next line, leading HTML browsers to collapse multiple spaces into one.

One solution would be to close your end tags immediately after the text to avoid this issue.

Additionally, make sure to update your last CSS code to li:hover a

a {
  text-decoration: none
}

li {
  display: inline;
}

li:hover a {
  text-decoration: underline;
}
<li><a href="">
  abc</a>
</li>
<li><a href="">
  def</a>
</li>
<li><a href="">
  ggg</a>
</li>
<li><a href="">
  hello</a>
</li>

Answer №4

    Styling links and list items using CSS:
    a {
    text-decoration:none;
    display:block;
      position:relative;
      padding-bottom:20px;
    }

    li{
    display:inline-block;
      
    }
    li:hover a:after {
      content:"";
      position:absolute;
      height:1px;
      width:100%;
      left:0;
      bottom:0;
      background:red;
      
    }
<li><a href="">
      abc
    </a>
    </li>
    <li><a href="">
      def
    </a>
    </li>
    <li><a href="">
      ggg
    </a>
    </li>
    <li><a href="">
      hello
    </a>
    </li>

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

Creating an MPG4 Video from a Three.js Scene: What Are the Steps?

I am working with a three.js scene that includes numerous animated objects. I am looking to export this animation as an mpg4 video. Here are my questions: What is the best method for exporting a scene to create an mpg4 video? Is it recommended to perfo ...

Identify all the CHECKBOX elements that are visible and not concealed

On my page, I have various checkboxes - some with hidden=true and others with hidden=false attributes. Despite trying to use a selector or jQuery to locate checkboxes with the hidden property, I am still facing some challenges. My goal is to differentiate ...

Constructing a comprehensive inventory is a skill that requires strategy

Can someone advise on the best way to create a list structure with one parent category and two subcategories, each containing three items? Would it be ideal to use a combination of span and two uls, or perhaps a mix of span, anchor tags, and ul elements? ...

Achieving Dynamic Alignment in CSS: How to Responsively Align a Div to the Width of its Parent Using Padding and Margins

My dilemma could not be clearer - I am struggling to properly align 4 divs within a width of 1150px (the maximum width of the content div). When resizing the screen, I want them to adjust accordingly: 4 in a row when possible, then 3 in the center, and so ...

Ensure that the content is perfectly aligned with the rest of the page for a visually pleasing

Seeking guidance on how to symmetrically center an image gallery with a list background, regardless of the browser's size. Any tips for aligning content perfectly? I attempted using a wrapper around the gallery and list with a fixed width, but it onl ...

Having trouble getting XSLT to work properly with the XML file

My XSL file doesn't appear to be functioning properly with my XML data. Despite the simplicity of my code, I am unable to identify the issue. Upon linking to the XSL spreadsheet and opening the document, my XML seems to transform into plain raw Data. ...

Refresh the content of an iframe (local HTML) by clicking on buttons

When a user clicks on a button, I am loading an HTML file into a DIV (iframe). The issue arises when the user clicks another button and wants to reload the iframe with a different HTML file. This is the current code snippet: <script type="text/javasc ...

Is it possible for the scroll event to be triggered while scrolling only when a div element is used?

While utilizing window.onscroll to track scroll events during scrolling, I noticed that in certain Android devices the scroll event is only triggered after the scroll has completed. However, when monitoring scroll events within a specific div element, it ...

Can we ensure there is consistently an even number of columns when using auto-fill?

Hello, I am just starting to explore CSS grid. Take a look at the example below: .platform { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); grid-gap: 20px; } .item { width:100%; background-color:#aaa; padding:10 ...

Is left padding appearing mysteriously (supernatural CSS phenomenon)?

While using the Firebug inspector tool, if you hover over #jimgMenu ul, you may notice that it has left padding without any corresponding CSS rule: Where is this mysterious left padding coming from? Why is the origin not visible? EDIT: If you navigate t ...

Issue with Android date input field not resetting the value

When testing in Android Tablet (version 4.1.2), I encountered a strange issue with an input date field that looks like this: <input type="date" value="2013-06-10"/>. Upon clicking on the field and trying to set a new date, instead of replacing the o ...

"Troubleshooting issues with Material Design components in AngularJS: Why is <md-select> not functioning correctly

I'm attempting to implement the <md-select> tag, but I can't seem to achieve the same result as shown here. This is the code I've written: <div layout="column" layout-align="center center" style="margin: 0px 10px 0px 5px;"> & ...

How can I make my Grid items in React and Material-UI occupy the entire horizontal space without wrapping to the next row?

I am currently utilizing Material-UI within a React 16.10 project. My goal is to create a table where the left column consists of an icon, while the right column displays a label and address stacked on top of each other. I want the items in the right colum ...

Dreamweaver constantly combines an external CSS file with locally stored CSS when running on a local server

When I used Dreamweaver CS5, XAMPP Server, and PHP files in the past, I encountered an issue. The websites within my htdocs folder seemed to be pulling a specific website's CSS file. In 'Live View,' I could see all external .css and .js file ...

What could be causing a .ts file to not play correctly?

I need help downloading a video from the following URL: I have successfully downloaded the file, but none of my video players can play it. Could it be encrypted? Is there a solution to make it work? Appreciate any help! ...

A fading transparency box on the border

Looking for a box with varying opacity from left to right (See image for reference - the red marked box has decreasing opacity from right to left). Here is my attempt: .waterMark { background-color: #FFFFFF; float: right; opacity: 0.6; position: ...

Determining User Consent: A Straightforward Guide to Identifying Previously Accepted Cookie Consent

I've been tasked with adding a cookie to a website. The site only tracks the number of visits, so there is no user-specific data available for cookie assignment or acknowledgment tracking. Is it possible to show the cookie notification only to users ...

Showing JSX/HTML content depending on the props received

Can you identify the name of this type of expression and do you know in what scenarios it should be applied? {props.type === "big" && <h2>{props.title}</h2>} ...

Challenges with HTML and JavaScript

Struggling to get this code to work properly with Node.js. const express = require('express') const app = express() app.use(express.static('public')) //includes content of public folder app.get('/', function (req, res){ ...

JavaScript tip: Improve the way you highlight the current navigation page while scrolling by finding alternative methods to using "scrollY > x"

Currently, my webpage layout is divided into 4 sections - HOME, ABOUT, SKILLS, and CONTACT. Below is the JavaScript code I am using to highlight a specific section on the navigation bar based on the scroll position: let home = document.querySelector(" ...