Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the css line: *[class].testClass{ } actually mean?

I was just hired at a job to create interactive emails for a marketing company, which is some cutting edge stuff.

I'm browsing through the guy's templates who left here, and his CSS has some things I cant figure out. I'm in charge of creating new CSS files and templates, but I have never seen this before. Can someone help me figure out what this all means? I am having trouble finding anything about it online

For instance, some lead with *[class], some lead with *[id] and some lead with none of those.

Here is an example.

*[class].h83 {
    height:43px !important;
}

*[class].pt50 {
    padding-top:50px;
}

*[class].pl30 {
    padding-left:30px;
}

*[class].anim_h {
    display:none;
}

*[id]#MMGContainer {
    width:640px !important; 
    height:500px !important;
    position:relative; 
    text-align:left; 
    display:block;
    overflow:hidden;                
}

*[id]#MMGContainer #hotspot_03_btn.hotspot:after {                
    top:166px;
    padding:0;
    display:inline-block; 
    content: url(images/1/icon-2.png);
}

#mobile-cta, .mobile-only { 
    display: block !important;
    max-height: none !important;
    width: 100% !important; 
    height: auto !important; 
    overflow: visible !important; 
}
like image 604
luminol Avatar asked Jun 29 '16 20:06

luminol


People also ask

What is the use of class in CSS?

What is a CSS class? A CSS class is an attribute used to define a group of HTML elements in order to apply unique formatting to those elements in CSS. This group can contain more than one type of element. The class attribute doesn't impact the semantic meaning of the HTML document.

What does p mean in CSS?

p is a selector in CSS (it points to the HTML element you want to style: <p>). color is a property, and red is the property value text-align is a property, and center is the property value You will learn much more about CSS selectors and CSS properties in the next chapters!

How do you write a class name in CSS?

These names are descriptive enough that someone just reading the CSS would understand the purpose of the class. Class names can be one or multiple words. If your class name is multiple words, use hyphens where you would put spaces. Also, it’s common practice to write class names in lowercase.

How do you select a class in CSS?

In CSS, a class selector is formatted as a period (.) character followed by the name of the class. It selects all elements with that class attribute so that unique CSS declarations can be applied to those specific elements without affecting other elements on the page.


1 Answers

Most of these declarations are overly verbose and could be simplified by quite a bit.

Example and Breakdown

Let's use *[class].h83 as an example as it has a few things going on :

  • * - This simply is a universal selector, so it doesn't do much here.
  • [class] - This is an attribute selector, which will target any element with a defined 'class' attribute.
  • .h83 - This will target an element with the class 'h83'.

So putting all of these things together, you'll get a style that target any elements with the class attribute of 'h83'.

Simplification

As I mentioned initially, nearly all of these styles are overly verbose. The *[class].h83 example earlier could easily be rewritten using something as trivial as :

.h83 { height:43px !important;}

Why is this? Well you know the universal selector * is going to handle targeting all elements, so that isn't going to be very specific in this case. Secondly, you know that if you are using .h83, you'll be targeting an element with a class attribute of h83, so you are already guaranteed to have a class attribute (thus you don't need the attribute selector).

Note on Simplifying Selectors

Currently all of your selectors are prefixed with * and some type of attribute selector. While this will work, it's generally unnecessary.

If you are using either id-based #id or class-based .class selectors, then you shouldn't need to preface them with *[id|class] respectively as the # or . character will take care of that on its own.

like image 148
Rion Williams Avatar answered Oct 19 '22 23:10

Rion Williams