html - float 将提交按钮放在 div 之外

标签 html css

我的 css 有一些问题,我有一个内容 ID,然后在其中有一个只是填充的类。在填充类中时,我有一个文本区域和一个提交按钮。默认情况下,提交按钮在左侧:enter image description here 但是当我将提交按钮与内容的左侧或右侧对齐时,它会去那里但它也会超出内容,就像它不再是内容的一部分一样: enter image description here 这些是我的 html 和 css 代码

html:

<div id="content">
        <div class="content-padding">
            <textarea class="content-post" placeholder="Update your status..."></textarea>
            <input type="submit" class="content-submit">
        </div>
    </div>

CSS:

#content {
    width: 60%;
    background: #dddddd;
    color: #000;
    margin: 0 auto;
    border-radius: 4px;
    margin-bottom: 10px;
    height: auto;

}
.content-padding {
    padding: 10px;
}
.content-post {
    width: 97.5%;
    height: 80px;
    border: 0px;
    background: #fff;
    resize: none;
    padding: 10px;
    outline: none;
    margin-bottom: 5px;
    border-radius: 4px;
}
.content-submit {
    background: #005ddb;
    width: 70px;
    height: 30px;
    border: 0px;
    border-radius: 4px;
    color: #fff;
    outline: none;
    cursor: pointer;
    float: right;
}

希望有人能尽快帮我解决这个问题,谢谢!

最佳答案

需要触发.content-padding的布局或者添加清空元素。

.content-padding {
    padding: 10px;
    overflow:hidden ; /* minds inside and outside floatting elements, fine if no size given */
}

或生成的清算元素。

.content-padding:after {
    content:'';
    display:block; /* or whatever else than inline */
   clear:both;
}

了解有关 float 元素的更多信息:http://css-tricks.com/all-about-floats/

关于html - float 将提交按钮放在 div 之外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24873761/

相关文章:

html - 如何确定 HTML5 播放器是否在浏览器中运行?

javascript - Pnotify - 在模态背景上显示通知

html - 如何保持 CSS3 动画的状态悬停?

css - 通过 CSS 选择背景图片,有什么区别?

带有 + 和 - 符号的 css 切换

html - 文本在 html 中围绕多边形边缘流动

html - 影响 HTML 链接元素中的 SVG 图标和文本内容的悬停效果

java - html 页面拒绝应用样式 bootstrap.min.css

html - Cufon 字体替换 : How do you define "hoverables"

css - 适用于平板电脑、台式机和手机的响应列。 Bootstrap