using an id= instead of a href=

I have an organized list with links, but when I add a link that requires a specific ID, the CSS is not applied to it.

Since the CSS only targets li a:link{}, how can I make it recognize the specified ID too?

The ID 'swishLink' is used in multiple places on the site, so altering its attributes isn't possible.

I've attempted using the <div id=""> option, but that would mean creating a CSS rule for each list item.

li:first-child a:link{
  text-decoration: none;
  border-top-right-radius: 2em;
  border-top-left-radius: 2em;
}
li{
  list-style-type: none;
  text-decoration: none;
  border: 2px solid white
}
li a:link{
  text-decoration: none;
  list-style-type: none;
  width: 200px;
  height:auto;
  padding: 20px;
  display: list-item;
  background: #eefbe7;
  font-family: Arial Rounded MT Bold,Helvetica Rounded,Arial,sans-serif;
  text-align: center;
  color: green;
}
li a:visited{
  color: green;
}
li a:active{
  color:purple;
}
li:last-child a:link{
  border-bottom-right-radius: 2em;
  border-bottom-left-radius: 2em;
}

 li a:hover {
  text-decoration: none;
  background: green;
  color: white;
}
 <ul>
        <li>
        <a href="./"> One </a>
        </li>
        <li>
        <a id='swishyLink'> Two </a>
        </li>

        <li>
        <a href="./"> Three </a>
        </li>
        <li>
        <a href="./">  Four </a>
        </li>
        <li>
        <a href="./">  five </a>
        </li>
    </ul>

Answer №1

To ensure that your CSS styling is also applied to <a> tags that are not hyperlinks, avoid specifying that it should only target links explicitly.

Instead of using :link, consider a more general approach.

Answer №2

a:link seems to be causing issues. Instead, try using li a

li:first-child a{
  text-decoration: none;
  border-top-right-radius: 2em;
  border-top-left-radius: 2em;
}
li{
  list-style-type: none;
  text-decoration: none;
  border: 2px solid white
}
li a{
  text-decoration: none;
  list-style-type: none;
  width: 200px;
  height:auto;
  padding: 20px;
  display: list-item;
  background: #eefbe7;
  font-family: Arial Rounded MT Bold,Helvetica Rounded,Arial,sans-serif;
  text-align: center;
  color: green;
}
li a:visited{
  color: green;
}
li a:active{
  color:purple;
}
li:last-child a{
  border-bottom-right-radius: 2em;
  border-bottom-left-radius: 2em;
}
/*
 Change the link color on hover */

 li a:hover {
  text-decoration: none;
  background: green;
  color: white;
}
 <ul>
        <li>
        <a href="./"> One </a>
        </li>
        <li>
        <a id='swishyLink'> Two </a>
        </li>

        <li>
        <a href="./"> Three </a>
        </li>
        <li>
        <a href="./">  Four </a>
        </li>
        <li>
        <a href="./">  Five </a>
        </li>
    </ul>

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 steps can I take to stop search engines from crawling and indexing one specific page on my website?

I'm looking for a way to prevent search engines from indexing my imprint page. Is there a method to achieve this? ...

What steps do I need to take to retrieve data in a JSON array based on its

Hello, I could really use your assistance with a problem I'm having. Here is the scenario: I have a JSON array that looks like this: "category" : [ { id: 1, product: [{id : product_1, type : ball}] }, { id : 2, product :[{id : prod ...

Struggling to align the footer of your webpage and ensure it adjusts proportionally with the window size?

After trying several codes that have worked before, I ran into a problem when attempting to place two div side by side for the footer. No matter what code I tried, I couldn't get it centered and responsive to the user window ratio. Even after consulti ...

Creating a mockup for a website design project in my class, utilizing HTML and CSS. Encountering issues with the CSS not displaying correctly, unsure of the root cause of the problem

Check out this wireframe design I created: https://i.stack.imgur.com/Ro3dl.png I'm working on translating this into HTML and CSS so that I can further develop it. The HTML Code: <!doctype html> <html> <head> <title> Trinit ...

Having trouble with the filtering feature in Material UI Datagrid

