简体   繁体   中英

Button width in css3

I have a button and I want it to be a particular size

html

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

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; 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. You could change it to be inline-block or block and then you'll have control over the width.

You need to make your <a> into a block level element. Here's an example of it working .

I just added this to your 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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