简体   繁体   English

按钮和输入框的css对齐

[英]css alignment for button and inputbox

I want to display textbox first and then button.But now button appears first.I attached css code and html 我想先显示文本框,然后显示按钮。但是现在按钮首先出现。我附加了CSS代码和html

css
   .search,.stxt{
    float: right;
    }  
html
   <form  method="POST">
     <p style="align:right;">
     <input class="stxt" type="text" name="searchtxt"><a style="padding-right:2ex;"></a>
     <button name="search" class="search">Search</button></p>
   </form>

在此处输入图片说明

The nature of floats will prioritise the first element in the list. 浮点数的性质将优先考虑列表中的第一个元素。 This is why your input text box is to the right. 这就是为什么您的输入文本框在右侧。

I would recommend wrapping your elements within a div and having that float to the right instead. 我建议将您的元素包装在div中,并将其浮动到右侧。

Just move the button before your input text : 只需将按钮移到您输入的文本之前:

<form  method="POST">
     <p style="align:right;">
     <button name="search" class="search">Search</button></p>
     <input class="stxt" type="text" name="searchtxt"><a style="padding-right:2ex;"></a>
</form>

Or the simpliest way is to put the float right on your <p> tag and remove the others float right 或最简单的方法是将浮点数放在您的<p>标记上,并删除其他浮点数

Floating Elements Next to Each Other If you place several floating elements after each other, they will float next to each other if there is room. 浮动元素彼此相邻如果将多个浮动元素彼此并排放置,则如果有空间,它们将彼此相邻浮动。

So add the same class for both elements like below 因此,为两个元素添加相同的类,如下所示

HTML: HTML:

<form  method="POST">
     <p style="align:right;">
     <input class="stxt alignLeft" type="text" name="searchtxt"><a style="padding-right:2ex;"></a>
     <button name="search alignLeft" class="search">Search</button></p>
   </form>

And remove the float:right; 并删除float:right; in the .search,.stxt classes in CSS styles and add the following CSS: 在CSS样式的.search,.stxt类中,并添加以下CSS:

 .alignLeft{
    float: left;
    }  
p{
    margin-left: 290px;
}

Fiddle: http://jsfiddle.net/gvmtuo5j/1/ 小提琴: http : //jsfiddle.net/gvmtuo5j/1/

Alternative: 替代方案:

Try Like this: 像这样尝试:

.search,.stxt{
    float: left;
    }  
p{
    margin-left: 290px;
}

check out this fiddle: http://jsfiddle.net/gvmtuo5j/ 看看这个小提琴: http : //jsfiddle.net/gvmtuo5j/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM