html - 指定百分比的垂直滚动条

标签 html css

我需要一个垂直滚动条,以 % 为单位指定高度和宽度。不是以 px 为单位。请查看我网站上的此链接,http://codepen.io/anon/pen/FLlvG ... 我想要在左侧内容中有一个滚动条

最佳答案

如果我理解这里的问题就是问题的解决方案之一

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; }

DEMO

关于html - 指定百分比的垂直滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24157049/

相关文章:

html - 将一个 div 放置在彼此上方的两个 div 旁边

javascript - 将元素宽度调整为父级滚动条

javascript - 什么时候应该使用 html 中的表单

html - 包含在父 div 中的各种 div 并响应父级大小

html - iOS UIWebView 不缩放内容

css - 在 DIV 中居中文本

javascript - 提示框重新创建自身,直到输入正确的字段

html - 这些天我们应该使用 -moz-border-radius 属性吗?

jQuery 和 CSS - 删除/添加显示 :none

html - 如何仅通过 CSS 选择一些 sibling 而不是全部 sibling ?