当前阅读教程:Bootstrap4教程 > 自定义控件显示在同一行 | |
阅读(22555525) 收藏 赞(5685) 分享 | |
上一篇: 自定义单选框 | 下一篇: 自定义选择菜单 |
我们可以在外部元素上使用 .custom-control-inline 类来包裹自定义表单控件,这样自定义表单控件就能显示在同一行: Bootstrap4 实例 <form> <div class="custom-control custom-radio custom-control-inline"> <input type="radio" id="customRadio" name="example" value="customEx"> <label for="customRadio">自定义单选框 1</label> </div> <div class="custom-control custom-radio custom-control-inline"> <input type="radio" id="customRadio2" name="example" value="customEx"> <label for="customRadio2">自定义单选框 2</label> </div> </form> 完整代码 <!DOCTYPE html> <html> <head> <title>Bootstrap 实例(小白教程网 2d5.net)</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css"> <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script> <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script> <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script> </head> <body> <div class="container mt-3"> <h2>自定义控件显示在同一行</h2> <p>我们可以在外部元素上使用 .custom-control-inline 类来包裹自定义表单控件,这样自定义表单控件就能显示在同一行:</p> <form action="/action_page.php"> <div class="custom-control custom-radio custom-control-inline"> <input type="radio" id="customRadio1" name="example1"> <label for="customRadio1">自定义单选框 1</label> </div> <div class="custom-control custom-radio custom-control-inline"> <input type="radio" id="customRadio2" name="example2"> <label for="customRadio2">自定义单选框 2</label> </div> <button type="submit" class="btn btn-primary">提交</button> </form> </div> </body> </html> 效果图 |
|
上一篇: 自定义单选框 | 下一篇: 自定义选择菜单 |