Why is my button stretching the entire width of the screen?

As I delve into learning bootstrap, I find myself puzzled by the behavior of my image button. It seems to be scaling to the full width of the screen, which is not what I expected. While I can manually adjust its size, I am curious about the reason behind this unusual occurrence. Normally buttons are compact by default, so this divergence intrigues me.

If you notice any mistakes or areas in my code that could be improved, I would greatly appreciate your feedback.

    #grid div {
        background: black;
        border: 3px solid #000;
    }

    #grid {
        padding-bottom: 50px;
    }

    ul {
        padding-right: 50px;
    }

    li {
        padding-left: 30px;
    }

    a {
        color: white;
        font-family: Verdana, Geneva, Tahoma, sans-serif;
    }

    h1 {
        font-family: Verdana, Geneva, Tahoma, sans-serif;
        text-align: center;
        font-weight: bold;
        margin-bottom: 100px;
    }

    #function {
        margin-left: auto;
        margin-right: auto;
    }

    .button {
        background-color: DodgerBlue;
        margin-left: auto;
        margin-right: auto;
    
    }
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid" id="grid">
        <div class="row">
          <div class="col-sm">
            <ul class="nav justify-content-end">
                <li class="nav-item">
                  <a class="nav-link active" href="#">Converter</a>
                </li>
                <li class="nav-item">
                  <a class="nav-link" href="#">More Products</a>
                </li>
                <li class="nav-item">
                  <a class="nav-link" href="#">About</a>
                </li>
                
            </ul>
          </div>
          
          
  
        </div>
        
  
      </div>

      <h1>Convert your jks to p12!</h1>

      <div class="container">
        <div class="row">
          <div class="col-lg-6" id="function">
            <div class="input-group">
                <div class="custom-file">
                  <input type="file" class="custom-file-input" id="inputGroupFile01"
                    aria-describedby="inputGroupFileAddon01">
                  <label class="custom-file-label" for="inputGroupFile01">Choose file</label>
                </div>
              </div>
          </div>
  
        </div>
      </div>
  
      
    
      <div class="button">
        <button class="btn">
          <i class="fa fa-home"></i>
        </button>
      </div>
      

Answer №1

The issue arises from attempting to customize the div with the class buttons, which inherently has a default width of 100%. The intention was likely to style the button within it instead, so the remedy is straightforward: modify the .buttons selector to .buttons button.btn.

#grid div {
  background: black;
  border: 3px solid #000;
}

#grid {
  padding-bottom: 50px;
}

ul {
  padding-right: 50px;
}

li {
  padding-left: 30px;
}

a {
  color: white;
  font-family: Verdana, Geneva, Tahoma, sans-serif;
}

h1 {
  font-family: Verdana, Geneva, Tahoma, sans-serif;
  text-align: center;
  font-weight: bold;
  margin-bottom: 100px;
}

#function {
  margin-left: auto;
  margin-right: auto;
}

