2015-11-12 94 views
1

下面的代码以html形式创建两个不同大小的按钮。如何使这些按钮的大小相同?创建相同大小的按钮

<form> 
<input type="button" value="btn""> 
<input type="button" value="superLongButon""> 
</form> 
+0

你的意思是两个按钮应该有相同的宽度? –

+1

设置宽度attr'input {width:200px}' – maioman

+1

对它们应用相同的大小? –

回答

1

创建一个样式类,并在这两个按钮,可以使用它。

.clsButton { 
    //Put your style declaration here 
} 

<form> 
<input type="button" value="btn" class="clsButton"> 
<input type="button" value="superLongButon" class="clsButton"> 
</form> 
1

您可以使用CSS flexbox来实现此行为。

检查下面的例子:

form { 
 
    display: flex; 
 
} 
 
input, 
 
button { 
 
    flex: 1; 
 
}
<form> 
 

 
    <button>small button</button> 
 

 
    <button>this is the bigger button</button> 
 

 
</form> 
 

 
<form> 
 

 
    <input type="button" value="small button"> 
 

 
    <input type="button" value="this is the bigger button"> 
 

 
</form>

+0

完美的解决方案。谢谢。 –

4

使用CSS控制页面上出现的按钮的宽度。

至少有3种方法可以实现您正在尝试做的事情。

1.内联CSS:

<form> 
    <input type="button" style="width:200px;" value="btn""> 
    <input type="button" style="width:200px;" value="superLongButon""> 
</form> 

2.添加一个HTML类和创建该类的CSS规则:

<form> 
    <input type="button" class="frmBtn" value="btn""> 
    <input type="button" class="frmBtn" value="superLongButon""> 
</form> 

然后你在CSS文件中添加此:

.frmBtn { 
    width:200px 
} 

3.仅限CSS(无需编辑您的ht一般应避免

form input[type='button'] { 
    display:inline-block; 
    width:200px; //or as wide as you want them to be 
} 

数1其中尽可能你失去使用外部样式表的一致性和性能优势:毫升)。

+0

您并不严格需要内联块,内联元素也会尊重宽度值。 –

+0

谢谢@Kyll我已经更新了我的答案。 – wf4