---
title: "书写css伪类时冒号前或后多个空格导致该规则失效"
author: "zhouyrt"
date: "2010-12-07T09:15:47Z"
tags: []
categories: ["Web前端"]
slug: "css"
draft: false
lastmod: "2011-04-02T10:27:08Z"
id: 835249
url: "https://snandy.iteye.com/blog/835249"
---

相信多数开发者不会多个空格。  
是偶然发现的，网上多数css格式化将压缩后的css格式化后会发生这个情况。

搜“css格式化”，以下网站

http://www.jb51.net/tools/cssyasuo.shtml  
http://www.ttmouse.com/geshi.html

格式化后会多出个空格，多出空格后样式规则失效了。

 

```
<!DOCTYPE html>
<html>
  <head>
    <title>书写css伪类时冒号后多个空格导致该规则失效</title>
	<meta http-equiv="Content-Type" content="text/html;charset=gbk"/>
	<style type="text/css">
		a:link{color : gray;}
		a:visited{color : red;}
		/* 冒号后多了个空格 */
		a: hover{color : yellow;}
	</style>
  </head>
  
  <body>
		<a href="http://www.sina.com">sina</a>
  </body>
</html>
```