5

ウィンドウのサイズが変更されたときに、緑の境界線がある左側に赤い境界線のdivを配置したいと思います。
現在、div には次の CSS ルールがあります。

#twitter-2 { 
width: 332px; 
background-color: #7E7D7D; 
opacity: 0.6; 
margin-left:525px; 
margin-top:-142px; 
}

http://imageshack.us/download/20/changemargin.jpg

私は問題を解決しました:

window.onresize = function(event) {
    var elem = document.getElementById("twitter-2");
    elem.setAttribute("style","margin: 20px 1px;");
}
4

3 に答える 3

4

メディアクエリを使用できます

ウィンドウのサイズを変更してサイトをテストします

どのデバイスで何をしたいのかを調整し、常にpxではなく%でプレイするようにしてください

いくつかのメディア クエリ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-20T12:56:18.920 に答える
1

次のように試してください

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-20T12:57:58.770 に答える
1

左右にフロートするよりも、ライン全体をコンテナに置くだけで、スペースが小さすぎると、ボックスが自然に下に入ります。

<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}
于 2013-03-20T13:00:29.090 に答える