Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reason for the last line in CSS to not have a closing tag ";"?

Tags:

css

I've been working with CSS for sometime and I see that in a lot of tutorials and exercises the last line of a CSS tag has no ";" added to it. For example:

ul li:hover ul { 
    display: block
}

ul li ul {
      list-style: none;
      position: absolute;
      display: none;
      width: 104px;
      height: 100px;
      background-image: url(../_img/nav/dropdownbg.1.png);
      background-repeat: no-repeat;
      background-position: center;
      background-position: top
}

As you can see there are two examples. One with only one line and another with different commands in one tag. I would like to know why and which reason is there to do this?!! At school they didn;t tell us anything about this. I just close the last or only line with and ";" and it works perfectly.

So, which is the reason to do this? Is it more safe?

like image 249
Daniel Ramirez-Escudero Avatar asked Dec 27 '22 19:12

Daniel Ramirez-Escudero


1 Answers

Šime Vidas' response to a related question is also valid here. The semicolon is a delimiter so the final property does not need to be delimited.

However, I would not recommend it, because in the scenario that you need to add another property to the end of a CSS rule it is far more likely that you'll miss out the need for a semicolon and your CSS will break.

like image 107
Mike B Avatar answered Dec 29 '22 09:12

Mike B