自己平时整理的一些常用的 CSS 样式
在IE6中使用 filter: alpha(opacity = 40);
在其他浏览器中使用 opacity: 0.4;/*\9表示兼容所有的IE浏览器*/
line-height: 35px\9; .clearfix:after {
content: '';
height: 0;
clear: both;
overflow: hidden;
visibility: hidden;
display: block;
}
.clearfix {
*zoom: 1;
} -moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;.parent {
position: relative
}
.child {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
}.parent {
position: relative;
}
.child {
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-o-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
position: absolute;
left: 50%;
top: 50%;
}.parent {
display: flex;
justify-content: center;
align-items: center;
}overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;.parent {
position: relative;
}
.child {
margin: auto;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
} .border-1px {
position: relative;
}
.border-1px::after {
content: '';
width: 100%;
border-top: 1px solid #ccc;
display: block;
position: absolute;
left: 0;
bottom: 0;
}
/* 如果网页在最小屏幕像素比为1.5的移动设备上运行 */
@media (-webkit-min-device-pixel-ratio: 1.5),(min-device-pixel-ratio: 1.5) {
.border-1px::after {
-webkit-transform: scaleY(0.7);
transform: scaleY(0.7);
}
}
/* 如果网页在最小屏幕像素比为2的移动设备上运行 */
@media (-webkit-min-device-pixel-ratio: 2),(min-device-pixel-ratio: 2) {
.border-1px::after {
-webkit-transform: scaleY(0.5);
transform: scaleY(0.5);
}
}.flex {
display: -webkit-box;
display: -webkit-flex;
display: flex;
}.flex-1 {
-webkit-flex: 1;
flex: 1;
}当引入第三方组件后,使用深度选择器可以局部修改第三方组件的样式,避免全局样式污染
<style lang="less" scoped>
/deep/ .ivu-poptip,
/deep/ .ivu-poptip-rel {
width: 100% !important;
}
</style>在 SCSS 中使用 /deep/
<style lang="scss" scoped>
/deep/ .ivu-poptip,
/deep/ .ivu-poptip-rel {
width: 100% !important;
}
</style>这里是以 iView 框架为例,不同框架的尺寸值可能不一样
.content {
height: 100vh;
}.screen {
width: 100%;
height: 100vh;
background: url('../bg.png') no-repeat center top;
background-size: 100% 100%;
}meishadevs欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果。 转载请注明: 【文章转载自meishadevs:常见的CSS样式兼容性写法】