html - 搜索输入和按钮未正确水平对齐

标签 html css forms

我正在尝试将表单文本输入和按钮水平对齐在同一行上,同时为按钮提供响应式布局的最小宽度。出于某种原因,最小宽度迫使按钮换行

.search-container{
    width:100%;
    border: 1px solid #000;
    display:block;
 }
.search-text-container {
    width:90%;
    display:inline-block;
}

.search-text-container input {
    width:100%;
    height:30px;
}

.round-icon-container {
    width:10%;
    display:inline-block;
}
.round-icon-button {
    min-width:30px;
    display:block;
    width:30px;
    height:30px;
    line-height:normal;
    border: 2px solid #f5f5f5;
    border-radius: 50%;
    color:#f5f5f5;
    text-align:center;
    text-decoration:none;
    background: #464646;
    box-shadow: 0 0 3px gray;
    font-weight:bold;
}
.round-icon-button:hover {
    background: #262626;
}

<div class="search-container">
    <span class="search-text-container">
        <form action="">
            <input type="text" name="fname" />
        </form>
    </span>
    <span class="round-icon-container">
        <button type="submit" class="round-icon-button">
            <i class="fa fa-search"></i>
        </button>
    </span>
</div>

我对我正在做的事情有一些了解 http://jsfiddle.net/dnssmw83/19/任何帮助将不胜感激

最佳答案

您可以使用 CSS 实现 @media queries像这样:

JSFiddle - DEMO

* {
    box-sizing:border-box;
}
@media(max-width:320px) {
    .search-text-container {
        width:70% !important;
    }
    .round-icon-container {
        width:30% !important;
    }
}
.search-container {
    width:100%;
    border: 1px solid #000;
    display:block;
    font-size: 0; /* to remove the space between inline-block elements */
}
.search-container > span {
    font-size: 16px; /* add the font-size to child span elements */
    vertical-align: middle;
}

关于html - 搜索输入和按钮未正确水平对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26261587/

相关文章:

html - 覆盖跨度样式

jquery - 如何使用jquery应用相同的CSS属性而不覆盖和多次?

html - 如何在 bootstrap 中将文本居中?

java - Alfresco 用于财务数据(表格和数据列表)

Django Taggit - 标记关联未从自定义管理表单中保存

javascript - JQuery:淡入一个addclass?

javascript - jQuery:样式悬停在 parents() 和 children() 上

javascript - 导航栏中的水平图标

php - 如何根据他们所属的用户组为 joomla 网站上的用户名着色?

php - 如何禁用/只读 MultiCheckbox 中的某些复选框?