开发者

Pass width and height as parameters to CSS selector

开发者 https://www.devze.com 2023-01-28 06:25 出处:网络
I\'ve a few .containers CSS selectors which wraps around input boxes which have the same attributes except for the width and height. Is it possible to pass th开发者_StackOverflow社区e width and height

I've a few .containers CSS selectors which wraps around input boxes which have the same attributes except for the width and height. Is it possible to pass th开发者_StackOverflow社区e width and height when I define class="container" ?


Maybe I'm not understanding you correctly, but you want to send back the width and height of the container class so that elements with that class later on inherit that width and height?

Not with pure CSS. It's called cascading style sheets, because you can't go in reverse, if that makes sense.

It's easy with JavaScript, though. In jQuery, for example, you could do:

$(document).ready(function() {
    var width = $('.container:first').css('width');
    var height = $('.container:first').css('height');
    $('.container').css({'width': width, 'height': height});
});
0

精彩评论

暂无评论...
验证码 换一张
取 消