Creating a CSS rule based on the visibility of the parent div

Is there a way to dynamically change the style of an element through CSS based on the display property of its parent element being set to none?

Take a look at the following HTML:

<div id="mapLinkDiv" class="nav nav-second-level">
  <table class="NavSurvey" style="width:180px;">
    <tbody>
      <tr>
        <td>
          <a class="fixedResultsLink" href="/QBMapping/QBMap.aspx" title="Map results by State" target="MapByState">Map by State</a>
        </td>
      </tr>
    </tbody>
  </table>
  <table class="NavSurvey" style="width: 180px; margin-top:10px;">
    <tbody>
      <tr>
        <td style="font-size:12px; text-align:center;">Maps are underdevelopment and may not work properly</td>
      </tr>
    </tbody>
  </table>
</div>

I would like to create a rule that removes the padding-left from all a tags with the class 'fixedResultsLink' if the parent element, mapLinkDiv, has its display set to none.

Here is the current CSS code on the page:

<style>
  a.fixedResultsLink{ 
    padding-left:28px;
  }
  #mapLinkDiv[style*='display:none'] a.fixedResultsLink {
    padding-left:0;
  }
</style>

Despite my efforts, I haven't been able to find a solution online. Any suggestions on how to make this work?

Answer №1

The CSS selector #mapLinkDiv[style*='display:none'] a.fixedResultsLink targets an a.fixedResultsLink that is a direct descendant of the #mapLinkDiv element. To make this selection less cumbersome, you could include all parent tags of the a.fixedResultsLink in the same css selector.

Another option would be to use the selector #mapLinkDiv[style*='display:none'] table tbody tr td a.fixedResultsLink

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

Is your browser displaying dimensions different from the ones specified in the CSS?

On my webpage, I have defined the header and leftpane as div. The specified height of header is 116px, and the width of leftpane is 181px. However, upon inspecting the page using chrome-developer-tool, the displayed height and width are 98.36px and 165.41p ...

Ways to prioritize HTML5/CSS3 navigation menu above the content

I am attempting to position my navigation menu on top of the content. Despite using z-index and overflow = visible, the desired effect is not achieved. I want to avoid setting the position relative as it will push the content downwards. Simply put, I want ...

My div is currently being concealed by a jQuery script that is hiding all of its

Below is the current code snippet: jQuery(document).ready(function($) { $("ul.accordion-section-content li[id*='layers-builder'] button.add-new-widget").click(function() { $("#available-widgets-list div:not([id*='layers-widget']) ...

Ways to implement the CSS on images with an ID such as img120 within a div that has a class of 'open'

<div class='cluster' id='12' 'style='width:350px;min-height:150px;border:4px solid #339966;'> <div class='image' style='width:150px;height:150px;border:2px solid black;float:left;margin-bottom: ...

"Efficiently managing multiple selections in Angular ui-select with a pristine ng

While attempting to utilize the ui-select feature, I have encountered an issue where the component is clearing my array. For example: {{ vm.staff_hotels }} <ui-select multiple ng-model="x" theme="bootstrap"> <ui-select-match placeholder="Not ...

Adjust the background to scroll to the bottom of the image first and then change it to be fixed

Here is the code I have written: body{ margin:0; padding:0; line-height: 1.5em; background-image: url(http://fehlbelichtet.stefanwensing.de/wp-content/uploads/sites/6/2016/04/alte-strasse-endlos.jpg); background-repeat:no-repeat; background-attachment: ...

Implementing AngularJS to display different divs according to the selected value

I am attempting to utilize the value of an HTML select element to toggle the visibility of specific div tags using AngularJS. Below is the code snippet I have been working with: <body ng-app="kiosk" id="ng-app" > <div class="page" ng-controll ...

How to manipulate iframe elements using jQuery or JavaScript

Hey there, I have a simple task at hand: I have a webpage running in an iFrame (located in the same folder on my local machine - no need to run it from a server) I am looking to use JavaScript to access elements within this iFrame from the main page. How ...

What is the reason for Selenium only capturing a portion of the HTML content on a webpage?

I attempted to utilize selenium in order to navigate the web-untis webpage and locate any tests scheduled for this week, but I am facing difficulty in locating the web-elements within the html-file that contain the lesson data. Although other elements such ...

"Unlocking the Power of jQuery: A Guide to Customizing CSS with Scroll Effects

Many CSS examples include a scrollbar for editing the CSS code. Click here to see an example of the scrollbar I haven't been able to find any instructions on how to do this. Can someone please explain? ...

What is the best way to transfer the value of a <span> element to a different <div> using jQuery or JavaScript

Is there a way to move or copy the price and insert it into the <div class="info"> using jQuery? The code I'm currently using is returning an unexpected result of "102030". jQuery(document).ready(function($) { $(document).ready ...

Ways to showcase a list in 3 columns on larger screens and 1 column on smaller screens

When viewing on a computer, my list appears like this: https://i.sstatic.net/fNhaP.png However, when I switch to a phone, only the first column is visible and the list does not continue in a single column format. I am utilizing Bootstrap for my layout, a ...

Opening a navigation app through a smartphone webpage

My goal is to enable users to click on a postcode and open their native map app. Most of the solutions I've come across are tailored to specific vendors. Is there a universal "maps" protocol that can launch the native app? Could something like "maps ...

Master the Art of Creating Responsive Table Rows

Can someone please help me with making my table of rows and columns mobile responsive? I have inserted data from the database, but it doesn't adapt well for mobile devices. I have used element1 and content1 id for the background of the elements, but h ...

Issue with XAMPP: Editing PHP file does not update displayed content in browser

Initially, my code looked like this: <!DOCTYPE html> <html> <head> <link type="text/css" rel="stylesheet" href="css/style.css" /> <title>PHP file</title> </head> <body> <h1> <?ph ...

Automatically setting the navbar to expand on medium devices

I am facing an issue while styling my navbar with BS5 installed. I have noticed that the className navbar-expand-md is being assigned, even though I have specified navbar-expand-custom in my code. navbar = _dbc.Navbar( [ _dbc.C ...

Encountering the issue of receiving an undefined class when using the img tag in a

In my React.js project, I encountered an issue where the class for the img tag is appearing as undefined. The problem lies within the Header.jsx component. In this file, I am using the <img> tag but the CSS properties are not being applied to the ima ...

Is there a way for me to use an ajax xmlhttprequest to submit all the selected values from my radio buttons?

Here's the situation: I have four input forms [A-D] and I have selected options A and B. I want to transfer this information to another page, but I'm not sure how to do it. I've tried searching for tutorials on AJAX, but most of them focus ...

When the navbar is expanded, a right-aligned image is visible; however, it becomes invisible when the

My website has a navigation bar with two logos - one in the left corner (the coat of arms) and one in the right corner (the scout lily), along with text links in between. The coat of arms uses the "navbar-brand" class. To see how it looks, click here: htt ...

How to retrieve the value of a <td> tag with a rowspan greater than one using JQuery

I have a dynamic table that depends on the quantity of data in the abc1 column. For example, in this instance, there are 2 rows in the abc1 column with values of 18 and 23 http://jsfiddle.net/SdN4L/ <table border=1> <tr> < ...