Hibop / Hibop.github.io

Hibop 个人博客
https://hibop.github.io/
23 stars 1 forks source link

关于css进阶——布局和BFC #41

Open Hibop opened 6 years ago

Hibop commented 6 years ago

display的几个常用的属性值,inline , block, inline-block

css中的百分比

注意事项:当百分比值用于可继承属性时,只有结合参照值计算后的绝对值会被继承,而不是百分比值本身。

css隐藏元素的方法

  1. input-file控件,重写定制化内置btn样式;
    .file {
      position:absolute;
      right:0;
      top:0;
      _zoom:30;
      font-size:300px\9;
      height:100%;
      _height:auto;
      opacity:0;
      filter:alpha(opacity=0);
      -ms-filter:"alpha(opacity=0)";
      cursor:pointer;
    }
      1. 什么widh: 0/height: 0
      1. 文字font-size:0; [可以hack display: inline-block; margin问题]
      1. 文字color: transparent;
      1. 文字text-indent: -99999999px;
      1. z-index: -999999999
      1. position: absolute left: -999999px;
      1. margin: -99899px
    • 11 transform: translate(-9999999px) skew(90deg) scale(0)

css选择符的命名规则及规范:

css语法对于命名字符有更多的规定。以下是W3C关于命名标识符的说明中的内容:

In CSS, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646 characters U+00A0 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a digit, two hyphens, or a hyphen followed by a digit. Identifiers can also contain escaped characters and any ISO 10646 character as a numeric code.

意思是说,css中允许使用的命名字符,包括大小写英文字母、数字、连字符-、下划线_及其他ISO 10646字符集(等同于Unicode)中的字符。同时,起始字符部分不能是数字,或连续2个-,或1个-后接1个数字。此外,允许使用转义字符和任意ISO 10646字符的数字代码。

可以看出,命名允许使用的字符其实是非常多的。但是,有一个地方需要注意,就是特殊字符。特殊字符是指在css语法中,被认定用来表示特定含义的字符(相当于编程语言中的关键字)。例如,...这样的class命名是不合法的,因为.是css选择符中表示class的字符,因此不允许直接用在命名中(...这位沉默着的class名你感觉如何?)。

css中的特殊字符包含:!, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @, [, \, ], ^,`, {, |, }, 和~。

这个时候,想要在命名中也加入这些特殊字符,就要使用字符转义(character escape)。字符转义通过反斜杠\实现,在css选择符中,你可以通过在特殊字符前加\的方法,取消特殊字符的特定含义,使其可以正确地被用于命名。

经过测试,IE6对起始字符是下划线_和单个连字符-的情况,也会认定样式规则无效。 eg:

<div class="^_^"></div>  合法
<div class="♫">music on~</div> 合法
.3-column 不合法

一套css书写规范:

rscss和rsjs是一套比较小巧的前端开发规则和约定,其中rs代表Reasonable System。

rscss希望有效地改善写css中的这样几个常见问题(css哲学三问):

主要要点:

SMACSS认为css有5个类别: