CSS should be Shorthand or Longhand

4

Set the correct practice, use CSS with Shorthand or Longhand ? I looked, but I did not find a definite answer ...

When we declare the class with Shorthand we are saying that all other values should be set to initial . I will only demonstrate a few situations that illustrate my interest and doubt.

  

A value that is not specified is set to its initial value. Source: link

So when we declare our BG color like this:

div { 
     background: red;
} 

In fact we are saying, or at least that's how Browser is reading, this:

div { 
    background-image: initial; 
    background-position-x: initial; 
    background-position-y: initial; 
    background-size: initial; 
    background-repeat-x: initial; 
    background-repeat-y: initial; 
    background-attachment: initial; 
    background-origin: initial; 
    background-clip: initial; 
    background-color: red; /* mas eu só queria o bg :) */
} 
  • Is this good for performance?
  • Is it better to declare all values individually or let Browser process all values we are not declaring ?

Possible problems with Shorthand (another example with background)

Simple shorthand problem with background doing override in classes defined by the default component.

.base-class { 
    height: 50px; 
    width: 100%;
    background-position: 0 0; 
    background-repeat: no-repeat; 
} 
.base-class--modifier { 
    background: radial-gradient(...) 
}

<div class="base-class base-class--modifier"></div>

Should be used background-image: radial-gradient(...)

Today like Emmet and software that already has autocomplit almost everything still worth writing CSS with shortcuts? Or is it better to be more concise in style statements?

Is there any good practice Considering performance, maintainability, readability, etc.

Reference links:

asked by anonymous 23.01.2018 / 20:47

1 answer

1
  

Set the correct practice, use CSS with Shorthand or Longhand?

You have responded with your link: link just need to look "When to use"

  

Is this good for performance?

Performance in css is related to use of id, tag and Universal.

#main-navigation {   }      /* ID (O mais Rapido) */
body.home #page-wrap {   }  /* ID */
.main-navigation {   }      /* Class */
ul li a.current {   }       /* Class *
ul {   }                    /* Tag */
ul li a {  }                /* Tag */
* {   }                     /* Universal (O mais lento) */
#content [title='home']     /* Universal */

You can trust this site about perfomance link

  

Is there any good practice?

Reuse of css is a good practice, but the performance is 10 milliseconds longer (just an idea of time), css itself making use of id is not reusable (unless you are reusing it) but it is faster and for not being reusable would be a practice.

A good practice in general, because css is so light and each company or designer has its own organizational style that is impossible to generate a design pattern to be followed by all, css runs in less than 0.1 second (well the less time I am putting aside), this time can "increase" not much when using pseudo-class.

(EDITED) "Avoid using css within html, because it's difficult to maintain."

And lastly, the css file manages the minify because the "biggest problem" is to load the file and not read it.

* Sorry for lack of upgrades my keyboard does not currently have such keys (Turkish keyboard)

    
06.03.2018 / 12:12