100% 宽度导致 div 在容器中离开屏幕

Chr*_*ker 1 html css containers twitter-bootstrap

所以我在将容器中的 div 与 Bootstrap 对齐时遇到了一些麻烦。

我想要做的是让 div 在容器宽度内扩展全宽。

它适用于容器的左侧,但不适用于右侧。它离开屏幕。

HTML:

<!-- Image With Action Section -->
    <section class="special_section">
        <div class="container-fluid" style="max-height: 25%">
            <div class="row">
                <div class="col-sm-12">
                    <div class="caption-2">
                        <img src="background-image-url" class="img-full-width img-responsive" alt="" />
                        <div class="container">
                            <div class="action-footer">
                                <div class="col-sm-10">
                                    <h4 class="caption-text">Title</h4>
                                </div>
                                <div class="col-sm-2">
                                    Link
                                </div>
                            </div>
                            <div class="caption">
                                <h4>Title</h4>
                                <p>Content</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
Run Code Online (Sandbox Code Playgroud)

CSS:

.caption-2 .action-footer {
    margin: -1px 0 0 0;
    padding: 10px;
    font-size: 15px;
}
@media (min-width:500px) {
    .caption-2 .action-footer {
        margin:0;
        position: absolute;
        bottom: 0;
        height: 10%;
        width: 100%;
    }
}

.action-footer .col-md-12 {
    margin-top: -10px;
}
Run Code Online (Sandbox Code Playgroud)

.action-footerDIV是,我需要为100%的宽度的父容器内部的一个。相反,它的宽度太大了。

Vic*_*yev 8

您需要应用 CSS 属性 box-sizing: border-box;

.action-footer {
    box-sizing: border-box;
}
Run Code Online (Sandbox Code Playgroud)


Zom*_*der 3

你的主要问题实际上是在这里:

@media (min-width:500px) {
    .caption-2 .action-footer {
        margin:0;
        position: absolute;
        bottom: 0;
        height: 10%;
        width: 100%;
    }
}
Run Code Online (Sandbox Code Playgroud)

将其更改为: position: relative;考虑到您正在为移动设备构建此应用程序,它应该可以完成工作。每当使用container-fluid时,大多数元素都有一个相对位置,因此它们可以与屏幕宽度重新对齐。