I have the following form:
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel='stylesheet' href='..//styles/styles-scale1-ma.css' />
<title>Title</title>
</head>
<body>
<div >
<h1 >Scale 1</h1>
<h3 >Subtitle 1</h3>
<div >
<div >
Item 1
</div>
<div >
<h5 >Question</h5>
<div >
<input type="radio" name="scale1-ma" id="1-1-0" value="0">
<label for="1-1-0">
Answer 0
</label>
<input type="radio" name="scale1-ma" id="1-1-1" value="1">
<label for="1-1-1">
Answer 1
</label>
<input type="radio" name="scale1-ma" id="1-1-2" value="2">
<label for="1-1-2">
Answer 2
</label>
<input type="radio" name="scale1-ma" id="1-1-3" value="3">
<label for="1-1-3">
Answer 3
</label>
<input type="radio" name="scale1-ma" id="1-1-4" value="4">
<label for="1-1-4">
Answer 4
</label>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<script src='../script.js'></script>
</body>
</html>
At the moment there is no script, but I use Bootstrap for the styles. My problem ist, that the last Radio isn't showing up. But it doesn't seem that there is a problem with the last element itself. If I delete it, the same problem appears with the fourth radio. What did I forget? I googled, but nobody seems to have the same issue.
Thanks, Tobi
CodePudding user response:
You could nest the input and label tag in Div element.
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel='stylesheet' href='..//styles/styles-scale1-ma.css' />
<title>Title</title>
</head>
<body>
<div >
<h1 >Scale 1</h1>
<h3 >Subtitle 1</h3>
<div >
<div >
Item 1
</div>
<div >
<h5 >Question</h5>
<div >
<div>
<input type="radio" name="scale1-ma" id="1-1-0" value="0">
<label for="1-1-0">
Answer 0
</label>
</div>
<div>
<input type="radio" name="scale1-ma" id="1-1-1" value="1">
<label for="1-1-1">
Answer 1
</label>
</div>
<div>
<input type="radio" name="scale1-ma" id="1-1-2" value="2">
<label for="1-1-2">
Answer 2
</label>
</div>
<div>
<input type="radio" name="scale1-ma" id="1-1-3" value="3">
<label for="1-1-3">
Answer 3
</label>
</div>
<input type="radio" name="scale1-ma" id="1-1-4" value="4">
<label for="1-1-4">
Answer 4
</label>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<script src='../script.js'></script>
</body>
</html>
CodePudding user response:
Group radios on the same horizontal row by adding .form-check-inline
to any .form-check
. please refer more here https://getbootstrap.com/docs/5.0/forms/checks-radios/#inline
Your radio button code should be as below.
<div >
<input type="radio" name="scale1-ma" id="1-1-0" value="0">
<label for="1-1-0">Answer 0</label>
</div>
<div >
<input type="radio" name="scale1-ma" id="1-1-1" value="1">
<label for="1-1-1">Answer 1</label>
</div>
<div >
<input type="radio" name="scale1-ma" id="1-1-2" value="2">
<label for="1-1-2">Answer 2</label>
</div>
<div >
<input type="radio" name="scale1-ma" id="1-1-3" value="3">
<label for="1-1-3">Answer 3</label>
</div>
<div >
<input type="radio" name="scale1-ma" id="1-1-4" value="4">
<label for="1-1-4">Answer 4</label>
</div>
CodePudding user response:
To list radio button just place your inputs between the Div attribute. This would provide radio button for each element.Here I have provided the code for your reference.
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel='stylesheet' href='..//styles/styles-scale1-ma.css' />
<title>Title</title>
</head>
<body>
<div >
<h1 >Scale 1</h1>
<h3 >Subtitle 1</h3>
<div >
<div >
Item 1
</div>
<div >
<h5 >Question</h5>
<div >
<div>
<input type="radio" name="scale1-ma" id="1-1-0" value="0">
<label for="1-1-0">
Answer 0
</label>
</div>
<div>
<input type="radio" name="scale1-ma" id="1-1-1" value="1">
<label for="1-1-1">
Answer 1
</label>
</div>
<div>
<input type="radio" name="scale1-ma" id="1-1-2" value="2">
<label for="1-1-2">
Answer 2
</label>
</div>
<div>
<input type="radio" name="scale1-ma" id="1-1-3" value="3">
<label for="1-1-3">
Answer 3
</label>
</div>
<div>
<input type="radio" name="scale1-ma" id="1-1-4" value="4">
<label for="1-1-4">
Answer 4
</label>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<script src='../script.js'></script>
</body>
</html>