可滚动的DIV,可根据页面宽度进行调整

时间:2012-10-11 18:02:15

标签: css html position

我有一个我想要滚动的DIV,但问题是我正在使用position:fixed;并且DIV不会调整它与页面其余部分的位置;因此在小分辨率上消失了。任何建议都会很棒。

这是目前的DIV:

<div style="
display: block; 
top: 200px; 
left: 1500px; 
width: 130px; 
position: fixed; 
border: 1px solid rgb(136, 136, 136); 
padding: 10px; 
text-align: center; 
font-weight: bold; 
color: rgb(255, 255, 255); 
background-color:#FFFFFF;
">

1 个答案:

答案 0 :(得分:0)

使用percentages.eg:top:20%代替top:1200px,而不是使用顶部和左侧属性的像素。在较小的分辨率中,左上角的值会使div离开屏幕。试试这个

display: block; 
top: xx%; 
left: nn%; 
width: mm%; 
position: fixed; 
border: 1px solid rgb(136, 136, 136); 
padding: 10px; 
text-align: center; 
font-weight: bold; 
color: rgb(255, 255, 255); 
background-color:#FFFFFF;

根据您的潜水尺寸调整您的百分比值。 一面注意事项如果您要定位移动设备,也可以使用媒体查询,例如。

@media all and (max-width: 699px) and (min-width: 520px), (min-width: 1151px) {
  #myDivId{
   width: 100px; /* or width:10%; */
  }
}
相关问题