The padding on the Bootstrap button creates the illusion that the button extends beyond the boundaries of the container

Can you help me troubleshoot why the "Subscribe now!" button is extending beyond the container in the image below? How can I align the right edge with the rest of the page, specifically column 12 in the bootstrap grid?

I attempted using box-sizing: border-box, but it did not resolve the issue.

Take a look at my HTML code:

.container-fluid {
  padding: 0;
}

.carousel-inner .carousel-item h1 {
  font-weight: bold;
  font-size: 300%;
  /*-webkit-text-stroke:1px black;*/
  font-family: 'Open Sans', sans-serif;
  /*text-align:right;*/
}

.carousel-inner .carousel-item img {
  filter: brightness(50%);
}

#paddingrow {
  padding: 25px;
}

#paddingrowLarge {
  padding: 100px;
}

#accordionRightalign {
  float: right;
}

#mycard {
  float: right;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<div class="container">
  <div class="row" id="paddingrow"></div>
  <div class="row">
    <div class="col-sm-12">
      <h1 style="text-align:center">SUBSCRIBE TO OUR NEWSLETTER</h1>
    </div>
  </div>
  <div class="row">
    <div class="col-sm-12">
      <form>
        <div class="row">
          <div class="col">
            <input type="text" class="form-control" placeholder="Enter your email">
          </div>
          <button class="btn btn-primary" style="box-sizing: border-box" type="submit">Subscribe now!</button>
        </div>
      </form>
    </div>
  </div>
</div>
</div>

https://i.sstatic.net/NVVQn.jpg

https://i.sstatic.net/dMZCT.jpg

Answer №1

Modify Bootstrap rows: To fix the alignment issue caused by

margin-right: -15px; margin-left: -15px;
, consider adding the mx-0 class for setting margin-left: 0 and margin-right: 0 within your nested row form.

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<div class="container">
  <div class="row" id="paddingrow"></div>
  <div class="row">
    <div class="col-sm-12">
      <h1 style="text-align:center">SUBSCRIBE TO OUR NEWSLETTER</h1>
    </div>
  </div>
  <div class="row">
    <div class="col-sm-12">
      <form>
        <div class="row mx-0">
          <div class="col pl-0 pr-3">
            <input type="text" class="form-control" placeholder="Enter your email">
          </div>
          <button class="btn btn-primary" style="box-sizing: border-box" type="submit">Subscribe now!</button>
        </div>
      </form>
    </div>
  </div>
</div>
</div>

Answer №2

Remember to set the column in the container with both margin and padding values of zero. Insert your image inside a container with a maximum width of 100%.

Answer №3

After realizing my button was not nested in the column div, I decided to create two separate column divs - one with a size of 10 and the other with a size of 2. I placed the input field in the first column and the button in the second column, and now everything appears to be functioning correctly.

Below is the updated code:

<div class="container">
           <div class="row" id="paddingrow"></div>
           <div class="row">
             <div class="col-sm-12">
               <h1 style="text-align:center">SUBSCRIBE TO OUR NEWSLETTER</h1>
             </div>
           </div>
           <div class="row">
              <div class="col-sm-12">
                <form class="form">
                  <div class="row">
                    <div class="col-sm-10">
                      <input type="text" class="form-control" placeholder="Enter your email">
                    </div>
                    <div class="col-sm-2">
                      <button class="btn btn-primary w-100" type="submit">Subscribe now!</button>
                    </div>
                  </div>
                </form>
              </div>
            </div>
          </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

How to extract text from a textarea without a value attribute using Python and Selenium WebDriver

I have exhausted all efforts and still need help. I am attempting to retrieve the text from an element on a page that displays as a popup within a frame, not as an alert or new window. Although WebDriver is able to locate the element, the text returned whe ...

Clear out the classes of the other children within the identical parent division

I'm currently in the process of replacing my radio circles with div elements. I've successfully implemented the functionality for selecting options by clicking on the divs, as well as highlighting the selected div. However, I'm facing trou ...

Expanding the Boostrap menu to occupy the entire width

I want the menu to span the width of its container instead of being aligned to the left. [LOGO A|B|C ] [LOGO A | B | C ] Here is my test code. How can this be achieved using bootstrap? .navbar-brand{width: 405px;} <link href="http ...

Styled HTML Radio Button Failing to Register Click

