用百分比制作滚动div

时间:2013-10-19 09:45:59

标签: css3 html scroll

我正在尝试使用百分比创建垂直滚动div,因为我正在针对不同的设备高度进行开发 但是,当我放置像素时,我工作,但当我按百分比时,它不适用

请看示例     

<div data-role="content"  >
    <div id="divChat" > 
    <div style="text-align:center"><div Class="ChatDate">2013-07-07</div></div>
    <div class="admin">Goal! Man city 1- Chealse 1<br/><span class="Time">16:42</span>     </div>

            <div class="bubble you"><div class="youName">Omer</div>Here?<br/>  <span class="Time">16:42</span></div>
                  <div class="bubble me">yes<br/><span class="Time">16:42</span></div>
         <div class="bubble me">yes<br/><span class="Time">16:42</span></div>
         <div class="bubble me">yes<br/><span class="Time">16:42</span></div>
         <div class="bubble me">yes<br/><span class="Time">16:42</span></div>
         <div class="bubble me">yes<br/><span class="Time">16:42</span></div>
         <div class="bubble me">yes<br/><span class="Time">16:42</span></div>
                     <div style="text-align:center"><div Class="ChatDate">2013-07-07</div></div>
    <div class="admin">Goal! Man city 1- Chealse 1<br/><span class="Time">16:42</span></div>

            <div class="bubble you"><div class="youName">Omer </div>Here?<br/><span class="Time">16:42</span></div>
                  <div class="bubble me">yes<br/><span class="Time">16:42</span></div>
    </div>
 <div data-role="footer"  style="bottom:0; position:absolute; left:0; width:100%">
    <div class="ui-grid-a"  > 
      <div class="ui-block-a" style="width:70%; padding-left:2px; ">
        <div data-role="fieldcontain"style=" padding:0px " >


        <textarea  data-mini="true"  data-role="none" style="width:90%; height:33px" data-theme="d"  name="chat_message" id="chat_message"  placeholder="Insert message here"></textarea>           </div>
      </div>
      <div class="ui-block-b" style="width:30%">

      </div>
    </div>
    </div>

我希望“divChat”处于固定高度并滚动 http://jsfiddle.net/vHLYj/

1 个答案:

答案 0 :(得分:0)

您可以在#divChat中添加内联块,如下所示:

#divChat {
   margin-top:2px;
   overflow-y:scroll; 
   height:50%;
   display: inline-block;
}

请注意,IE7等旧浏览器不支持内联块。

在以下位置查看兼容性:

http://caniuse.com/inline-block