在响应式布局中设置元素高度? [英] Setting element height in responsive layout?

查看:45
本文介绍了在响应式布局中设置元素高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一般来说,什么标记和 CSS 会在响应式设计中创建一个基于百分比的高度的元素?如何构建 2 列(固定- Fluid) Layout with Twitter Bootstrap? 展示了如何创建两个 100% 高度的列,但这会破坏高度 <100%.

具体来说,我有一个带有项目列表的侧边栏 div,它可能很短(空)或很长(overflow: auto).但是因为没有父元素有固定的高度,height: 20%; 不起作用.如何在保持响应式设计的同时为侧边栏提供流畅的高度?

解决方案

通常在父容器上有一个流体填充底部可以解决这个问题.

更多信息可以在这里找到:http://www.alistapart.com/articles/creating-intrinsic-ratios-for-video/

更新:在js bin http://jsbin.com/obesuk/1/

标记:

<div class="content">content</div>

CSS:

 .obj-wrapper {位置:相对;宽度:50%;填充底部:40%;高度:0;溢出:隐藏;}.内容 {位置:绝对;宽度:100%;高度:100%;背景:红色;}

Generally, what markup and CSS will create an element with a percentage-based height in a responsive design? How to build a 2 Column (Fixed - Fluid) Layout with Twitter Bootstrap? shows how to create two 100% height columns, but this breaks for heights < 100%.

Specifically, I have a sidebar div with a list of items, which may be short (empty) or long (overflow: auto). But because no parent elements have a fixed height, height: 20%; does not work. How can I give the sidebar a fluid height while maintaining a responsive design?

解决方案

Usually having a fluid padding-bottom on the parent container solves this problem.

More information can be found here : http://www.alistapart.com/articles/creating-intrinsic-ratios-for-video/

update: on js bin http://jsbin.com/obesuk/1/

markup :

<div class="obj-wrapper">
 <div class="content">content</div>
</div>

css:

  .obj-wrapper {
    position:relative;
    width:50%;
    padding-bottom:40%;
    height:0;
    overflow:hidden;
  }
  .content {
    position:absolute;
    width:100%;
    height:100%;
    background:red;
  }

这篇关于在响应式布局中设置元素高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