div高度不会增加以包围子内容

Mo.*_*Mo. 4 html css html5 css3

我在a中创建了一个输入字段 div

div高度是自动可惜searchbar_home div高度不增加包围我的输入框和提交按钮.

这是我的HTML

  <div id='container'>    
    <div id="content">
        <h1 class="home_title">English to Malayalam</h1>
        <div id="searchbar_home">
            <input type="text" />
            <input type="submit" />
        </div>
    </div>
    <footer>
        <p>Copy right only for me ;)</p>
    </footer>

  </div>?
Run Code Online (Sandbox Code Playgroud)

我的CSS:

#searchbar_home{
    margin: 0 auto 20px;
    padding: 10px;
    height: auto;
    width: 80%;
    background: #F5F5F5;
    border: 1px solid #D8D8D8;

    border-radius: 6px;
}
#searchbar_home:after{
    clear: both;
}
#searchbar_home input[type="text"]{
    height: 35px;
    float: left;
    width: 90%;
    border: 1px solid #CCCCCC;
    border-right: none;

    border-radius: 6px 0 0 6px;
}
#searchbar_home input[type="submit"]{
    float: left;
    background: #414141;
    height: 40px;
    width: 50px;
}?
Run Code Online (Sandbox Code Playgroud)

这是关于jsfiddle 的演示.

这里的图像演示

如何让`searchbar_home``div'增加大小?

Tie*_* T. 15

我假设你已经漂浮了你的input.要使div大小适合它,请overflow:auto;为其样式添加规则.

  • 也为了省去一些浪费的行,删除高度:auto; 它什么都不做. (2认同)