踩坑 - CSS 篇

This is a note for writing down what I have learnt through my work. And this note is for CSS


input 设置 :before、:after 无效

原因:要设置“之前”、“之后”的内容,要求该元素本身是要可以插入 DOM 内容的。而 input、img、iframe 等元素是不能包含其他元素的,因此设置 :before、:after 无效

prop 修改属性与相关选择器

在 css 中使用属性选择器,当使用了 jQuery 的 prop 方法修改属性值后,选择器依然可以监测到。

<input type="text" readonly>

input[readonly] {
background: pink;
}
$('text').prop('readonly', false);

stylus 的减法运算符

stylus 的减法运算符和变量之间要用空格隔开

$width=300px;
.test{
width: $width - 100
}

==>

.test{
width: 200px;
}

IE8 下的 box-sizing

在高版本浏览器中,直接使用通配符选择器,设置 box-sizing 属性,就可以为所有元素设置该属性。但是在 IE8 中失效,并没有将这个属性应用到元素中。
解决方法:

/* 为 body 加一个 class —— "page" */
.page * {
box-sizing: border-box;
}

文本取消自动换行

css3 的属性:

.test {
white-space: nowrap;
word-break: keep-all;
}