[英]Javascript: Set Width of DIV by Window Height
I want to set the width of a div to the same value as the window height. 我想将div的宽度设置为与窗口高度相同的值。
I tried something like this: 我尝试过这样的事情:
<script type="text/javascript">
$(".rt-container").style.width = $(window).height();
</script>
But it's not working. 但这不起作用。 Maybe because I'm an absolute beginner with javascript.
也许是因为我绝对是javascript初学者。
How can I achieve it (by using jquery)? 如何实现(使用jquery)?
You can change css
styles like this, use the method .css()
with option
and value
as parameters and add the "px" to value, as mentioned in comments: 您可以像这样更改
css
样式,使用带有option
和value
作为参数的.css()
方法,并在value
中添加“ px”,如注释中所述:
<script type="text/javascript">
$(".rt-container").css("width",$(window).height() +"px");
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.