The CSS adjacent sibling selector stops working if a class is added to the parent element

Here is a Fiddle showcasing the issue

Everything seems to be working flawlessly

.content-wrapper.row-fluid + .footer.row-fluid {
    margin-top: 40px;
}

This particular selector successfully targets the adjacent sibling element only on pages with the body class path-frontpage

.path-frontpage .footer.row-fluid {} 

Similarly, this code snippet works for the div above the footer specifically on pages with the body class path-frontpage

.path-frontpage .content-wrapper.row-fluid {}

However, the subsequent section fails to adjust the footer's margin-top to zero on pages with the body class path-frontpage. Even though Chrome inspector indicates that the first rule is active. What could be causing this? How can I make sure the margin gets reset only on pages with the body class path-frontpage ?

.path-frontpage .content-wrapper.row-fluid + .path-frontpage .footer.row-fluid {
    margin-top: 0px;
}

Answer №1

Correct implementation

.path-frontpage .content-wrapper.row-fluid + .footer.row-fluid {
    margin-top: 0px;
}

In order for your code to function properly, the HTML structure should resemble the following.

div { border:1px solid #ff0000; height: 30px; }

.content-wrapper.row-fluid + .footer.row-fluid {
    margin-top: 40px;
}

.path-frontpage .content-wrapper.row-fluid + .path-frontpage .footer.row-fluid {
    margin-top: 0px;
}
<body class="path-frontpage">
<div class="content-wrapper row-fluid">wrapper
</div>
<div class="path-frontpage"> <!-- I added -->
<div class="footer row-fluid">footer
</div>
</div>
</body>

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

How can I showcase Bootstrap cards horizontally within a razor foreach iteration?

I seem to be experiencing a mental block on how to arrange bootstrap cards in a horizontal layout using a for each loop. By default, they appear vertically. Below is my razor code: @foreach (var item in Model) { var imgUrl = Url.Content("~/Conte ...

What is the best way to center align an element while having another element situated directly below it?

I want to create a grid of "clock" elements, with five clocks in each row. Below each clock, I'd like to display the DAY and DATE centered with the clock (day on top line, date below). Since I'm new to html/css, I appreciate your patience. Here&a ...

what is a way to verify the presence of a variable in Angular?

Take a look at this sample code snippet: <li class="list-group-item" *ngIf="request.answer.user"> <a href="" class="d-flex flex-column align-items-center"> <span class="i ...

The width of the Bootstrap tooltip changes when hovered over

Currently, I am facing a peculiar issue with my angular web-application. Within the application, there is a matrix displaying data. When I hover over the data in this matrix, some basic information about the object pops up. Strangely, every time I hover ov ...

Border concealed by Bootstrap Glyphicons

Is there a reason why glyphicons hide a border of a floated container? Can anyone shed light on this issue and suggest a workaround? Check out this link for more information. https://i.sstatic.net/CXZSd.jpg My setup: OS X 10.11.1, Chrome 47.0.2526.73 (6 ...

HTML and CSS3 - Pair of Background Divs

I've been encountering some issues with my website recently. I'm attempting to stack two divs on top of each other to create a jagged background effect. Here's an example: https://docs.google.com/drawings/d/1IdqWKdkbS-xxLrvzLF8bh5k_B6iIzmlmN ...

Tips for choosing an SVG element within an HTML <object> tag using JavaScript

I have an Angular application where I need to select the embedded SVG element within an <object> tag using JavaScript or Angular jqLite. Usually, in order to accomplish this task, one typically needs to write code similar to the following: // Creat ...

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 ...

Overflowing C3 graph within a Bootstrap 4 accordion card

I have been trying to embed a c3 graph into a Bootstrap accordion section. The graph displays perfectly on the active card, but when I expand Card 2, the right side of the graph extends beyond the edge of the card. https://i.sstatic.net/vZZ8k.png Do I ne ...

Customizing the Dropdown Arrow Icon to a Desired Icon of Choice

I'm looking to customize the dropdown select on my website by changing the arrow icon to a plus icon, which will then turn into a minus icon when clicked and the choices are displayed. I'm new to jquery and eager to learn more about this language ...

Ensure that all panels are set to the same width as the widest panel

Is there a way to make all the panels in my jQuery tabs have the same width as the widest panel? I know that heightStyle:"auto" works for adjusting the height, but is there a similar option like widthStyle:"auto"? I want to show you the current look compa ...

Using jQuery to Retrieve an Element's Class Through an AJAX Call

For my website, I am using ajax to load pages by replacing the content in the main tag. The issue arises when working with Wordpress, as each page has its own set of body classes for styling purposes. My goal is to replace the old page's body classes ...

Creating an ASP.NET MVC application, the index table seems to extend beyond the confines of the page

Embarking on the journey of creating my first web app after years of mastering C# Windows Forms development in .NET has been a thrilling adventure. Following the guidance of the NerdDinner tutorial, I've tweaked certain components to align with my pro ...

Is it possible to conceal a div using the visible property, regardless of its background?

Below is the code for a div element: <div visible="false" style="background-image:url('../Contents/Images/item-background-selected.png'); width:113px; height:58px; background-repeat: no-repeat; position: absolute;" /> <div> D ...

Unable to retrieve the form from the website

My goal is to extract the login form from: Although I can see the form element when inspecting in Chrome, I'm encountering difficulties retrieving it using the jaunt API in Java. userAgent = new UserAgent(); userAgent.visit("https://etoro.com/login" ...

What is the most effective way to sort through an observable array?

Currently, I am working on filtering an array of strings retrieved from Firebase database by clicking on a button and invoking a method to apply the filter. However, I am facing an issue where nothing seems to be happening as expected. Can someone point o ...

Aligning Bootstrap Cards in Mobile View

When viewing on mobile, the cards aren't centering properly. I've attempted to use d-flex and justify-content-center as recommended in a previous response without success. I've observed that by adding mx-auto to each card class it somewhat ...

Turn off scroll bar to create a seamless browsing experience on your website

As I work on creating the frontend for a single-page website with seamless scrolling between divs, I'm looking to eliminate mouse scrolling altogether. I understand that using overflow:hidden; can hide scroll bars, but my goal is to make the page scr ...

Having trouble with a fixed element that won't scroll?

Code Example: <div id="tmenu" style="direction:rtl;"> <img src="assets/imgs/menu/all.jpg"/> <img src="assets/imgs/menu/sweets.jpg"/> <img src="assets/imgs/menu/main meals.jpg"/> <img src="assets/imgs/menu/ma5bozat.jpg"/& ...

With Firefox, when submitting a form only the final repeated region value is $_POSTed and not all of them

There seems to be an issue with the code below when running it in Firefox. The problem occurs when passing the URL variable UserName. In Firefox, only the last record is being used from the record-set, regardless of which button is clicked. This page utili ...