引导按钮未调整大小

Posted

技术标签:

【中文标题】引导按钮未调整大小【英文标题】:Bootstrap button not resizing 【发布时间】:2021-04-23 12:03:23 【问题描述】:

我正在使用引导 CDN 以及另一个静态引导 CSS 示例文件。在尝试为表单创建文件输入和提交按钮时,我无法降低两个标签的宽度。它们横跨我笔记本电脑的整个页面。我尝试了几种方法来解决这个问题,但似乎没有任何效果。

代码:

html,
body 
  height: 100%;


body 
  display: -ms-flexbox;
  display: -webkit-box;
  display: flex;
  -ms-flex-align: center;
  -ms-flex-pack: center;
  -webkit-box-align: center;
  align-items: center;
  -webkit-box-pack: center;
  justify-content: center;
  padding-top: 40px;
  padding-bottom: 40px;
  background-color: #f5f5f5;


.form-upload 
  width: 80%;
  max-width: 330px;
  padding: 15px;
  margin: 0 auto;

.form-upload .checkbox 
  font-weight: 400;

.form-upload .form-control 
  position: relative;
  box-sizing: border-box;
  height: auto;
  padding: 10px;
  font-size: 16px;

.form-upload .form-control:focus 
  z-index: 2;

.form-upload input[type="email"] 
  margin-bottom: -1px;
  border-bottom-right-radius: 0;
  border-bottom-left-radius: 0;

.form-upload input[type="password"] 
  margin-bottom: 10px;
  border-top-left-radius: 0;
  border-top-right-radius: 0;


.file-block .btn-block 
  width: 25%;
<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

        <title>Skin Lesion Classifier</title>

        <link href="../static/css/form-upload.css" rel="stylesheet">
        <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">

        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
        integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

        <style>
            body 
                background-image: url('https://www.wchcd.org/wp-content/uploads/2014/04/healthcare-background.jpg');
            
        </style>
    </head>

    <body class="text-center">
        <div class="form-upload">
            <form enctype="multipart/form-data" action="predictImage" method="post" class="form-upload">
                % csrf_token %

                <img class="mb-4" src="https://cdn4.iconfinder.com/data/icons/artificial-intelligence-64/512/ai-healthcare-artificial-intelligence-512.png"  >
                <h1 class="h3 mb-3 font-weight-normal">Upload the Image to Classify</h1>

                <input type="file" name="filePath" id="image" class="form-control file-block" required autofocus>
                <button class="btn btn-lg btn-primary btn-block" type="submit">Predict</button>

                <br> <br>

                <img src=filePathName alt='imagename'  >
                <h3 class="h3 mb-3 font-weight-normal">Type of Skin Lesion: predictedLabel</h3>
            </form>
        </div>
    </body>
</html>

【问题讨论】:

【参考方案1】:

您遇到的问题是因为您在按钮 html 中使用了它

class="btn-block"

bootstrap 4 按钮有三种默认尺寸

<button type="button" class="btn btn-primary btn-lg">Large button</button>
<button type="button" class="btn btn-primary btn-sm">Small button</button>
<button type="button" class="btn btn-primary btn-lg btn-block">Block level button</button>

您也可以尝试使用 css 样式来自定义尺寸

style="width:80px;"

你可以这样使用

<button type="button" class="btn btn-primary" style="width:80px;">Custom button</button>

【讨论】:

以上是关于引导按钮未调整大小的主要内容,如果未能解决你的问题,请参考以下文章

UIButton 框架未随图像调整大小

获取视图大小未调整大小

为响应式网页布局调整网页大小[重复]

Extjs:面板内的工具栏未在浏览器调整大小时调整大小

UIViewController 的视图未由 viewWillAppear() 调整大小 [重复]

根据列表大小调整引导菜单多列的大小