【发布时间】:2015-06-04 11:02:29
【问题描述】:
我有 4 个 divs 和 button 类。
有时一个页面可能有 5 个具有该类名的 divs,因此我需要更改它们的宽度以使其适合页面。
这是我的 CSS:
<style>
.button{
width:25%;
}
@media only screen and (max-device-width: 480px) {
.button{
width:100%;
}
}
</style>
这是我的html:
<div id="center">
<div class="button" style=" background: blue; float:left;">test</div>
<div class="button" style=" background: red; float:left;">test</div>
<div class="button" style=" background: purple; float:left;">test</div>
<div class="button" style=" background:orange; float:left;">test</div>
</div>
这是我在 javascript 中的尝试
<script type="text/javascript">
$(document).ready(function() {
if($("#center div").length == 4);
button.style.width = '25%';
}
else{
button.style.width = '20%';
}
});
</script>
但是这个脚本不起作用。
【问题讨论】:
-
你在所有发布的答案中都试过了吗?
标签: javascript css responsive-design width