Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resizing a button

I have a "button" that I wish to use all throughout my site, but depending on where in the site the button is, I want it to display at different sizes.

In my HTML I have tried (but its not working):

<div class="button" width="60" height="100">This is a button</div>

And the matching CSS:

.button {
  background-color: #000000;
  color: #FFFFFF;
  float: right;
  padding: 10px;
  border-radius: 10px;
  -moz-border-radius: 10px;
  -webkit-border-radius: 10px;
}

I assumed that if each time I call this class I can just pass in a size and hey-presto!....but not....

By adding the width and height as I call the button class seems to do nothing to the size of it. Does anyone know how I can do this? And if I put the width and height in the CSS then the button will be the same size everywhere.

like image 692
heyred Avatar asked Jul 27 '12 14:07

heyred


People also ask

How do you make a button smaller in CSS?

Pure CSS Button Sizes class: There is no predefined class for button size we have to do that by using CSS. Button Size percentage depends on the parent: button-xsmall: This class is used to create extra small buttons (70%). button-small: This class is used to create small buttons (85%).

How do you change the font size on a button in HTML?

In the case of a button click, use the DOM to access the <div> tag for changing the value of the font-size attribute from javascript itself. In the case of moving the slider, again use DOM to access the value of the slider that has been set by the user and use this value as the font-size value for the <div> tag.

What properties are needed to change button size?

To set the button width, use the CSS width property.


2 Answers

You should not use "width" and "height" attributes directly, use the style attribute like style="some css here" if you want to use inline styling:

<div class="button" style="width:60px;height:30px;">This is a button</div>

Note, however, that inline styling should generally be avoided since it makes maintenance and style updates a nightmare. Personally, if I had a button styling like yours but also wanted to apply different sizes, I would work with multiple css classes for sizing, like this:

   .button {
        background-color: #000000;
        color: #FFFFFF;
        padding: 10px;
        border-radius: 10px;
        -moz-border-radius: 10px;
        -webkit-border-radius: 10px;
        margin:10px
    }
    
    .small-btn {
        width: 50px;
        height: 25px;
    }
    
    .medium-btn {
        width: 70px;
        height: 30px;
    }
    
    .big-btn {
        width: 90px;
        height: 40px;
    }
    <div class="button big-btn">This is a big button</div>
    <div class="button medium-btn">This is a medium button</div>
    <div class="button small-btn">This is a small button</div>
 

jsFiddle example

Using this way of defining styles removes all style information from your HTML markup, which in will make it easier down the road if you want to change the size of all small buttons - you'll only have to change them once in the CSS.

like image 181
Anders Arpi Avatar answered Dec 01 '22 00:12

Anders Arpi


If you want to call a different size for the button inline, you would probably do it like this:

<div class="button" style="width:60px;height:100px;">This is a button</div>

Or, a better way to have different sizes (say there will be 3 standard sizes for the button) would be to have classes just for size.

For example, you would call your button like this:

<div class="button small">This is a button</div>

And in your CSS

.button.small { width: 60px; height: 100px; }

and just create classes for each size you wish to have. That way you still have the perks of using a stylesheet in case say, you want to change the size of all the small buttons at once.

like image 29
Rampant Creative Group Avatar answered Dec 01 '22 00:12

Rampant Creative Group