CSS3 :not does not exclude a selector by id

Hello wonderful community of Stackoverflow,

Here is my CSS code:

.text:not(#overview > *) {
    margin-top: 10px;
    margin-bottom: 10px;
}

I am trying to apply a 10px top and bottom margin to everything with the class "text", except for elements marked with the ID "overview" and its children. However, the CSS doesn't seem to be working as intended.

Appreciate any assistance, Yasin

Answer №1

Having trouble with how it's functioning? It seems like it's not excluding the id itself, correct? To achieve that, you'll need to include the id as well:

.text:not(#overview) {
    margin-top: 10px;
    margin-bottom: 10px;
}

At the moment, what you're doing is only targeting everything inside the id and not the id itself. This modification ensures that the id is also being targeted.

You can also reset it by using:

.text {
    margin-top: 10px;
    margin-bottom: 10px;
}
#overview.text {
    margin-top: 0;
    margin-bottom: 0;
}

The id carries more specificity than the class.

Answer №2

One possible approach is shown below, however I cannot guarantee that it is the best method!

.content {
    padding-top: 10px;
    padding-bottom: 10px;
}
#summary {
    padding-top: 0;
    padding-bottom: 0;
}

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 there a common method for generating complex identifiers to be used as the HTML element's id, class, or name attributes

Is there a recommended method for "encoding" complex identifiers such as {Source:"ARCH.1", Code: "456-789.456 A+", SubNumber:##2} to be used in HTML elements' id, class, and name attributes? I could come up with something myself, but perhaps there is ...

"Exploring the concept of odd and even numbers within the ng-repeat

Can anyone help me with detecting odd or even numbers in an ng-repeat? I have created a fiddle that displays some dots randomly showing and hiding. Now, I want to change the background color so that odd numbers are green and even numbers are red. function ...

What is the method for incorporating text below font icons?

Having a bit of trouble here with my code snippet featuring 'font awesome' icons in circles. I'm looking to add text beneath each icon, but the alignment within the circle is proving to be a challenge. Check out the code in this link to see ...

Collecting information from form submissions, accessing data from the database, and displaying the results

I am currently working on a project using nodejs, express, and mongodb within the cloud9 IDE. My goal is to create a page with a form that allows users to input data, search for corresponding information in the database, and display that data on the same ...

Elegant Bootstrap 4 Carousel featuring a glimpse of the upcoming slide alongside the primary carousel item

I am in search of a straightforward Bootstrap 4 carousel that showcases a glimpse of the next slide on the right. Despite exploring similar questions, I have not found a suitable solution. The links to those questions are: 1)Bootstrap carousel reveal part ...

The pattern() and onkeyup() functions are unable to function simultaneously

When trying to display a certain password pattern using regex while typing in the fields, I encountered a problem. The onkeyup() function works for checking if both passwords match, but it causes the pattern info box not to appear anymore. I'm curiou ...

Rule for restoring scroll position upon reloading web pages in browsers

When it comes to websites that handle data asynchronously, the behavior of scroll position restoration upon browser refresh can vary. Sometimes the scroll position is preserved, while other times it is not. For example, when reloading after scrolling down ...

Adjust the styling of the anchor tag within the selected div by utilizing jQuery

I am struggling with changing the color of a specific anchor tag when clicked inside a div with class .product_wishlist. Currently, all anchor tags within .pw div are changing colors. Is there a way to apply selected css only to the clicked element? Any he ...

Display the selected checkbox in the table

I am struggling to display the selected check value in a table. I am having difficulty in showing the check values corresponding to each row in the table based on my selected value. For instance, in the code snippet below, I have selected values as true,f ...

Is there a way to display data in a checkbox field using PHP and JQuery Mobile?

I am currently working on a challenge in viewsessions.php. My goal is to retrieve multiple values from a database and group them into checkbox fields (such as typeofactivity, employer, date, time, amount as one combined checkbox field) using <input type ...

Ensure that the sidebar automatically scrolls to the bottom once the main content has reached the bottom

I am facing an issue with a sticky sidebar that has a fixed height of calc(100vh-90px) and the main content. The sidebar contains dynamic content, which may exceed its defined height, resulting in a scrollbar. On the other hand, the main content is lengthy ...

Discovering hidden elements using Overflow:hidden

I need help figuring out how to display the cropped part of my text without using scroll bars in css. For example: td { overflow: hidden; } The hidden content is important, but the table property is fixed. table { table-layout: fixed; } I want the ...

What is the best way to distribute stroke width evenly on a rounded hexagon in an SVG?

I created a rounded hexagon with stroke width, but the top and bottom curves appear darker. Does anyone know how to evenly distribute the stroke width along the border? Here is my SVG code: <svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewbox ...

Refresh the content with an embedded iframe

I am attempting to update the body content by removing all existing content and inserting an iframe: function create_custom_iframe(target){ var iframe = document.createElement('iframe'); iframe.setAttribute('id', 'target_u ...

Enhance your AngularJS skills by incorporating multiple conditions into the ternary operations of ng-class

I am struggling to apply multiple classes when the condition in the ng-class attribute evaluates to true. Here is the code I have attempted so far, but it doesn't seem to be working: <div class="col-md-4" ng-mouseover="hoverButton=true" id="plai ...

The sign-up button mysteriously vanishes after the page is refreshed

I am encountering an issue with the sign up button during the user registration process. There is a checkbox for Terms & Conditions, and the button should only become enabled after checking this box. Everything seems to be functioning correctly, but when I ...

Is it required to double click checkboxes to uncheck them?

My checkboxes require 2 clicks to be unchecked, even though one click is enough to check them. This issue occurs in all 7 checkboxes and there is no onchange() function or similar in TS. import { Component, OnInit, Inject } from '@angular/core&apos ...

Arrange pictures and div elements in a horizontal layout

I am facing an issue with my code that is displaying 5 'cards' in a messed up layout instead of a straight line. I have tried to align them vertically, but some are still higher and not in the right positions. For reference, I want the layout to ...

What is the best way to ensure that my mobile website with fixed-width always appears fully zoomed in?

How can I ensure that my fixed width website always appears fully zoomed in on Webkit browsers such as iPhone and Android? Currently, the site looks good on an iPhone but appears too small or zoomed out on higher resolution Android phones. I have tried u ...

The alignment of Material-UI Typography in AppBar appears to be off

Having trouble centering text in an AppBar? You're not alone. Despite trying various methods like using Typography element, align="center", textAlign="center", and style={{ align: "center" }}, among others: class CustomApp extends React.Component { ...