Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I change the width of html buttons on class level in css? [duplicate]

Tags:

html

css

I want three buttons to each take up 33% of the assigned space. They are grouped in a class "numbers".

When I define the width for the button tags, that works fine, but when I do it for all buttons in the class that they belong to, nothing happens.

html:

<html>
<link rel="stylesheet" href="opmaak.css">
<body>
    <section class="numbers">
        <button type="button" value=1> 1</button>
        <button type="button" value=2> 2</button>
        <button type="button" value=3> 3</button><br>
    </section>
</body>
</html>

css when I do it on button level:

button {
    width: 33%;
}

css when I try it for all buttons of that class:

button.numbers {
    width:33%;
}

Could anyone point out why that is?

button.numbers {
    width: 33%;
}
<html>
<link rel="stylesheet" href="opmaak.css">
<body>
    <section class="numbers">
        <button type="button" value=1> 1</button>
        <button type="button" value=2> 2</button>
        <button type="button" value=3> 3</button><br>
    </section>
</body>
</html>
like image 726
Zegher V Avatar asked Apr 03 '21 10:04

Zegher V


People also ask

How do I fix the width of a button in CSS?

HTML, CSS and JavaScript To set the button width, use the CSS width property.

How do I make buttons wider in CSS?

To increase the height and width of a button, use padding, and then overwrite default value buttons like border and background if you wish by overwriteing the appropriate border values as well as the applicable background values.In addition, to make buttons responsive, you can add a percentage to the width value.

How do I change the height and width of a button in CSS?

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.


1 Answers

This is just an issue with the CSS selector:

button.numbers {
    width:33%;
}

Should be:

.numbers > button {
    width:33%;
}

Each button is a direct child of the .numbers class.

The original selector button.numbers would only select button elements that had a class of numbers (i.e. <button class="numbers" ...>).

like image 165
Martin Avatar answered Oct 26 '22 03:10

Martin