如何为伪元素样式更改CSS?
我正在尝试获取CSS ::before
规则并将left:
更改为95%
或4px
。我应该如何在我的上下文中执行此操作?
我还尝试使用document.querySelector
进行一些测试,但它不起作用,我得到了一个计算只读错误。
你有什么建议吗?
示例:
CSS
.iziToast-wrapper-bottomLeft .iziToast.iziToast-balloon:before {
border-right: 15px solid transparent;
border-left: 0 solid transparent;
right: auto;
left: 8px;
}
js
if(description_iziToast){
let RightMode = event.x>window.innerWidth/2;
let bubblePosition = document.getElementsByClassName("iziToast-balloon")[0]; // get the div that hold the bubble
let ajustScreenLR = RightMode && document.getElementsByClassName("iziToast")[0].offsetWidth || 0; // halfScreen ajustement
//bubblePosition.style.left = RightMode && '95%' || '4px'; // here i need to change the position in the befor:: attribut
description_iziToast.style.left = `${event.x-20-ajustScreenLR}px`;
description_iziToast.style.top = `${event.y-105}px`;
}
}else{
if(description_iziToast){ iziToast.destroy(); description_iziToast = false; };
}
elem.rightMode :: before {left: 95%;}
。 - Kaiido