element中的Switch标签设置文字描述的显示位置


1、html

添加class=“switch”,避免全局样式污染。

<el-switch
	class="switch"
	v-model="switchvalue"
	:validate-event="true"
	active-text="新增"
	inactive-text="累计"
	inactive-color="#409EFF"
	:width="40"
	:active-value="1"
	:inactive-value="0"
	@change="agent_change"
>
</el-switch>

2、css

style标签不需要加任何属性,否则不起作用。<style lang=“scss” scoped>(不起作用),<style>(起作用)。

.switch .el-switch__label {
    
    
  position: absolute;
  display: none;
  color: #fff !important;
}

/*打开时文字位置设置*/
.switch .el-switch__label--right {
    
    
  z-index: 1;
}

/* 调整打开时文字的显示位子 */
.switch .el-switch__label--right span {
    
    
  margin-left: 9px;
}

/*关闭时文字位置设置*/
.switch .el-switch__label--left {
    
    
  z-index: 1;
}

/* 调整关闭时文字的显示位子 */
.switch .el-switch__label--left span {
    
    
  margin-left: 22px;
}

/*显示文字*/
.switch .el-switch__label.is-active {
    
    
  display: block;
}

/* 调整按钮的宽度 */
.switch.el-switch .el-switch__core,
.el-switch .el-switch__label {
    
    
  width: 60px !important;
  margin: 0;
}

3、原文参考链接

原文链接

猜你喜欢

转载自blog.csdn.net/weixin_51157081/article/details/120823424
今日推荐