I'm currently using Material UI Data Grid to display a table on my website. The grid has an additional filter for each column, but when I click on the filter, it hides behind my Bootstrap Modal. Is there a way to bring it to the front? https://i.stac ...

Detecting click events in D3 for multiple SVG elements within a single webpage

My webpage includes two SVG images inserted using D3.js. I am able to add click events to the SVGs that are directly appended to the body. However, I have encountered an issue with another "floating" div positioned above the first SVG, where I append a dif ...

Guide to creating a distortion-free layout with Bootstrap 4

I am in need of creating a design layout using Bootstrap 4 with the following specifications: https://i.sstatic.net/JeUHh.png Here is my code : <div class="row"> <div class="col-md-7"> A </div> <div class="col-md-5"> <div ...

choose multiple elements from an array simultaneously

Looking for help with a basic Array question and seeking the most effective solution. The scenario involves having an array: var pathArr = [element1, element2, element3, element4, element5, element6] If I want to select multiple elements from this array ...

Implementing a redirect and setting a background image dynamically in ASP.NET using code-behind

I have a section in my PHP template with a onclick event handler. My goal is to redirect users to another page when they click on this section. Here's what I've attempted: HTML: <section id="header" onclick="window.location.href='Anoth ...

Attempting to display a larger version of an image sourced from miniature versions fetched with the assistance of PHP and

I'm dealing with the challenge of displaying thumbnails fetched from a database. PHP is successfully interacting with and presenting my thumbnails. I'm currently faced with the issue of passing the id from the database to the imageID in my JavaSc ...

Having trouble setting a background image for a specific DIV element in HTML

I am in the process of updating my webpage, and need some assistance implementing a small background image. Here is what I have done so far: https://i.sstatic.net/nTxtD.png Below is the marked section where I am trying to add the background image: https ...

JavaScript Hangman Game Malfunctioning

I am in the process of creating a basic hangman game to be played on a web browser. Whenever the user clicks a button, it triggers a function called pickWord(): <button onclick="pickWord()" id="restart">Choose A Word</button> This functi ...

Utilizing Python to manipulate the 'select' tag in HTML

Currently, I am attempting to retrieve events from an HTML page located at In my efforts to choose different areas using python script, I encountered a challenge with the following snippet of HTML code: <select data-ng-options="key as value.name for ( ...

Is it considered a bad practice to use the record ID on a <tr> element for an editable row within a table?

I am in the process of using jQuery to create a feature that allows users to edit a HTML table containing category names. Currently, I have successfully populated my table using PHP/MySQL. While researching on jQuery - Edit a table row inline, I came acr ...

Is it possible to alter preact-material-components to switch to mdc-theme--dark mode, thereby changing the CSS style of all descendant components?

I recently created a preact-cli app and added the following code in Header.js: document.body.classList.add('mdc-theme--dark'); However, when a user tries to switch from the light theme to the dark theme, only the background of the app changes. ...

Managing Margins and Padding in Multiple Lines of Divs in CSS

Trying to understand the spacing issues that arise when tiling a series of divs within a parent div. Here is a link to the fiddle for reference: http://jsfiddle.net/SNSvU/4/. Below is the code snippet: <div id="prioritiesWrapper"> <div class="p ...

What is the standard size for PHP files, or the suggested maximum limit?

I created a tool at where users can upload a .php file with comments and spaces, and it will compress it for a smaller file size. It functions similar to but is web-based and provides instant results. Once you click upload, you receive a prompt to downl ...

Tips for positioning the border properly within a scrollable table

My table has a sticky header with a fixed height, and in order to see more rows in the table, we have to scroll through them. The table design includes borders. The problem arises when there are more rows, as the border moves with the scroll. Initially, ...

How about "Can I position two divs on the right side of the page

After browsing through some StackOverflow threads and other sources, I'm still struggling to figure out how to float two divs to the right while aligning them vertically (with the "sign in" div on top). Based on my findings, here are the key points: ...

The issue lies in the alignment of the navbar at the top

After retrieving this script: <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"> <nav class="navbar bg-light navbar-expand-sm justify-content-center"> <a class="navbar-brand" ...