CSS: Почему эти кнопки не принимают фиксированную ширину и высоту, которые я установил? - PullRequest
0 голосов
/ 02 февраля 2020

Я пытаюсь сделать эти кнопки фиксированного размера. Это ширина 42px и высота 25px. По некоторым причинам они не правильного размера. Просто стандартный. Я искал решения, но не смог найти его, к сожалению. Извините, если мой код немного запутан, я новичок и пытаюсь заставить что-то работать :)

Вот код HTML и CSS

    <!DOCTYPE html>
<html>
<head>
    <title>Super epic game</title>
    <link rel="stylesheet" type="text/css" href="mainstyles.css">
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <link href="https://fonts.googleapis.com/css?family=Lato:300&display=swap" rel="stylesheet">
    <meta name="viewport" content="width=device-width, initial-scale=0.45"> 
</head>

<body>

<div class="container">
        <div id="speelkader"> <canvas  id="canvas" style="background-color: black;"></canvas></div>
        <div id="attributen">
                <button id="rood" class="color-changer" data-color="red">Rood</button>
                <button id="groen" class="color-changer" data-color="green">Groen</button>
                <button id="blauw" class="color-changer" data-color="blue">Blauw</button>
                <button id="paars" class="color-changer" data-color="purple">Paars</button>
                <button id="oranje" class="color-changer" data-color="orange">Oranje</button>
                <button id="geel" class="color-changer" data-color="yellow">Geel</button>
                <button id="wit" class="color-changer" data-color="white">Wit</button>
                <button id="gum" class="color-changer" data-color="black">Gum</button>
                <input type="button" id="reset" value="Reset tekening" onClick="window.location.reload()">
                <div id="clear"></div>
        </div>
</div>




<p id="center">Hallo! Gebruik de WASD toetsen om te bewegen :)</p>




<script src="gameJS.js"></script>

</body>
</html>

CSS

* 
{
    margin: 0;
    padding: 0;
}
.container{
    width: 1359px;
    margin: auto;
}
#speelkader{ 

    margin-top: 20px;
    background-color: transparent;
    float: left;
    padding-right: 10px;
}

#attributen{
    margin-top: 20px;
    background-color: gray;
    width: 500px;
    height: 800px;
    float: left;
}

#clear {
    clear: both;
}

canvas{
    background-color: black;
    height: 800px;
    width:  800px;
}


#groen{
    background-color: green; 
    color: white;
    width: 42px;
    height: 25px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    -webkit-transition-duration: 0.1s;
    transition-duration: 0.1s;
    font-family: Lato;
    border-color: black;
    border-style: solid;
    margin: 10px 10px 10px 10px;
}
#groen:hover{
    background-color:darkgreen; 
    color: white;        
    transform: scale(1.15);
}

#rood{
    background-color: red; 
    color: white;
    width: 42px;
    height: 25px;       
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    -webkit-transition-duration: 0.1s;
    transition-duration: 0.1s;
    font-family: Lato;
    border-color: black;
    border-style: solid;
    margin: 10px 10px 10px 10px;
}
#rood:hover{
    background-color:darkred; 
    color: white;        
    transform: scale(1.15);
}

#blauw{
    background-color: blue; 
    color: white;
    width: 42px;
    height: 25px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    -webkit-transition-duration: 0.1s;
    transition-duration: 0.1s;
    font-family: Lato;
    border-color: black;
    border-style: solid;
    margin: 10px 10px 10px 10px;
}
#blauw:hover{
    background-color:darkblue; 
    color: white;        
    transform: scale(1.15);
}

#paars{
    background-color: purple; 
    color: white;
    width: 42px;
    height: 25px;   
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    -webkit-transition-duration: 0.1s;
    transition-duration: 0.1s;
    font-family: Lato;
    border-color: black;
    border-style: solid;
    margin: 10px 10px 10px 10px;
}
#paars:hover{
    background-color:rgb(92, 0, 92); 
    color: white;        
    transform: scale(1.15);
}

#oranje{
    background-color: orange; 
    color: white;
    width: 42px;
    height: 25px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    -webkit-transition-duration: 0.1s;
    transition-duration: 0.1s;
    font-family: Lato;
    border-color: black;
    border-style: solid;
    margin: 10px 10px 10px 10px;
}
#oranje:hover{
    background-color:darkorange; 
    color: white;        
    transform: scale(1.15);
}

#geel{
    background-color: yellow; 
    color: white;
    width: 42px;
    height: 25px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    -webkit-transition-duration: 0.1s;
    transition-duration: 0.1s;
    font-family: Lato;
    border-color: black;
    border-style: solid;
    margin: 10px 10px 10px 10px;
}
#geel:hover{
    background-color:rgb(233, 233, 0); 
    color: white;        
    transform: scale(1.15);
}

#wit{
    background-color: white; 
    color: black;
    width: 42px;
    height: 25px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    -webkit-transition-duration: 0.1s;
    transition-duration: 0.1s;
    font-family: Lato;
    border-color: black;
    border-style: solid;
    margin: 10px 10px 10px 10px;
}
#wit:hover{
    background-color: whitesmoke; 
    color: black;        
    transform: scale(1.15);
}

#gum{
    background-color: gray; 
    color: white;
    width: 42px;
    height: 25px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    -webkit-transition-duration: 0.1s;
    transition-duration: 0.1s;
    font-family: Lato;
    border-color: black;
    border-style: solid;
    margin: 10px 10px 10px 10px;
}
#gum:hover{
    background-color: darkgray; 
    color: white;        
    transform: scale(1.15);
}

#reset{
    background-color: darkred; 
    color: white;
    width: 42px;
    height: 25px;   
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    -webkit-transition-duration: 0.1s;
    transition-duration: 0.1s;
    font-family: Lato;
    border-color: black;
    border-style: solid;
    margin: 10px 10px 10px 10px;
}
#reset:hover{
    background-color: rgb(114, 0, 0); 
    color: white;        
    transform: scale(1.15);
}

Ответы [ 2 ]

0 голосов
/ 02 февраля 2020

Добавьте атрибуты типа кнопки со всеми кнопками и установите для нее кнопку, ваша проблема будет решена.

type="button"

0 голосов
/ 02 февраля 2020

Вы использовали отдельные идентификаторы в стилях для ширины и высоты и удалили все используемые идентификаторы высоты и ширины. Используйте приведенный ниже код, и он будет работать с равной высотой и шириной кнопки.

#attributen button[class=color-changer], 
  #attributen input[id="reset"] {    
    width: 140px;    
    height: 35px;
 }

enter image description here

...