Change Position Of An Element - Responsive Website
How can i change the position of an element from being left to being right in a smaller screen? This is for wider screens: .nav { position:absolute; top: 0px; left: 5%;
Solution 1:
You can set the break points this way(assuming 600 px is the breakpoint between small screen and large screen)
@media screen and (min-width: 601px) {
.nav {
position:absolute;
top: 0px;
left: 5%;
}
}
@media screen and (max-width: 600px) {
.nav {
position:absolute;
right:10px;
}
}
Here is a jsfiddle
update 1
In reference to the updated fiddle provided in the question the newer working code on the above logic will be
@media screen and (max-width: 600px) {
.social-nav {
position:absolute;
right: 10px;
}
.social-navul {
margin: 0;
padding:0;
}
.social-navulli {
list-style: none;
display:block;
background: #393939;
padding:10px10px5px10px;
margin: 1px;
opacity: .5;
transition: all 0.6s ease-in-out;
}
.social-navulli:hover {
opacity: .8;
background:#fff;
}
}
@media screen and (min-width: 600px) {
.social-nav {
background:#000;
width:100%;
position:absolute;
top: 0px;
left: 5%;
}
.social-navul {
margin: 0;
padding:0;
}
.social-navulli {
list-style: none;
display:table-cell;
float: left;
background: #393939;
padding:100px10px5px10px;
margin: 1px;
opacity: .5;
transition: all 0.6s ease-in-out;
}
.social-navulli:hover {
opacity: .8;
background:#fff;
}
.social-navullia {
color:#fff;
}
}
}
Solution 2:
Do you have the viewport meta tag in your header? Your media queries wont work properly without it.
<metaname="viewport"content="width=device-width, initial-scale=1, maximum-scale=1">
Solution 3:
You would need to set a media query for the size, as you would like the browser,to shift the element from left to right at different resolutions .
@media (min-width: 780px) and (max-width: 980px) {
// CSS definition for element(s) at this resolution
}
Of course you will change the min and max to your desired size or you can just set a min width.
Post a Comment for "Change Position Of An Element - Responsive Website"