What could be causing the child element in CSS to be larger than its parent element when sorting?

I am working with a UL that contains multiple LI's. Within each li, there is a table.

Using mootools, I have made my li elements draggable/sortable. However, I only want a small portion of the li element (and its child table) to be draggable.

I attempted to use 'relative and absolute' positioning to solve this issue, but the hover effect of the li persists. When hovering over the (child) table, the (parent) li still displays its hover effect, which is not desired.

<ul>
  <li>
    <table cellpadding="0" cellspacing="0">
      <tr>
        <td>...</td>
        <td><a href="foobar.html">foobar</a></td>
        <td>...</td>
        <td>...</td>
        <td>...</td>
      </tr>
    </table>
  </li>
</ul>

<style>
  ul {
    list-style: none;
    margin: 0;
    padding: 0;
    float: left;
  }
  
  li {
    background-color: red;
    width: 25px;
    height: 25px;
    float: left;
    clear: both;
  }
  
  li:hover {
    background-color: green;
    cursor: move;
  }
  
  li table {
    border: 1px solid #eee;
    width: 850px;
    position: absolute;
  }
</style>

When implementing this code, you'll notice that the actual li size is 25x25. However, when hovering over the table, the li turns green (only that 25x25 part).

My goal is for only that specific 25x25 area to respond to the hover event!

Answer №1

Your markup is causing the issue. Placing the table as a sibling of the list item (li) means that any styling or effects applied to the li will also affect everything within it, which explains why hovering over the table turns the li green.

Answer №2

When the mouse hovers over the table inside a li element, it triggers the :hover pseudo-class for the parent li.

To solve this issue, you can add a specific class to all li elements containing tables:

<li class="withTable">
    <table cellpadding="0" cellspacing="0">
        <tr>
            <td>...</td>
            <td><a href="foo.html">foo</a></td>
            <td>...</td>
            <td>...</td>
            <td>...</td>
        </tr>
    </table>
</li>

Then, add this CSS rule:

li.withTable:hover {
    background-color:transparent;
    cursor:default;
}

You can customize the background color as needed:

li.withTable:hover {
    background-color:blue;
    cursor:default;
}

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

rearrange elements in the HTML code

I need to display 3 tables, each with a width of 300px, on a webpage. These tables can be collapsed or visible. My goal is to arrange them so that if only one table is visible, it appears in the center of the page (centrally aligned). Additionally, the tab ...

Creating a responsive bootstrap card-tall for mobile devices

I'm currently using Bootstrap cards to create a gallery-like display of images. To style the images, I'm also utilizing the card-tall class. Since these images are posters, they naturally occupy a lot of space. Here's how it appears on the ...

Tips for aligning inputs vertically and stretching them horizontally with bootstrap flex only

For a practice exercise, I want to achieve vertical left alignment and horizontal stretching of input fields using only Bootstrap Flex (or CSS3 flexbox), without relying on Bootstrap Grid or CSS3 grid layout. Here is the code snippet (also available on co ...

Challenges with transitions and transformations across different web browsers

I've encountered some difficulties while working on my new website. The mobile navigation menu is supposed to appear when the browser window is below 940px wide. It functions properly on Chrome and other webkit browsers, but in Firefox and IE, the tr ...

Animate css style using setTimeout: "in the blink of a moment"

I need help creating a bar (#innerBar) that decreases in width by 1% every second. Unfortunately, the loop I implemented is not working as expected. The bar goes from 100% to 0% almost instantaneously. function timer(){ var timer; for(i=100;i&g ...

Utilizing CSS Media Queries to Activate DOM Alterations

Utilizing CSS media queries, I am able to display different layouts of my website based on the width of the screen. This involves showing and hiding specific elements accordingly. However, in addition to this, I also need to rearrange elements within the ...

Guide to modifying WordPress version 4.5 with HTML pages

https://i.sstatic.net/5zA5S.png I am encountering issues with my Wordpress website. I have installed it on Softcald in cPanel and now I want to edit my Wordpress using HTML. However, I am having trouble finding the editing option. My Wordpress version is ...

Vue.js: click event does not trigger transform animation

I am facing a challenge with rotating an arrow icon within a dropdown menu. Despite my efforts, the rotation does not synchronize with the appearance of the dropdown menu. Here is the Vue component code snippet: <nav> <section class= ...

Arranging Icons to Coordinate with Text in a Line

I am working on a layout that features 7 icons with short links and descriptions underneath each. My goal is to have 4 icons displayed horizontally in one row, followed by 3 icons in the second row. While I have managed to set up the text and links as desi ...

Tips for creating a responsive input field within a navbar

Can anyone assist me with setting the input field width in my navbar to adjust to the remaining width of the navbar and be responsive to different device sizes? I need the input field to dynamically change its width based on the screen size. Any help would ...

Customizing vertical padding in Bootstrap 4 Tables: Adjusting the spacing between rows

<div class="table-wrapper"> TABLE STUFF </div> I'm using Bootstrap to create a table with no borders, but I'm finding that the rows have too much vertical padding. How can I adjust the padding to create a more compact design? ...

CSS-loader imported styles failing to function properly

Constructing a React 16.4.0 application with Bootstrap 4.1.1. My approach involves using css-loader alongside webpack to generate personalized stylesheets for each component within my app. Despite my efforts, I am facing the issue where my custom styles ...

After each animation in the sequence is completed, CSS3 looping occurs

I have currently set up a sequence of 5 frames, where each frame consists of 3 animations that gradually fade into the next frame over time. My challenge is figuring out how to loop the animation after completing the last sequence (in this case, #frame2). ...

Issues with CSS rendering in the Chrome browser are causing display problems

After successfully creating an iFrames page tab on Facebook that looks great in Firefox and Internet Explorer, I encountered an issue with the div positioning in Chrome. You can view the page here: Oddly enough, this is the only page experiencing problems ...

What is the best way to execute a function based on the width of the screen?

Two functions need to be called based on the screen width. Here is one attempt: var winWidth = $(window).width(); var sections = function() { $('.image').each(function(){ var $this = $(this), x = $this.find('img'). ...

Modify the currently selected color in a multi-select menu by editing the option tag

Why does the selection option value turn blue, but then become a faint grey when clicking on anything else on the page? Can these colors be changed, especially the faint grey for better accessibility? I've experimented with various CSS approaches, bu ...

Creating a unit by merging variables in SASS

Is there a way to merge two variables in SASS to create a single unit together? The current configuration is outlined below: $font-size: 16; $font-unit: px; $base-font-size: {$font-size}{$font-unit} !default; @if unit($base-font-size) != 'px' ...

Exploring the functionality of the PageIndicator for Wearable Technology

Exploring the Page Indicator within a Tizen Wearable Application for Gear S3 Frontier has been an interesting journey. Despite successful implementation with text content, adding controls to each section or incorporating background images has proven challe ...

Is it possible to dynamically add attributes to XHTML tags using Javascript? For instance, adding a title attribute to an anchor tag like <a title="text">

Is it possible to modify XHTML source code through JavaScript? Can attributes be added to any XHTML tag dynamically, such as adding a title attribute to an anchor tag (<a title="text">)? ...

Responsive CSS Dropdown Menu - Divided into Two Columns

After searching for solutions in the support resources and experimenting with various techniques, I am struggling to divide this CSS Dropdown menu into two columns. The nav list is long enough that it extends below the fold. Although the menu adapts respo ...