Javascript 样式表的索引。我使用了console.logdocument.styleSheets;这听起来很不错,但对我来说不起作用。您提到的MDN引用sais attr函数可以用于任何CSS属性,但是对内容以外的属性的支持是实验性的。 .column:before{
Javascript 样式表的索引。我使用了console.logdocument.styleSheets;这听起来很不错,但对我来说不起作用。您提到的MDN引用sais attr函数可以用于任何CSS属性,但是对内容以外的属性的支持是实验性的。 .column:before{,javascript,jquery,css,Javascript,Jquery,Css,样式表的索引。我使用了console.logdocument.styleSheets;这听起来很不错,但对我来说不起作用。您提到的MDN引用sais attr函数可以用于任何CSS属性,但是对内容以外的属性的支持是实验性的。 .column:before{ width: 300px; float: left; content: ""; height: 430px; } .column{ width: 500px; float: right;
样式表的索引。我使用了console.logdocument.styleSheets;这听起来很不错,但对我来说不起作用。您提到的MDN引用sais attr函数可以用于任何CSS属性,但是对内容以外的属性的支持是实验性的。
.column:before{
width: 300px;
float: left;
content: "";
height: 430px;
}
.column{
width: 500px;
float: right;
padding: 5px;
overflow: hidden;
text-align: justify;
}
$('head').append('<style>.column:before{width:800px !important;}</style>');
$('#element').addClass('some-class');
.some-class:before {
/* change your properties here */
}
var pseudoElementContent = window.getComputedStyle($('#element')[0], ':before')
.getPropertyValue('content')
var addRule = function(sheet, selector, styles) {
if (sheet.insertRule) return sheet.insertRule(selector + " {" + styles + "}", sheet.cssRules.length);
if (sheet.addRule) return sheet.addRule(selector, styles);
};
addRule(document.styleSheets[0], "body:before", "content: 'foo'");
/*!
* jquery.addrule.js 0.0.1 - https://gist.github.com/yckart/5563717/
* Add css-rules to an existing stylesheet.
*
* @see http://stackoverflow.com/a/16507264/1250044
*
* Copyright (c) 2013 Yannick Albert (http://yckart.com)
* Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php).
* 2013/05/12
**/
(function ($) {
window.addRule = function (selector, styles, sheet) {
styles = (function (styles) {
if (typeof styles === "string") return styles;
var clone = "";
for (var p in styles) {
if (styles.hasOwnProperty(p)) {
var val = styles[p];
p = p.replace(/([A-Z])/g, "-$1").toLowerCase(); // convert to dash-case
clone += p + ":" + (p === "content" ? '"' + val + '"' : val) + "; ";
}
}
return clone;
}(styles));
sheet = sheet || document.styleSheets[document.styleSheets.length - 1];
if (sheet.insertRule) sheet.insertRule(selector + " {" + styles + "}", sheet.cssRules.length);
else if (sheet.addRule) sheet.addRule(selector, styles);
return this;
};
if ($) $.fn.addRule = function (styles, sheet) {
addRule(this.selector, styles, sheet);
return this;
};
}(window.jQuery));
$("body:after").addRule({
content: "foo",
color: "red",
fontSize: "32px"
});
// or without jquery
addRule("body:after", {
content: "foo",
color: "red",
fontSize: "32px"
});
<div class="column" bf-width=100 >
<img src="..." />
</div>
// General use:
$('.column').attr('bf-width', 100);
// With your image, along the lines of:
$('.column').attr('bf-width', $('img').width());
.column:before {
content: attr(data-content) 'px';
/* ... */
}