Html 如何在启动页面或单击任意位置时选中我的单选按钮

Html 如何在启动页面或单击任意位置时选中我的单选按钮,html,css,forms,radio-button,Html,Css,Forms,Radio Button,我正在尝试进行个性化的无线电输入,当我单击按钮被取消选中的任何位置时,我如何保持它处于选中状态,而不管我在哪里单击?。另一个问题是,为什么即使我添加了选中的选项,“男性”选项也没有显示为已选中 我的网站: HTML: <div id="bloco"> <h1>QUAL É SUA CATEGORIA NO UFC</h1> <p id="resultPound">Coloque seu peso e vamos transf

我正在尝试进行个性化的无线电输入,当我单击按钮被取消选中的任何位置时,我如何保持它处于选中状态,而不管我在哪里单击?。另一个问题是,为什么即使我添加了选中的选项,“男性”选项也没有显示为已选中

我的网站:

HTML:

<div id="bloco">
      <h1>QUAL É SUA CATEGORIA NO UFC</h1>
      <p id="resultPound">Coloque seu peso e vamos transformar em libras para descobrir em que categoria do UFC você
         lutaria!</p>
      <form> <input type="text" id="fname" name="fname" placeholder="digite seu peso"><br>

      <div class="gender">
         <input type="radio" id="male" value="male" checked>
         <label for="male">Masculino</label>
         <input type="radio" id="female" value="female">
         <label for="female">Feminino</label><br>
      </div>
   </form>
      <button onclick="changeValue()">Confirmar</button>
      <script src="script.js"></script>
   </div>
  font-family: lato;
  font-size: 72px;
  color: #FF7979;
  font-weight: heavy;
  margin: 0px 0px 25px 0px;
}

p {
  font-family: lato;
  font-size: 24px;
  color: #000000;
  font-weight: regular;
  margin:0px;
  margin: 0px 0px 30px 0px;
}

button {
  background-color: #FF7979;
  border: none;
  color: white;
  border-radius: 50px;
  width: 281px;
  height: 38px;
  text-align: center;
  display: inline-block;
  font-size: 24px;
  font-family: lato;
  margin: 10px 0px;
}

button:hover {
  outline:0;
  background-color: rgb(235, 119, 119);
  box-shadow: 0 12px 16px 0 rgba(0,0,0,0.05), 0 17px 50px 0 rgba(0,0,0,0.05);

}

button:focus {
  outline:0;
}

button:active {
  background-color: rgb(245, 130, 130);
  transform: translateY(4px);
}

input[type=text] {
  width: 281px;
  height: 38px;
  box-sizing: border-box;
  border: 3px solid #ccc;
  -webkit-transition: 0.5s;
  transition: 0.5s;
  outline: none;
  border-radius: 50px;
}

input[type=text]:focus {
  border: 3px solid #555;
}

#fname {
  text-align: center;
  font-family: lato;
  font-size: 24px;
  color: #000000;
  font-weight: regular;
  opacity: 40%;
}

#bloco {
text-align: center;
margin: 0;
position: absolute;
top: 45%;
left: 50%;
transform: translate(-50%, -50%);
white-space: nowrap;
}

.gender input[type="radio"] {
  opacity: 0;
  position: fixed;
  width: 0;
}

.gender {
  color:#EA8079;
  font-size: 24px;
  font-family: lato;
  margin: 20px 0px 25px 0px;
}

.gender label {
    border: 1px solid #EA8079;
    border-radius: 50px;
    padding: 5px 15px;
}

/* .gender input[type="radio"]:checked + label {
  background-color:#bfb;
  border-color: #4c4;
}
 */
.gender input[type="radio"]:focus + label {
  background-color:#FF7979;
  color: white;
  font-weight: bold;
}

.gender label:hover {
  background-color: rgba(255, 0, 0, 0.247);
}

您可以将
checked
属性添加到要自动选择的输入中


您正在使用
:focus
:active
伪选择器。如果要设置选中收音机的样式,应将其设置为
:checked

.gender输入[type=“radio”]:选中+标签{
背景色:#FF7979;
颜色:白色;
字体大小:粗体;
}
但我也注意到,您的输入没有name属性,因此它们不会单独工作


男性的
女性化
最终结果:

constchangevalue=()=>{
var teste=document.getElementById(“fname”).value;
函数kilostofounds(teste){return((teste*2.2046).toFixed())}
const finalfound=千磅(teste);
开关(真){
案例finalFound==0:
document.getElementById(“resultPound”).innerHTML=`Coloque seu peso e vamos transformar em libras para descobrir em que categoria do UFC vocêlutaria!`;
打破

case FinalFound您可以将
checked
属性添加到要自动选择的输入中


您正在使用
:focus
:active
伪选择器。如果要设置选中收音机的样式,应将其设置为
:checked

.gender输入[type=“radio”]:选中+标签{
背景色:#FF7979;
颜色:白色;
字体大小:粗体;
}
但我也注意到,您的输入没有name属性,因此它们不会单独工作


男性的
女性化
最终结果:

constchangevalue=()=>{
var teste=document.getElementById(“fname”).value;
函数kilostofounds(teste){return((teste*2.2046).toFixed())}
const finalfound=千磅(teste);
开关(真){
案例finalFound==0:
document.getElementById(“resultPound”).innerHTML=`Coloque seu peso e vamos transformar em libras para descobrir em que categoria do UFC vocêlutaria!`;
打破

case Final感谢你的提示,但我的问题是关于收音机的,而不是按钮!哦,我是指收音机,对不起。让我来解决这个问题谢谢提示,但我的问题是关于收音机的,而不是按钮!哦,我是指收音机,对不起。让我来解决这个问题