Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i change the left margin of a div when the window is resized?

I want to place the red border div,on the left where the green border is,when the window is resized.
Currently the div has the following css rules:

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

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

I solved the problem:

window.onresize = function(event) {
    var elem = document.getElementById("twitter-2");
    elem.setAttribute("style","margin: 20px 1px;");
}
like image 430
Iliescu Alex Avatar asked Mar 20 '13 12:03

Iliescu Alex


1 Answers

you can use media queries

and test your site by re-sizing the window

adjust what you want on which device and always try to play with %'s not px's

Some media queries for you 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 */
}
like image 171
Sahil Popli Avatar answered Sep 17 '22 19:09

Sahil Popli