.button button.btn {    /* amended */
  background-color: DodgerBlue;
  margin-left: auto;
  margin-right: auto;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<div class="container-fluid" id="grid">
  <div class="row">
    <div class="col-sm">
      <ul class="nav justify-content-end">
        <li class="nav-item">
          <a class="nav-link active" href="#">Converter</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">More Products</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">About</a>
        </li>

      </ul>
    </div>



  </div>


</div>

<h1>Convert your jks to p12!</h1>

<div class="container">
  <div class="row">
    <div class="col-lg-6" id="function">
      <div class="input-group">
        <div class="custom-file">
          <input type="file" class="custom-file-input" id="inputGroupFile01" aria-describedby="inputGroupFileAddon01">
          <label class="custom-file-label" for="inputGroupFile01">Choose file</label>
        </div>
      </div>
    </div>

  </div>
</div>



<div class="button">
  <button class="btn">
      <i class="fa fa-home"></i>
    </button>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Challenges in accurately capturing canvas drawing masks using HTML5 and JavaScript for image inpainting

I have been developing an image inpainting tool that allows users to mark areas they want to remove on a canvas. These drawn masks are then sent to the server for processing. However, I am facing an issue where the produced mask does not accurately align w ...

`json object allows for category selection in options`

Hello (please excuse my English), I have the following script: <script type="text/javascript"> $(document).ready(function() { var idPlato = decodeURI(getUrlVars()["idPl"]); var url = "http://localhost/plato-datos.php?idPla="+idPl ...

internet explorer 11 not properly aligning text to center

I've encountered an issue with center-aligning a canvas and overlapping image on different browsers. While Chrome and Firefox display it correctly, Internet Explorer does not cooperate. The canvas is not centered, but the image is. I've tried var ...

Flex sidebar collapse menu

I am currently in the process of developing an admin panel for my website. I have a sidebar menu that I would like to hide behind a hamburger icon and only expand when clicked on. After researching potential solutions, I haven't found much that fits m ...

Creating a flexible and adaptive navigation menu

Struggling with making the navigation bar responsive. The toggle and positioning are not working properly. See the example below. Can't figure out what's missing? <script type="text/javascript"> function myFunction() { var x = docume ...

Creating Sleek Rounded Corners with Pure CSS in Older Versions of Internet Explorer (Compatible with jQuery)

Looking for a seamless solution to render rounded corners on browsers that do not support CSS3 without the delay typically seen with JQuery plugins. The use of .htc files with www.css3pie.com seems like the best option so far, but there is still a delay c ...

Video files embedded using Shopify's HTML code may not be visible on iPhones

Hello everyone, I hope you can help me with my issue! I have successfully integrated an HTML video onto my Shopify homepage, but I am experiencing some trouble when trying to view it on an iPhone. Instead of the video playing, I see a blank box. Below is ...

What are the time-saving benefits of utilizing semantic X/HTML in CSS development?

Exploring the Time-Saving Power of Semantic X/HTML Markup - Streamlining CSS writing for websites Adapting to future design changes from clients with ease Avoiding the time-consuming nature of Table-based layouts in all scenarios Today, I have the task ...

Variation in `th` & `td` Width in Table

Is it possible to have different widths for th and td, such as 50px for th and 500px for td? To address this issue, I am utilizing datatable. To enable others to help me, here is a simple code snippet: .abc { width: 500px; } .def { width: 50px; } ...

JavaScript code not functioning properly to submit form

My journey with my first web application has hit a roadblock. I am attempting to use javascript to submit a form by clicking on text, but nothing happens when I click. All I want is for it to open a simple webpage at this stage. Although I have experience ...

Deleting a database table row with a click of a button

I am working with a table structure in my HTML: <table class="table" id="mytable"> <tr> <td>Column 1</td> <td>Column 2</td> <td><button type="submit" class="btn removeButton">Remove</button& ...

What are the steps to getting Jarallax MDB up and running?

This is the code I am currently working with: <div class="view jarallax" data-jarallax = '{"speed":0.2 }' style="background- image: url('OFP/OFP_Group.jpg'); background-repeat: no-repeat; background- size: cover; background-positi ...

How to alter button text dynamically in Android Studio issue

What is causing this issue in the code? It seems to be rejecting the setText function when applied to a button. findViewById(getResources().getIdentifier("button" + Integer.toString(i), "id", getPackageName())) .setText( ...

Placing a form amidst two div containers

I am delving into the world of CSS and Bootstrap, attempting to recreate a simple layout. However, I'm encountering some challenges. My goal is to stack 2 divs on top of each other with a form that spans both divs. Can you provide insight on how to a ...

JSON format used to convert information from a webpage

I came across a URL in my textbook, , which directs to a page providing the original page's content in JSON format. Intrigued, I attempted to format another webpage's content into JSON using the same method, as my professor also shared a link in ...

Is there a way to switch my image buttons to a different image when clicked?

In order to create interactive buttons for a website, I designed four unique .PNG images using Photoshop. Two of these images are intended to serve as default buttons, while the other two are meant to be used as "post-click" buttons. For the default butto ...

What is the process for uploading content when an image is clicked on?

Is it possible to assign a name to a variable on click of an image? Instead of using a text field and submit button, I want to achieve this functionality by simply clicking on the image itself. I tried the following code but it doesn't seem to work. A ...

Utilizing Angular2 to name dynamically generated sets of radio buttons

As a novice in web development and Angular2, I am facing an issue with an Angular2 component tasked with creating a tree view on a webpage using the angular-tree-component library. In this tree, each node is associated with a popover HTML template containi ...

Is there a way to trigger the opening of a jQuery-UI-Selectmenu dropdown using the 'ENTER' key instead of the 'SPACE' key as indicated in the documentation?

I'm currently working on implementing jQuery-UI-Selectmenu to create a dropdown feature. As per the API documentation for select menu available at https://api.jqueryui.com/selectmenu/, it mentions that the 'SPACE' key can be utilized to ope ...

Toggling dropdown menus with conditional Jquery statements

I am experiencing some discomfort. :) I've been working on a calorie calculator that includes a dropdown for various dietary preferences. Currently, when a user clicks the button, the dropdown appears and disappears when clicking outside the button. ...