Is there a way to implement row striping for unordered lists using anchors in HTML?

I'm currently working on creating a layout with draggable rows.

When trying to style the table (located on the right and bordered in green), everything looks great. However, once I add anchor tags to transform these into large draggable cells that will be moved around, the striping disappears and they end up with a gray background (reflecting the left table with a yellow border).

Here is my HTML/CSS code:

<html>
  <head>
  <style>
    #categorizer { padding: 20px; }
    #left  {
      color: green;
      background-color: yellow;
      display: inline;
      border: solid;
      border-color: pink, 10px
      padding: 20px;
      margin: 20px;
    }   
    #right {
      color: yellow;
      background-color: green;
      display: inline;
      border: solid;
      border-color: pink, 10px
      padding: 20px;
      margin: 20px;
    }   
    ul  
    {   
      padding: 30px;
      margin: 30px;
      float:left;
      list-style:none;
    }   
    li {
    padding: 20px;
    }   
    li:nth-child(even) { background-color: #000 }
    li:nth-child(odd) { background-color: #666 }
  </style>
  </head>
  <body>
    <div id="categorizer">
      <ul id="left">
        <a href="#"><li>1</li></a>
        <a href="#"><li>2</li></a>
        <a href="#"><li>3</li></a>
        <a href="#"><li>4</li></a>
      </ul>
      <ul id="right">
        <li>a</li>
        <li>b</li>
        <li>c</li>
        <li>d</li>
        <li>e</li>
      </ul>
    </div>
  </body>
</html>

I'm looking for a way to create big draggable cells where the 'hand' cursor appears over the entire cell rather than just the text inside. It's crucial to maintain the table striping even if there are more than 20 rows involved, as this dynamic component is vital to the design.

Answer №1

relocate all <a> elements into your <li> tags and apply the style cursor:move to the li elements to give them a hand cursor.

Check out the jsLint demo here

Here is the HTML code:

<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>

And this is the CSS code:

li {
    cursor:move;
}

If you don't want the pointers to show on the a tags, consider changing li{ to li, li > a in your CSS.

Answer №2

If you want to include an <a> element in a list, it needs to be nested within a <li> tag inside the <ul> or <ol>. Make sure to adjust the structure of your first list (#left) accordingly and apply the style display: block; to the <a> elements.

<ul id="left">
    <li><a href="#">1</a></li>
    <li><a href="#">2</a></li>
    <li><a href="#">3</a></li>
    <li><a href="#">4</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

ways to trigger an event and pass it to a JavaScript function using a hyperlink

This specific "href="javascript:stop(this);" pattern allows the hyperlink object to be passed to the stop function. However, I also need to pass the invoked event to that function. How can I achieve this? Since my records are loaded through AJAX, I am unab ...

Design a dynamic rectangular division using CSS and Bootstrap 4 that adapts to different screen sizes

I am encountering difficulties attempting to replicate a full-width rectangle div on a website, particularly with issues related to responsiveness and mobility. Here is an example of the design I am trying to recreate. And here's what I've acco ...

Adjust grid column sizes automatically when a smaller number is declared - tailwind

I am working with the tailwind grid system and have specified 6 columns for each row. However, if the number of elements is less than 6, I would like it to resize them to 3. <div className="grid grid-cols-2 md:grid-cols-4 lg:grid-cols-6 grid-flow-r ...

Prevent the transfer of data from webpage

Is there a way to prevent users from copying content on a web page? I want to ensure that no text can be selected by the user. I am currently working on asp.net and would appreciate any creative ideas or solutions. ...

What is the method to submit to a protected service from an unsecured page without relying on a complete domain name?

I am interested in creating a form on a non-secure page without the need for a fully qualified domain name. http://www.example.com/page This form should post to a secure service on the same domain. https://www.example.com/service I currently have a wor ...

Update the button's onclick event

I have a unique challenge in HTML - I need to create a button that toggles text visibility with a single click. The button's 'onclick' attribute is essential as it directs to a JavaScript function, but I also want the button text to change d ...

Tips for deleting directory path from a file name

Similar Question: How to extract file name from full path using PHP? echo '<td width="11%" class="imagetd">'. ( ( empty ($arrImageFile[$key]) ) ? "&nbsp;" : htmlspecialchars( is_array( $arrImageFile[$key] ) ? implode(",", $arrImag ...

Shadow border added to each div creates a unique navigation tab for easy access

#container { position: fixed; height: 100%; left: 0px; right: 0px; top: 0px; width: 10%; background-color: blue; } #container>div {} <html> <div id="container"> <div>up</div> <div>down</div> <d ...

What is the best way to insert a chart into a div using *ngIf in Angular?

I just started using chart.js and successfully created the desired chart. However, when attempting to implement two tab buttons - one for displaying tables and the other for showing the chart - using *ngIf command, I encountered an error: Chart.js:9369 F ...

Ways to incorporate horizontal scrolling into a flex container within a Bootstrap navigation bar

I am encountering an issue with my Bootstrap navigation menu that uses a flex container (). The goal is to have horizontal scrolling for the menu items when they surpass the width of the container. I have implemented the following CSS style on the containe ...

Troubleshooting problem with ngb carousel timing interval

I am currently developing a web app for selecting maps in Escape from Tarkov. To enhance the visual appeal of the app, I decided to incorporate an ngb-carousel feature for a smooth animation effect. However, I have encountered a problem where the slides ar ...

Issues regarding the CSS navigation bar

I'm currently working on creating a navigation bar using HTML and CSS. However, I'm facing an issue where the nav-bar doesn't extend to the full width of the page as intended. I've attempted adjusting the padding-left: 0px and padding-r ...

"Troubleshooting problems with jQuery click function during real-time search execution

In my code, I have an empty result div that dynamically fills up with item elements as search queries are entered (using jQuery ajax). If I use the following code: $(".result").click(function(){ alrert("click on whole result class captured") }); I r ...

Adjusting the height of an element in AngularJS based on its width dynamically

I am working on a table that is generated using ng-repeat, and I want to ensure that each td in the tbody is square. Since all the tds have an equal width, I only need to adjust the first one. However, the size of the table and td will change when the wind ...

I'm encountering issues with adding a div element using Jquery

I've been attempting to insert a div using jQuery, following the code example below. Unfortunately, it's not working as expected. jQuery: $('<div />', { $('<img />', { "src": "/Pages/Images/calendar.png").add ...

Avoid incorporating unicode characters in Angular 4

How can I prevent users from using unicode characters in a text field in my front-end developed with Angular 4 framework? For example: ½ -> U+00BD ('onehalf') ...

Print out two forms separately using HTML5

I'm currently tackling a project that condenses all content onto one convenient page, housing two forms. Despite my efforts, I have yet to find a successful solution. My goal is to print the Sales person form first, followed by the Customers section. ...

AJAX form submission failed due to empty input fields

The form I have is submitted via AJAX and functions perfectly, except for a few inputs that always remain empty. NOTE: This snippet includes only the specific inputs of my HTML as posting the entire code would be too extensive. HTML <!-- This input s ...

The AJAX chat interface is failing to show messages, even after refreshing the page

My JavaScript file is not displaying messages from the PHP file even though they are successfully sent. The messages are present in the PHP file and database, so I'm wondering if there's a mistake in my code. Can anyone suggest an alternative app ...

The size of divs adjust based on the size of the browser window

Within a container div, I have multiple nested divs arranged side by side. The container is 1100px wide and centered in the browser window. In the example image below, three inside divs are illustrated, but there could be more (divD, divE, etc). https://i ...