javascript - 在 HTML5 和 CSS3 中对齐下拉列表和输入框

标签 javascript html css

我有一个下拉列表,其中选择了一个列表并将其输入到输入框中。但是,下拉列表未与输入框正确对齐。我在下面展示代码。

下面是 HTML 5 代码

<form class="form" action="put.php" method="post" name="access_form">
<li>
     <label for="firstname">First Name</label>
      <input name="firstname" id="keyword" type="text" placeholder="type first name (required)" required />
     <div id="results">
	<div class="item">abc</div>
	<div class="item">def</div>
	<div class="item">hij</div>
</div>

</li>
</form>

下面是css代码

.form label {
    width:150px;
    margin-top: 3px;
    display:inline-block;
    float:left;
    padding:3px;
}

.form input {
    height:20px; 
    width:220px; 
    padding:5px 8px;
}



#results {
	width: 204px;
        display: none;
	display: absolute;
	border: 1px solid #c0c0c0;
}

#results .item {
	padding: 3px;
	font-family: Helvetica;
	border-bottom: 1px solid #c0c0c0;
}

但只要我运行代码,我就会得到以下对齐方式

the drop down list is out of line with the input box

现在,如何对齐下拉框和输入框以使其相互匹配。

最佳答案

如果我没理解错的话,你希望输入在下一行,与下面的列表对齐:

.form label {
    display:block;}

.form input {
    display:block;}

关于javascript - 在 HTML5 和 CSS3 中对齐下拉列表和输入框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31318925/

相关文章:

python - Django:显示管理站点的换行符?

javascript - 通过 css 删除 div 的用户脚本

html - 将页脚换行扩展到页面宽度

javascript - 引用错误 : invalid assignment left-hand side in console

html - 使用 HTML 符号实体代替实际符号

HTML/CSS : Make a wrapper extend to fit the height of its children

css - 制作一个按钮样式的 Angular 组件( Angular Material )

html - Div 标签在 IE 中不展开 .. 在所有其他浏览器中正常

javascript - 代码镜像 html 在 chrome 中不起作用,但在其他浏览器中起作用

javascript - 按相同元素对数组对象求和