更改a:前的css选择器的width属性使用JQuery [英] Changing width property of a :before css selector using JQuery
问题描述
我有一个页面,其中有一个图像,我使用样式:CSS选择器之前。
图像是动态的,因此它没有固定的宽度;所以我需要设置:动态规则的宽度之前。
我想在客户端使用JQuery。
假设:
I have a page that has an image in it and I styled it using :before CSS selectors.
The image is dynamic so it hasn't a fixed width; So I need to set :before rule's width dynamically.
I want do it in client side using JQuery.
Assume this:
.column:before{
width: 300px;
float: left;
content: "";
height: 430px;
}
.column{
width: 500px;
float: right;
padding: 5px;
overflow: hidden;
text-align: justify;
}
如何只能改变类的宽度属性:before
选择器(而不是一个没有它)使用JQuery?
How Can I only change the width property of class with :before
selector (and not one without it) using JQuery?
推荐答案
我不认为有一个jQuery的方式来直接访问伪类的规则,但你可以总是追加一个新的 style
元素到文档的头像:
I don't think there's a jQuery-way to directly access the pseudoclass' rules, but you could always append a new style
element to the document's head like:
$('head').append('<style>.column:before{width:800px !important;}</style>');
See a live demo here
我还记得有一个插件解决这个问题一次,但我找不到它googling不幸。
I also remember having seen a plugin that tackles this issue once but I couldn't find it on first googling unfortunately.
这篇关于更改a:前的css选择器的width属性使用JQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!