1.文字镂空:
-webkit-text-fill-color:transparent;
-webkit-text-stroke:1px #000;
2.文字强制换行:
word-break: break-all;
3.保留换行符。
// css保留空格和换行符
white-space: pre-wrap;
// css保留换行符
white-space: pre-line;
4.图片变灰色
-webkit-filter: grayscale(100%);
-moz-filter: grayscale(100%);
-ms-filter: grayscale(100%);
-o-filter: grayscale(100%);
filter: grayscale(100%);
filter: gray;
opacity:0.7;
5.inp修改提示字的颜色
input::-webkit-input-placeholder {
color: red;
}
6.文字渐变色:
①
p{
background-image: linear-gradient(135deg,red,blue);
-webkit-background-clip:text;
color: transparent;
}
②
<span text='房屋租赁到期提醒'>房屋租赁到期提醒</span>
span{
position: relative;
color:#ffd901;
}
span:before{
content: attr(text);
position: absolute;
z-index: 10;
color:#ffff00;
-webkit-mask:linear-gradient(to left, #ffff00, transparent );
}
7.设置背景图固定在底部,不会跟随滚动条的变化而滚动
background-attachment: fixed;
background-image: url('图片路径');
background-repeat: no-repeat;
background-attachment: fixed;
background-size: 100% 50%;
background-position: bottom;
8.h5页面跳转传参
window.location.href = 'list.html?name='+name+'&age='+age;
9.h5网页右上角的logo
<link rel="shortcut icon" href="/favicon.ico" />
10.响应式手机端图片:
图片设置:max-width:100%; max-height:100%;
11.css去除input聚焦时的边框:
input{ outline: none; }
12.手机端的logo在电脑端审查元素时是清晰的,在手机查看就模糊:
解决方法:宽高使用三倍像素的logo图片,使用时用1倍的宽高即可。
13.文本域textarea去掉边框的方法:
border:none; resize:none;
14.宽高未知的元素居中:
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
15.父元素高度随子元素变化而变化
#menu{width:1000px;overfloat:hidden;}
.news_detail .img_div img{
width: 100%;
display: block;
height: auto;
overflow: hidden;
margin: auto;
}
16.iframe实现将超链接内容显示到当前页面:
<iframe src ="https://720yun.com/t/97vkcy197dw?scene_id=69125726" longdesc="w3school.txt"></iframe>
17.用swiper轮播的时候,新闻列表处,不要加loop:true;不然只有一条新闻的时候,会显示多条。
18.css给图片增加模糊效果:
只要在图片里面添加一个CSS即可:filter: blur(10px);
19.网站轮播图,宽度设置为100%的时候,会有模糊的感觉。使用object-fit
属性可以解决。
tips:object-fit 属性指定元素的内容去适应指定容器的高度与宽度。
代码:img{ width: 100%; object-fit: none; }