我不太擅长 jQuery,因此完整的代码解决方案将是理想的选择。
该函数将:
- 获取浏览器屏幕的 70% 宽度。
- 将该宽度转换为其相应的 px 值
- 设置最大宽度
#mainContainer
使用从转换/计算中获得的值。
这是我要设置的容器的 CSS 样式max-width
with:
#mainContainer {
background-image: url(bg3.jpg);
background-repeat: repeat;
background-color: #999;
width: 70%;
padding: 0;
min-width: 940px; /* 940px absolute value of 70%. */
margin: 0 auto;
min-height: 100%;
/* Serves as a divider from content to the main container */
-webkit-border-radius: 10px;
border-radius: 10px;
}
您应该能够将其复制粘贴到<script>
在页面中任何有 jQuery 的地方添加标签,它应该可以工作。
$( document ).ready( function(){
setMaxWidth();
$( window ).bind( "resize", setMaxWidth ); //Remove this if it's not needed. It will react when window changes size.
function setMaxWidth() {
$( "#mainContainer" ).css( "maxWidth", ( $( window ).width() * 0.7 | 0 ) + "px" );
}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)