我想在标签后添加单选按钮。 现在它也显示
但我想像这样显示它
已更新
这是我的完整代码
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-md-12">
<form [formGroup]="surveyQuestionForm">
<div class="form-group">
<label class="control-label"> 1) What is the answer of 3 + 5?</label>
<div class="ml-3">
<div class=" custom-radio custom-control">
<input type="checkbox" class="custom-control-input" id="q1_1" name="q1"
value="1" formControlName="q1" />
<label class="custom-control-label" for="q1_1">2</label>
</div>
<div class=" custom-radio custom-control">
<input type="checkbox" class="custom-control-input" id="q1_2" name="q1"
value="2" formControlName="q1" />
<label class="custom-control-label" for="q1_2">5</label>
</div>
<div class=" custom-radio custom-control">
<input type="checkbox" class="custom-control-input" id="q1_3" name="q1"
value="3" formControlName="q1" />
<label class="custom-control-label" for="q1_3">7</label>
</div>
<div class=" custom-radio custom-control">
<input type="checkbox" class="custom-control-input" id="q1_4" name="q1"
value="4" formControlName="q1" />
<label class="custom-control-label" for="q1_4">3</label>
</div>
<div class=" custom-radio custom-control">
<input type="checkbox" class="custom-control-input" id="q1_5" name="q1"
value="5" formControlName="q1" />
<label class="custom-control-label" for="q1_5">8</label>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
我尝试过这种方式
<div class=" custom-radio custom-control">
<label class="custom-control-label" for="q1_1">2
<input type="radio" class="custom-control-input" id="q1_1" name="q1"
value="1" formControlName="q1" /></label>
</div>
然后我无法检查。这不是检查。
Update2
这里是user863让步的地方。如果我对其他问题使用该方法,则单选按钮将显示内部答案。 如果我同样更改css值,
.custom-control-label::after {
left: 1.5rem!important;
}
然后正确显示。但是我不能手动更改CSS。因为我不知道答案的长度,所以所有问题的长度都不相同。
.custom-control-label::before,
.custom-control-label::after {
left: 1.5rem!important;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-md-12">
<form [formGroup]="surveyQuestionForm">
<div class="form-group">
<label class="control-label"> 1) What is the country you would like to go?</label>
<div class="ml-3">
<div class=" custom-radio custom-control">
<input type="radio" class="custom-control-input" id="q1_1" name="q1" value="1" formControlName="q1" />
<label class="custom-control-label" for="q1_1">Australia</label>
</div>
<div class=" custom-radio custom-control">
<input type="radio" class="custom-control-input" id="q1_2" name="q1" value="2" formControlName="q1" />
<label class="custom-control-label" for="q1_2">England</label>
</div>
<div class=" custom-radio custom-control">
<input type="radio" class="custom-control-input" id="q1_3" name="q1" value="3" formControlName="q1" />
<label class="custom-control-label" for="q1_3">Canada</label>
</div>
<div class=" custom-radio custom-control">
<input type="radio" class="custom-control-input" id="q1_4" name="q1" value="4" formControlName="q1" />
<label class="custom-control-label" for="q1_4">India</label>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
答案 0 :(得分:1)
这是使用自定义CSS的演示
.custom-control-label::before,
.custom-control-label::after {
left: 1.5rem!important;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="form-group">
<label class="control-label"> 1) What is the answer of 3 + 5?</label>
<div class="ml-3">
<div class=" custom-radio custom-control">
<input type="radio" class="custom-control-input" id="q1_1" name="q1" value="1" formControlName="q1" />
<label class="custom-control-label" for="q1_1">2</label>
</div>
<div class=" custom-radio custom-control">
<input type="radio" class="custom-control-input" id="q1_2" name="q1" value="2" formControlName="q1" />
<label class="custom-control-label" for="q1_2">5</label>
</div>
<div class=" custom-radio custom-control">
<input type="radio" class="custom-control-input" id="q1_3" name="q1" value="3" formControlName="q1" />
<label class="custom-control-label" for="q1_3">7</label>
</div>
<div class=" custom-radio custom-control">
<input type="radio" class="custom-control-input" id="q1_4" name="q1" value="4" formControlName="q1" />
<label class="custom-control-label" for="q1_4">3</label>
</div>
<div class=" custom-radio custom-control">
<input type="radio" class="custom-control-input" id="q1_5" name="q1" value="5" formControlName="q1" />
<label class="custom-control-label" for="q1_5">8</label>
</div>
</div>
</div>
更新
向右移动,如果需要对齐,请使用固定的width
(根据需要)
.custom-control-label::before,
.custom-control-label::after {
left: unset!important;
right: -1.5rem!important;
}
.custom-control-label {
/*width: 100px; (if alignment needed) */
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-md-12">
<form [formGroup]="surveyQuestionForm">
<div class="form-group">
<label class="control-label"> 1) What is the country you would like to go?</label>
<div class="ml-3">
<div class=" custom-radio custom-control">
<input type="radio" class="custom-control-input" id="q1_1" name="q1" value="1" formControlName="q1" />
<label class="custom-control-label" for="q1_1">Australia</label>
</div>
<div class=" custom-radio custom-control">
<input type="radio" class="custom-control-input" id="q1_2" name="q1" value="2" formControlName="q1" />
<label class="custom-control-label" for="q1_2">England</label>
</div>
<div class=" custom-radio custom-control">
<input type="radio" class="custom-control-input" id="q1_3" name="q1" value="3" formControlName="q1" />
<label class="custom-control-label" for="q1_3">Canada</label>
</div>
<div class=" custom-radio custom-control">
<input type="radio" class="custom-control-input" id="q1_4" name="q1" value="4" formControlName="q1" />
<label class="custom-control-label" for="q1_4">India</label>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
答案 1 :(得分:0)
如果要计算总和,则需要使用aggregate(score~grp+gname,df,max)
,因为一次只能选择一个单选按钮。
参考:https://www.w3schools.com/tags/att_input_type_radio.asp
aggregate(grp~grp+gname,df,length)