html - 论坛输入 100% 宽度

标签 html css

我无法在搜索表单中将输入宽度设置为 100%。 我不确定我做错了什么。尝试在所有可能的地方设置 100%,但只有当我设置大小 px 时才会发生变化。

http://jsfiddle.net/26Gmz/

.searchInput {
    background: none repeat scroll 0 0 #FFFFFF;
    border: 1px solid #CCCCCC;
    border-radius: 5px;
    display: table-cell;
    height: 29px;
    padding: 0 4px;
    vertical-align: middle;
    width: 100%;
}


.searchIn {
    -moz-appearance: none;
    -moz-box-sizing: border-box;
    background: none repeat scroll 0 0 rgba(0, 0, 0, 0);
    border: 0 none;
    font-size: 15px;
    margin: 0;
    outline-width: 0;
    padding-left: 4px;
    width: 97%;
}

                <form method="post">
                        <div class="searchEn">
                                <input type=hidden name="do" value=search>
                                <input type="hidden" name="subaction" value="search" />
                                <div class="searchInput">
                                        <input class="searchIn" name="story" width="100%" type="text" />
                                </div>

                        </div>
                </form>

最佳答案

我认为您可以通过将 .searchInputdisplay 规则更改为 block(然后是 宽度98%) 像这样 ( demo )

.searchInput {
    background: none repeat scroll 0 0 #FFFFFF;
    border: 1px solid #CCCCCC;
    border-radius: 5px;
    display: block;
    height: 29px;
    padding: 0 4px;
    vertical-align: middle;
    width: 98%;
}

或者为了更完整的修复(解决一堆填充和宽度问题),您可以使用此 CSS ( demo )(更改已注释)

.searchEn {
    background-image: linear-gradient(to bottom, #FFFFFF 0px, #DFDFDF 100%);
    border-radius: 5px;
    color: #000000;
    /*Push the right side over slightly more*/
    padding: 4px 6px 4px 4px;
}
.searchInput {
    background: none repeat scroll 0 0 #FFFFFF;
    border: 1px solid #CCCCCC;
    border-radius: 5px;
    display: block;
    height: 29px;
    /*Remove padding from this element (now in the parent element)*/
    padding: 0;
    vertical-align: middle;
    /*These can be full width if you fix the padding on the parent element*/
    width: 100%;
}
.searchIn {
    -moz-appearance: none;
    -moz-box-sizing: border-box;
    background: none repeat scroll 0 0 rgba(0, 0, 0, 0);
    border: 0 none;
    font-size: 15px;
    margin: 0;
    outline-width: 0;
    padding-left: 4px;
    /*Center the input box better inside the container*/
    padding-top: 6px;
    /*And make the input full width*/
    width: 100%;
}

关于html - 论坛输入 100% 宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20182813/

相关文章:

html - border-bottom 没有按预期工作

php - 我如何为由 php 代码生成的奇数行和偶数行使用 Jquery 选择器?

html - 页脚位置不会粘在底部

javascript - 使用 javascript 切换禁用属性

javascript - 短脚本(<50 行)适用于 jfiddle 但不适用于浏览器

php - 固定页眉和页脚不允许页面内容滚动?

html - 部分图片未显示

javascript - 在同一个 Chrome 应用程序窗口中打开 HTML 文件?

css - 如何在 bootstrap-vue modal[b-modal] 上创建过渡/动画

javascript - 自动更新对网页上其他标题的引用