【问题标题】:100% width div with box shadow ovelaps parent div带框阴影的 100% 宽度 div 与父 div 重叠
【发布时间】:2012-12-31 03:35:16
【问题描述】:

我有一个居中的容器 div,其中当前有 3 个其他 div。它们都有盒子阴影(因此添加了大约 5px 的边距)。

我遇到的问题是第一个 div(upcoming) 是 100% 宽度并且在右侧被切断(overflow: hidden 已设置)。或者它溢出它包含一点 div 。这没关系,但下面的其他 2 个 div 浮动并并排,因此不会溢出一点(如果 size 设置为超过可用空间,则最近的 div 移动到 latest 之下)。

填充没有帮助。除了将宽度设置为 98% 之外,还有其他解决方案吗?

这是我正在使用的 css:

.mainSection{
    width:1020px;
    margin:70px auto 0px auto;
}

.widget{
    background-color:rgba(255, 255, 255, 0.5);
    -webkit-box-shadow:0 0 5px 2px #CCC;
    -moz-box-shadow:0 0 5px 2px #CCC;
    box-shadow:0 0 5px 2px #CCC;
    border:1px solid #CCC;
    margin:4px;
    overflow:hidden;
}

/* 3 child divs */

.widget.upcoming{
    float:left;
    width:100%;
    height:380px;
}

.widget.recent{
    float:right;
    width:260px;
    height:auto;
}

.widget.latest{
    float:left;
    width:740px;
    height:460px;
}

<section class="mainSection">
    <article class="widget upcoming">
        <header>
            <h3>Upcoming</h3>
        </header>
    </article>
    <article class="widget news">
        <article>
            <p>Some text</p>
        </article>
    </article>
    <article class="widget latest">
        <header>
            <h3>Latest</h3>
        </header>
    </article>
    <aside class="widget recent">
        <header>
            <h3>Recent</h3>
        </header>
    </aside>    
</section>

【问题讨论】:

  • 是的,请 html,我正在努力提供帮助,如果更多信息会很棒jsbin.com/uharax/1
  • 在 jsbin 示例中,您可以看到问题(为清楚起见,在 .recent 上设置 px 高度)。 .upcoming div 比它下面的 div 长。

标签: css-float css fluid-layout


【解决方案1】:

所以如果我们改变改变

.widget.upcoming{
   float:left;
   width:100%;
   height:380px;
}

 .widget.upcoming{
    height:380px;
 }

我觉得应该可以

http://jsbin.com/uharax/1

【讨论】:

  • 似乎有效,但它会一直扩展到 100% 吗?我的意思是现在它只能缩放,因为默认情况下文本是 100%。如果我只有固定宽度/高度的 div 并且没有文本怎么办?
  • 实际上,它似乎工作得很好,因为里面的元素有自动边距。
  • 太棒了,真的很高兴它对你有用。只是我在玩它,jsbin.com/uharax/5。如果要将宽度设置为 100% 并将其浮动到左侧,只需删除边距:4px;形成 .widget 因为它增加了元素周围的大小。我们也可以使用 box-sizing ,这样边框就在元素宽度之内。里面还加了一些盒子。检查示例。祝你有美好的一天:)
  • 需要边距或阴影被切断或与其他阴影重叠。我可能会为此使用同位素 jquery 插件...
猜你喜欢
  • 2020-08-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-04
  • 2013-01-02
  • 2011-01-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多