CSS:为什么这些按钮不采用我设置的固定宽度和高度?在此处输入图像描述

问题描述 投票:0回答:1

我正在尝试将these按钮设置为固定大小。宽度为42像素,高度为25像素。由于某些原因,它们的尺寸不正确。只是标准之一。我一直在寻找解决方案,但可悲的是找不到。抱歉,如果我的代码有点混乱,我是一个初学者,正在尝试使某些事情起作用:)

这里是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);
}
html css button height width
1个回答
0
投票

您已在样式中使用分隔的ID作为宽度和高度,并已将其全部使用ID高度和宽度删除。使用以下代码,该按钮的高度和宽度将相等。

属性按钮[class = color-changer],#attribute input [id =“ reset”] {宽度:140像素;高度:35像素;} enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.