Calc()替代带有内容的固定边栏? [英] Calc() alternative to fixed side bar with content?

查看:93
本文介绍了Calc()替代带有内容的固定边栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在左侧和右侧的内容区域都有一个固定的侧栏.除了calc()以外,还有其他方法可以计算内容宽度吗?我想要一种浏览器更安全的方法.

I have a fixed side bar on the left and a right content area. Is there an alternative to calculating the content width other than calc()? I wanted a more browser safe method.

.left-sidebar {
        width: 160px;
        height: 100%;
        border-right: 1px solid black;
        position: fixed;
        top: 72px;
 }

.right-content {
    position: absolute;
    left: 160px;
    top: 72px;
    width: calc(100% - 160px);
    overflow: hidden;
}

推荐答案

我已经做了一个类似的示例,我想分享一下.在这种情况下,您需要使用定位.这是固定流体的情况:

I have already done a similar example, which I would like to share. You need to use positioning for this case. This is a case of fixed-fluid:

+-------+-----------+
| FIXED | FLUUUUUID |
+-------+-----------+

+-------+-----------+
| FIXED | FLUUUUUID |
|       | FLUUUUUID |
+-------+-----------+

固定流体模型.在我的代码片段中,我演示了两种示例.在第一种情况下,流体的尺寸较小.而且下一个内容太长.

Fixed-Fluid Model. In my snippet, I have demonstrated two kinds of examples. In the first case, the fluid is less in size. And the next has too long content.

代码段

.parent {position: relative; margin: 0 0 15px; border: 1px solid #999; padding: 5px; padding-left: 100px;}
.parent .fixed {position: absolute; left: 5px; width: 90px; background-color: #99f;}
.parent .fluid {background-color: #f99;}

<div class="parent">
  <div class="fixed">Fixed</div>
  <div class="fluid">Fluid</div>
</div>

<div class="parent">
  <div class="fixed">Fixed</div>
  <div class="fluid">Fluid Lorem ipsum dolor sit amet, consectetur adipisicing elit. Itaque animi placeat, expedita tempora explicabo facilis nulla fuga recusandae officia, maiores porro eaque, dolore et modi in sapiente accusamus id aut.</div>
</div>

为了获得更好的固定液,我为您做了同样的处理:

For a better fixed fluid, I have done with the same kind for you:

.main-content {border: 1px solid #999; padding: 5px; position: relative; min-height: 200px; padding-left: 125px;}
.left-sidebar {position: absolute; left: 0; top: 0px; width: 120px; background-color: #eee; height: 100%;}

<div class="main-content">
  <div class="left-sidebar"></div>
  <div class="right-fluid">
    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsum libero iure facere quam iste, nostrum laborum in, dolorum beatae optio rem explicabo voluptates qui quos eius accusamus! Accusamus blanditiis, et!
  </div>
</div>

这篇关于Calc()替代带有内容的固定边栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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