我需要一个垂直滚动条,指定高度和宽度为%..不在px ..请检查我的网站http://codepen.io/anon/pen/FLlvG的此链接... 我想在左侧内容中滚动条
答案 0 :(得分:0)
如果我理解这里的问题是解决问题的方法之一
<强> HTML 强>
<div id="container">
<div id="sidebar">
<ul>
<li> line 1 </li>
<li> line 2 </li>
<li> line 3 </li>
<li> line 4 </li>
<li> line 5 </li>
<li> line 6 </li>
<li> line 7 </li>
<li> line 8 </li>
<li> line 9 </li>
<li> line 10 </li>
<li> line 11 </li>
<li> line 12 </li>
<li> line 13 </li>
<li> line 14 </li>
<li> line 15 </li>
<li> line 16 </li>
<li> line 17 </li>
<li> line 18 </li>
<li> line 19 </li>
<li> line 20 </li>
</ul>
</div>
<div id="main">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </p>
</div>
</div>
<强> CSS 强>
#container { width:500px; border:3px solid red; margin:0 auto; position:relative; }
#sidebar { position:absolute; left:0; top:0; width:150px; height:100%; background-color:yellow; overflow-y:scroll; }
#main { margin-left:150px; }
p, ul { padding:10px; }
答案 1 :(得分:0)
默认
height
和width
为auto
。对于height
,长度为 由容器的内容决定,对于width
,长度是 由屏幕上可用的水平空间决定。
因此,要在容器中使用百分比(%
)中的height属性,您应该以其他单位(px
,pt
)为父元素指定高度。
修复你的CSS(codepen),如下所示:
.content {height: 150px;}
.leftcontent {height: 50%;}
答案 2 :(得分:0)
检查这个jsfiddle.net/Yajju/。我只在html中添加了内联css。