我对前端开发非常陌生,我只是想创建一个示例网站。我为模板使用了引导程序,目前在对齐单选按钮时遇到问题。这是代码示例:
<div class="row">
<div class="col">
<p class="h5 mt-4 mb-4">Production Machine</p>
<div class="custom-control custom-radio col-md-10">
<input type="radio" class="custom-control-input" id="desktop" name="prodMachine">
<label class="custom-control-label" for="desktop">Desktop Machine</label>
</div>
<div class="custom-control custom-radio col-md-10">
<input type="radio" class="custom-control-input" id="laptop" name="prodMachine">
<label class="custom-control-label" for="laptop">Laptop Machine</label>
</div>
</div>
<!--Transportation Availability-->
<div class="col col-sm">
<p class="h5 mt-4 mb-4">Transportation Availability</p>
<div class="custom-control custom-radio col-md-10">
<input type="radio" class="custom-control-input" id="massTranspo" name="transpoAvail">
<label class="radio custom-control-label" for="massTranspo">Mass Transporation</label>
</div>
<div class="custom-control custom-radio col-md-10">
<input type="radio" class="custom-control-input" id="privateVehicle" name="transpoAvail">
<label class="custom-control-label" for="privateVehicle">Private Vehicle</label>
</div>
</div>
</div>
我似乎无法对齐标签。这是本节的内容: enter image description here
我做错什么了吗?或者我只是想念什么?
任何建议将不胜感激。 :)
答案 0 :(得分:2)
您的标签与bootstrap 4.5.0对齐。请运行代码段。
编辑1 :添加<form class="border border-light p-5 m-0" action="#!">
以包装代码。未对齐是由于添加到表单的text-center
类所致。删除它,对齐问题消失了。
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
<form class="border border-light p-5 m-0" action="#!">
<div class="row">
<div class="col">
<p class="h5 mt-4 mb-4">Production Machine</p>
<div class="custom-control custom-radio col-md-10">
<input type="radio" class="custom-control-input" id="desktop" name="prodMachine">
<label class="custom-control-label" for="desktop">Desktop Machine</label>
</div>
<div class="custom-control custom-radio col-md-10">
<input type="radio" class="custom-control-input" id="laptop" name="prodMachine">
<label class="custom-control-label" for="laptop">Laptop Machine</label>
</div>
</div>
<!--Transportation Availability-->
<div class="col col-sm">
<p class="h5 mt-4 mb-4">Transportation Availability</p>
<div class="custom-control custom-radio col-md-10">
<input type="radio" class="custom-control-input" id="massTranspo" name="transpoAvail">
<label class="radio custom-control-label" for="massTranspo">Mass Transporation</label>
</div>
<div class="custom-control custom-radio col-md-10">
<input type="radio" class="custom-control-input" id="privateVehicle" name="transpoAvail">
<label class="custom-control-label" for="privateVehicle">Private Vehicle</label>
</div>
</div>
</div>
</form>