In What Conditions We Can Use CSS * Selector

in what conditions we can use css * selector?

It's mainly useful where you want to express that there's an element present, but you don't care what it is. For example:

#mything * span { color: red; }

selects spans inside mything, but not spans directly inside mything.

You should be sparing about when you use * as a global match. As it could hit every one of the (potentially thousands of) elements on your page it's certainly no optimisation; in particular when it's the last thing in a selector (eg. .thing * or just * alone) it makes most browser selector engines work much harder than an simpler selector like .thing. You can get away with one * rule for resets, but using loads of them isn't a good idea.

(Personally I'm somewhat against the * { margin: 0; padding: 0; } fix. It affects way more elements than it actually needs to; the real ‘problem margin elements’ are just the list elements and <form> really. Some form controls also look wrong with the padding removed.)

What does the * * CSS selector do?

Just like any other time you put two selectors one after another (for example li a), you get the descendant combinator. So * * is any element that is a descendant of any other element — in other words, any element that isn't the root element of the whole document.

What does the * * CSS selector do?

Just like any other time you put two selectors one after another (for example li a), you get the descendant combinator. So * * is any element that is a descendant of any other element — in other words, any element that isn't the root element of the whole document.

* vs html, body, div, span, applet, object, iframe...etc

I would actually disagree that most web developers make a long list of element selectors like that. In fact, web developers all have different views on what is the best way to reset CSS.

For instance, the "Tripoli Reset" uses the universal selector *.

This article details only a handful of ways to reset CSS.

http://sixrevisions.com/css/a-comprehensive-guide-to-css-resets/

One reason to be more specific I think is performance as the above answers mentioned (albeit modern browsers nowadays are pretty fast at parsing CSS). Furthermore, developers can also more specific if need be. For instance, some CSS properties such as border-collapse only apply to specific types of elements.

CSS Selector (A or B) and C ?

is there a better syntax?

No. CSS' or operator (,) does not permit groupings. It's essentially the lowest-precedence logical operator in selectors, so you must use .a.c,.b.c.

Checking the existence of a css selector through if conditions

You should use is_dispalyed() to check whenther element is present or not.

try below code :-

  if browser.find_element_by_css_selector('.signOut.logout-icon').is_displayed()
print "Sign In Succesful"
elif browser.find_element_by_css_selector('.msg.ux-error ').is_displayed():
print "Sign In Error"
else:
print "Other issues"

or try below code :

try:
if browser.find_element_by_css_selector('.signOut.logout-icon').is_displayed():
print "Sign In Succesful"

except NoSuchElementException::
if browser.find_element_by_css_selector('.msg.ux-error ').is_displayed():
print "Sign In Error"
except :
print:"other issue"

CSS selector vs Class for styling elements

I think it's better to use CSS selectors style when the style is related to the position of elements and otherwise use classes.

For example, if a table's background of each line is related to their position, say, red for the first line, green for the second line, blue for the third line, red for the fourth line, and green for the sixth line and so on. It's better to use CSS selectors like :nth-child(3n+1) in this case so that you don't need to write the extra information like class='red' in HTML which is a bad practice since it's hard to change if you want to use four colors later.

But if the background of the table lines are decided by their values, say, red for values less than 0, green for values greater than 0, and blue for 0. You may find it quite hard to express this in CSS selectors so adding class='lz0' may be a wise thing to do.

In conclusion, bear it in mind that content and style should be decoupled. Use HTML for content and structure and use CSS for style.



Related Topics



Leave a reply



Submit