DEV Community

Calin Baenen
Calin Baenen

Posted on

Is this CSS valid (does it work properly)?

body * {
    /* Styling */
    position:absolute;
}

body * * {
    position:relative;
}
Enter fullscreen mode Exit fullscreen mode

Will this work the way I expect?

I don't know how many sub-elements I'm going to add yet, so I can't really try it, since I'm working on a project, blah blah.

Would this make all elements nested inside of body-nested elements relative positioned, or does * work in the way it works as the normal "universal selector", where it can only be overridden by !important?

Thanks in advance!
Cheers!

Top comments (10)

Collapse
 
merri profile image
Vesa Piittinen • Edited

The end result will be that every immediate child of body will be position: absolute, but all elements within will be position: relative regardless level of nesting.

Demonstrated here with colors:

A * does not have specificity weight so if you reverse the rules then all elements will be red.

Collapse
 
baenencalin profile image
Calin Baenen

Thank you. This was very helpful to my understanding of CSS (because imo, it's kinda wonky).

Collapse
 
desirtech profile image
Jeffrey Desir

I like your curious questions, try postCSS!. CSS' days are numbered as more creative thinkers bridge the abstraction gap between 2D/3D layouts, and linear, declarative statements✌🏿

Thread Thread
 
baenencalin profile image
Calin Baenen

That looks intimidating, what files would I want/need, how would I import them in a meaningful manner?

When it comes to libraries and such (in any language/ctx) I'm an absolute fucking noob, especially when it comes to tools used for web development.

Thread Thread
 
rvxlab profile image
RVxLab

If you’re still learning don’t worry about tooling just yet.

Learn the languages first and when you’re comfortable with them look at things like tooling and frameworks. When you start learning web frameworks like Vue and React you’ll come across the things you need over time.

Thread Thread
 
baenencalin profile image
Calin Baenen

What if I never become familiar or comfortable with such things?

Thread Thread
 
rvxlab profile image
RVxLab

You don’t learn these things overnight. If you’re willing to learn and grow as a programmer all these things will come with time.

You can learn A LOT of these things on YouTube as well.

Everyone learns different, find what works for you.

Thread Thread
 
baenencalin profile image
Calin Baenen • Edited

If only search engines could find the answers to my very specific questions so I wouldn't have to always ask. I ALWAYS get stuck putting in new keywords, calling my default SE (Google) (and the other ones that fail) a dumbass in the search bar after too much searching.
I hate that SEs aren't so literal w/ keywords/tags.

Thread Thread
 
rvxlab profile image
RVxLab

That’s a skill you develop over time as well. You need to ask your question vague enough to be generally applied, but specific enough as to be useful to you.

Google can be made literal by putting quotes around the keyword.

Give me an example of what you’re trying to find.

Thread Thread
 
baenencalin profile image
Calin Baenen

How to import java packages that use raw .java files.

It comes up with how to use default packages, and how to make and compile them, but not exactly what I specified.