当前阅读教程:Bootstrap4教程 > 自定义文件上传控件 | |
阅读(22555525) 收藏 赞(5685) 分享 | |
上一篇: 自定义滑块控件 | 下一篇: Bootstrap4 轮播 |
我们可以在父元素添加 .custom-file 类,然后在 input 设置为 type="file" 并添加 .custom-file-input: 上传控件的文本使用 label 标签,标签使用 .custom-file-label 类,label 的 for 属性值需要匹配复选框的 id。 Bootstrap4 实例 <form> <div> <input type="file" id="customFile"> <label for="customFile">选择文件</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-file 类,然后在 input 设置为 type="file" 并添加 .custom-control-label:</p> <form action="/action_page.php"> <p>自定义上传文件样式:</p> <div class="custom-file mb-3"> <input type="file" id="customFile" name="filename"> <label for="customFile">选择文件</label> </div> <p>默认上传文件样式:</p> <input type="file" id="myFile" name="filename2"> <div> <button type="submit" class="btn btn-primary">提交</button> </div> </form> </div> </body> </html> 效果图 |
|
上一篇: 自定义滑块控件 | 下一篇: Bootstrap4 轮播 |