When I select the radio button, it does not actually get clicked and the status of other buttons remains unchanged. The CSS code being used is as follows: input[type="radio"] { display:none; } input[type="radio"] + label { height: 20px ...

Refrain from engaging with "disabled" table rows to prevent user interaction

I have an HTML table with certain rows marked as 'disabled'. To make this clear to the user, I decided to apply a blur filter to the tr, resulting in a table that looks like this: https://i.stack.imgur.com/GcX67.png NOTE: You can view a live ex ...

I am encountering a JQuery syntax error while using Bootstrap 3 button-dropdown links

I'm trying to replicate the example found here in order to create a similar markup: <div class="btn-group"> <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> ...

How can I enhance the appearance of my custom field using CSS in Advanced Custom Fields?

Utilizing the Wordpress Advanced custom field plugin, I have successfully added a custom field to my site. Within this custom field, I have inserted images and now I am looking to center them on my page using CSS styles such as margin: 0 auto. If you&apo ...

Using JavaScript to pass the href attribute value

On my HTML page, there are multiple links that reload the page when clicked. I want to capture the href value of each link the user clicks and store it in a variable called xhash: Here is the HTML: <a href='#taba' id='passid'>Li ...

Determining the number of columns dynamically in CSS based on the maximum content of children elements

I am experimenting with using CSS columns to showcase a variable number of columns based on the maximum width required for the content to display elegantly (without any unnecessary line breaks). Additionally, I aim to expand each element to fill the availa ...

Is there a way to create submit buttons that trigger printing in HTML? Additionally, how can I design a text input that spans 100% width on the same line as a <span>, <p>, or <div>?

These are the files I have: .dir { color: white; font-family: "Lucida Console", Monaco, monospace; font-size: 16px; } .cmdline { font-family: "Lucida Console", Monaco, monospace; background-color: black; border: 1px solid black; color: whi ...

IN to CM Conversion Size Chart

I'm just starting out and I want to make a size chart table that can convert between metric units. For example, I have table data with values in "inches" and I want to be able to switch it to "centimeters" with the click of a button. Some of the data ...

Is there a way to show a fallback message for unsupported video file formats?

When incorporating a video element on my webpage, I typically use the following code: <video src="some source" controls> Error message </video> Based on my knowledge, the "Error message" will only appear if the browser does not support the ...

Personalized FileInput within a card - Bootstrap 5

I am attempting to incorporate a custom file selection feature within a Bootstrap card: Here is my attempt: <style> label { cursor: pointer; } .custom-input-image { opacity: 0; position: absolute; z-index: -1; } </style> <div ...

Tips for avoiding the transmission of className and style attributes to React components

Hey there! I'm working on a custom button component that needs to accept all ButtonHTMLAttributes except for className and style to avoid any conflicts with styling. I'm using TypeScript with React, but I've run into some issues trying to ac ...

Creating a barcode in HTML using the Code128 (Type B) format, incorporating Google Fonts for customization

I've been tasked with creating an HTML barcode (not an image, not a drawing, and without using TCPDF classes) using PHP in my job, but I'm struggling to understand how it works. I found a sample online and tried to run it, but no barcode is showi ...

CSS for a Div with a Subtle Curve at the Bottom

Is there a way to achieve this specific shape using CSS? I attempted to use the following resources, but they didn't provide me with the desired outcome. Curved border with stroke in pure CSS? http://jsfiddle.net/ECHWb/ .banner-img{ height: 661p ...

What is the best way to detect a checkbox click event inside a nested container?

I've created a list of divs, each with a corresponding pair containing more details. When you click on the "intro" div, the detailed pair opens and the intro is hidden. Each div also has a checkbox. I encountered an issue where clicking the checkbox i ...

What causes materialui styles to vanish upon refreshing in nextjs?

After consulting the materialui documentation (https://material-ui.com/guides/server-rendering/), I was able to find a solution, but I am still unsure of the underlying reason. Why does the style work initially during rendering but disappear upon subs ...

Ways to merge various input values

I need help combining input values in my code. Below is the code I have so far: getCodeBoxElement(index) { return document.getElementById("codeBox" + index); } onKeyUpEvent(index, event) { const eventCode = event.which || event.keyCode; console.lo ...

How can I match dates in order to run the following code?

If Purchase Date is after 31/Mar/xxxx it should not calculate elap_yend, rem_days, depre_cur, cur_wdv. Also I have to calculate GST with some options that is if SGST and CGST are chosen, I should not calculate IGST else if IGST selected or marked it shoul ...