如何順利地更改div的位置,作出響應?如何使div響應
HTML:
<div class="icon">
<i class="fa fa-search toggle_icon"></i>
</div>
<div class="sidenav">
<center>
<input id="provider-json" />
</center>
</div>
CSS:
.icon {
position: absolute;
top: 30%;
left: 0;
width: 50px;
height: 50px;
background: #d54042;
}
.sidenav {
position: absolute;
top: 30%;
left: 52px;
height: 50px;
width: 200px;
border-top-right-radius: 8px;
border-bottom-right-radius: 8px;
background: #d54042;
background: -webkit-linear-gradient(left, #D54042 , #D56769);
background: -o-linear-gradient(right, #D54042, #D56769);
background: -moz-linear-gradient(right, #D54042, #D56769);
background: linear-gradient(to right, #D54042 , #D56769);
}
#provider-json {
margin-top: 6px;
padding: 10px 5px;
border-radius: 3px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
border:solid 1px #ccc;
-moz-box-shadow: inset 0 0 4px rgba(0,0,0,0.2);
-webkit-box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.2);
box-shadow: inner 0 0 4px rgba(0, 0, 0, 0.2);
outline-color: #d54042;
}
.toggle_icon {
font-size: 2.5em;
color: white;
padding: 3px 3px 2px 5px;
}
我想verticaly改變.icon和.sidenav的位置。 當我使屏幕變小時,應該順利地到頂部:0;
我嘗試這樣做:
@media screen and (max-width: 480px) {
.icon, .sidenav {
top: 5%;
}
}
但這隻能當屏幕480像素寬。
如果您想檢查其他尺寸,請更改媒體查詢中的「最大寬度」 – Swellar