简体   繁体   English

css3中的按钮宽度

[英]Button width in css3

I have a button and I want it to be a particular size 我有一个按钮,我希望它是一个特定的大小

html HTML

<a class="button icon Raise"
onclick="raiseButtonAction(realPlayer, gameState)" id="nupp1" href="#"><span>RAISE</span></a>

css CSS

.button {
position: absolute;
border-top: 1px solid #96d1f8;
background: #65a9d7;
background: -webkit-gradient(linear, left top, left bottom, from(#3e779d),
    to(#65a9d7) );
background: -moz-linear-gradient(top, #3e779d, #65a9d7);
padding: 5px 10px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
-webkit-box-shadow: rgba(0, 0, 0, 1) 0 1px 0;
-moz-box-shadow: rgba(0, 0, 0, 1) 0 1px 0;
box-shadow: rgba(0, 0, 0, 1) 0 1px 0;
text-shadow: rgba(0, 0, 0, .4) 0 1px 0;
color: white;
font-size: 19px;
font-weight: bold;
font-family: Segoe;
text-decoration: none;
vertical-align: middle;

But if I put for example width:100px; 但是,如果我举例如宽度:100px; it doesn't change in size. 它的大小没有变化。 Am I doing something wrong or you just can't change the size of a premade button? 我做错了什么或者你不能改变预制按钮的大小?

Try this.. 试试这个..

.button {
display:inline-block;
min-width: 50px;
width: 80px;
padding:5px 10px;

}

That style is on an a element, which is an inline and won't accept a width. 该样式a元素上,该元素是内联的,不接受宽度。 You could change it to be inline-block or block and then you'll have control over the width. 您可以将其更改为inline-blockblock ,然后您可以控制宽度。

You need to make your <a> into a block level element. 您需要将<a>转换为块级元素。 Here's an example of it working . 这是一个有效的例子

I just added this to your CSS for .button: 我刚将这个添加到你的CSS for .button:

display: block;
width: 200px;
text-align: center;

Missing 失踪

display: block; 显示:块;

Have to set display to block if you want to set a fixed width on an inline element 如果要在内联元素上设置固定宽度,则必须将显示设置为阻止

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

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