saucypanda
saucypanda

Reputation: 37

Bootstrap button not resizing

I am using bootstrap CDN along with another bootstrap CSS example file in static. While trying to create the file input and submit button for the form, I could not manage to bring the width of the two tags down. They span across the full page of my laptop. I tried a few ways to solve the issue but nothing seems to work.

Code:

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" width="80" height="80">
                <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' width="400" height="300">
                <h3 class="h3 mb-3 font-weight-normal">Type of Skin Lesion: {{predictedLabel}}</h3>
            </form>
        </div>
    </body>
</html>

Upvotes: 1

Views: 917

Answers (1)

video-reviews.net
video-reviews.net

Reputation: 2916

The problem you are having is because you are using this in your button html

class="btn-block"

There are three default sizes for bootstrap 4 buttons

<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>

You can also try using css styling for custom sizes

style="width:80px;"

Which you can use like this

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

Upvotes: 2

Related Questions