css常用到的设置总结

css常用到的设置总结

1.每段文本自动缩进两个字符

text-indent:2em;

2.元素超出盒子宽度自动变成省略号

white-space:nowrap;
text-overflow:ellipsis;
overflow:hidden;

3.ES6数组去重

在这里插入图片描述

white-space:nowrap;
text-overflow:ellipsis;
overflow:hidden;

4.es6中的模板字符串拼接

在这里插入图片描述
结果:
在这里插入图片描述

5.数组里面有多个对象,对象中有多个属性,在这些属性中选取其中的id和name重新组成一个新的数组对象。

得到数组对象res循环取出该结果中每一个对象的id和name,然后将id和name拼接在一起再传给接收的数组,该数组要先置为空,不然数据会堆积。
如:
在这里插入图片描述

6.map函数的应用

从后台返回来的res中的数据格式:长沙,武汉,广州
要实现将“长沙”“武汉”“广州”分别取出来放入一个数组中保存
取出返回数据中的每一项,用逗号分开再返回给this.getActivityList变量中保存

在这里插入图片描述

7. 设置div中的图片居中,

vertical-align: middle;但要注意这个值是基于基线对齐的,父元素要设置line-height: 300px;属性才能达到效果

.father{
		background-color: orange;
		width: 100%;
		height: 300px;
		line-height: 300px;
	  
	}
	.father image{
		width: 40px;
		height: 40px;	
		vertical-align: middle;	
	}

运行结果:
在这里插入图片描述

注意:如果有一方不设置会出现偏差,达不到自己想要的结果
如:父元素只设置line-height,图片不设置vertical-align
在这里插入图片描述
再如:
在这里插入图片描述

8.让div中的图片居中

(1)设置图片上下左右居中:
用定位来实现,父元素为相对定位,里面的图片用绝对定位,然后上下左右设置为0.再给margin:auto;即可实现,
如:

<template>
	<view>
		<view class="father">
			<image src="../../static/wenjianimg.png" mode=""></image>
		</view>
	</view>
</template>
<script>
	
</script>
<style scoped>
	.father{
		background-color: orange;
		width: 100%;
		height: 300px;
		
		position: relative;
	}
	.father image{
		width: 40px;
		height: 40px;
		
		position: absolute;
        top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		margin: auto;
	}
</style>

结果截图:
在这里插入图片描述
(2)设置图片左右居中:
①设置图片:margin: 0 auto;display: block;

.father{
		background-color: orange;
		width: 100%;
		height: 300px;
	}
	.father image{
		width: 40px;
		height: 40px;
		margin: 0 auto;
		display: block;
	}

② 设置父级div:text-align: center;

.father{
		background-color: orange;
		width: 100%;
		height: 300px;
		text-align: center;
	}
	.father image{
		width: 40px;
		height: 40px;
	}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值