小编典典

Calc()替代带有内容的固定边栏?

css

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

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

阅读 408

收藏
2020-05-16

共1个答案

小编典典

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

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

要么

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

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

片段

.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>

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

.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>
2020-05-16