Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在javascript中更改css伪元素?_Javascript_Jquery_Html_Css_Pseudo Element - Fatal编程技术网

如何在javascript中更改css伪元素?

如何在javascript中更改css伪元素?,javascript,jquery,html,css,pseudo-element,Javascript,Jquery,Html,Css,Pseudo Element,我想更改以下:在css伪元素的top值之前,通过javascript或jQuery动态地。。。我怎么做 #buble{ height:70px; width:980px; background-color:#bce5a5; display:none; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px; box-shadow:0px 0px 4px #dadada; text-indent:35px; col

我想更改以下
:在
css伪元素的
top
值之前,通过javascript或jQuery动态地。。。我怎么做

#buble{

height:70px;
width:980px;
background-color:#bce5a5;
display:none;
-moz-border-radius:5px;
-webkit-border-radius:5px;
border-radius:5px;
box-shadow:0px 0px 4px #dadada;
text-indent:35px;
color:#4a8f44;
font-weight:bold;
font-size:14pt;

       }

#buble:before{

content:"";           
display:block;
position:absolute;
top:77px; /* value = - border-top-width - border-bottom-width */
left:555px; /* controls horizontal position */
border-width:11px 7px 0px; /* vary these values to change the angle of the vertex */
border-style:solid;
border-color:#bce5a5 transparent;
width:0;
height:0;
}

使用jQuery,您需要在头部添加样式:

$('<style>#buble:before{top: 50px}</style>').appendTo('head');
$('buble:before{top:50px}')。appendTo('head');

据我所知,您不能直接修改伪样式,但您可以通过这种方式将CSS插入DOM的头部部分

jQuery
$(“div”)。单击(函数(){
$('p:before{top:10px}')。appendTo('head');
});

检查这个简单的答案,你不能,但有workarounds@user3509090它将被设置为什么值?从
77px
到什么值?谢谢你没看到我的答案吗?@C-link我看到了。非常感谢你,花你宝贵的时间回答我的问题
$( "div" ).click(function() {

  $('<style>p:before{top:10px}</style>').appendTo('head');

});