我想在调整窗口大小时,将红色边框div放在绿色边框所在的左侧。
目前div有以下css规则:
#twitter-2 {
width: 332px;
background-color: #7E7D7D;
opacity: 0.6;
margin-left:525px;
margin-top:-142px;
}

我解决了这个问题:
window.onresize = function(event) {
var elem = document.getElementById("twitter-2");
elem.setAttribute("style","margin: 20px 1px;");
}发布于 2013-03-20 20:56:19
您可以使用媒体查询
并通过调整窗口大小来测试站点
在哪个设备上调整你想要的,并且总是尝试播放%s而不是px
您的一些媒体查询Thanks to Chris
/* Smartphones (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
@media only screen
and (min-width : 321px) {
/* Styles */
}
/* Smartphones (portrait) ----------- */
@media only screen
and (max-width : 320px) {
/* Styles */
}
/* iPads (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* Styles */
Like This
#twitter-2 {
margin-left:Some Value ;
margin-top:Some Value ;
}
}
/* iPads (landscape) ----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape) {
/* Styles */
}
/* iPads (portrait) ----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : portrait) {
/* Styles */
}
/* Desktops and laptops ----------- */
@media only screen
and (min-width : 1224px) {
/* Styles */
}
/* Large screens ----------- */
@media only screen
and (min-width : 1824px) {
/* Styles */
}
/* iPhone 4 ----------- */
@media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* Styles */
}发布于 2013-03-20 20:57:59
像这样试一试
CSS
.red {
width: 332px;
background-color: #7E7D7D;
opacity: 0.6;
margin-left:525px;
margin-top:-142px;
}
.green {
width: 332px;
background-color: #7E7D7D;
opacity: 0.6;
margin-left:25px;
margin-top:-342px;
}假设您的twitter-2 div当前具有class red
在window.resize function上
$(window).resize(function(){
$('#twitter-2').addClass('green').removeClass('red');
});此外,您还可以根据需要针对不同的width执行此操作。
阅读http://api.jquery.com/resize/
发布于 2013-03-20 21:00:29
只需将整条线放在一个容器上,而不是左右浮动,当空间太小时,盒子就会自然地移到下面。
<div class="row">
<div class="follow">keep in touch</div>
<div class="tweet-update">bla bla</div>
</div>
.follow {float:left; margin-bottom:30px;}
.tweet-update {float:right}https://stackoverflow.com/questions/15524048
复制相似问题