How to set the size of button in HTML

2020-02-21 05:16发布

I have some buttons on my pure HTML/JS page. When the page is opened in browser, the button size is normal. But on refresh/reloading page, the button size is reduced. In fact, I have not set the button text value. The button's text is blank. How should I set the size of my button in HTML irrespective to the size of the text?

标签: html button
4条回答
Evening l夕情丶
2楼-- · 2020-02-21 05:27
button { 
  width:1000px; 
} 

or even

 button { 
    width:1000px !important
 } 

If thats what you mean

查看更多
叼着烟拽天下
3楼-- · 2020-02-21 05:38

Do you mean something like this?

HTML

<button class="test"></button>

CSS

.test{
    height:200px;
    width:200px;
}

If you want to avoid CSS, see this:

<button style="height:200px;width:200px"></button>
查看更多
够拽才男人
4楼-- · 2020-02-21 05:45

If using the following HTML:

<button id="submit-button"></button>

Style can be applied through JS using the style object available on an HTMLElement.

To set height and width to 200px of the above example button, this would be the JS:

var myButton = document.getElementById('submit-button');
myButton.style.height = '200px';
myButton.style.width= '200px';

I believe with this method, you are not directly writing CSS (inline or external), but using JavaScript to programmatically alter CSS Declarations.

查看更多
何必那么认真
5楼-- · 2020-02-21 05:50

This cannot be done with pure HTML/JS, you will need CSS

CSS:

button {
     width: 100%;
     height: 100%;
}

Substitute 100% with required size

This can be done in many ways

查看更多
登录 后发表回答