What is the best way to align the button correctly beside the cluster of checkboxes within bootstrap framework?

Here is a snippet of HTML code that I am working with:

<div class="container">
<form name ="queryForm">

<div class="form-group">
    <p class="checkbox-inline">
        <input type="checkbox" name="optionsRadios" id="checkOne" value="one">
        One
    </p>
    <p class="checkbox-inline">
        <input type="checkbox" name="optionsRadios" id="checkTwo" value="two">
        Two
    </p>
    <p class="checkbox-inline">
        <input type="checkbox" name="optionsRadios" id="checkThree" value="three">
        Three
    </p>
    <p class="checkbox-inline">
        <input type="checkbox" name="optionsOther" id="checkFour" value="four">
        Four
    </p>
    <button type="submit" class="btn btn-fill btn-info">Reload</button>
</div>
</form>
</div>

The current layout of the code looks like this:

https://i.sstatic.net/JhfFa.png

I would like to reposition the Reload button next to the checkboxes. Initially, I attempted to move the <button... code right after the last checkbox as seen below:

Four

<button type="submit" class="btn btn-fill btn-info">Reload</button>
</div>

However, this resulted in an undesired layout:

https://i.sstatic.net/NMF0M.png

My goal is to have the button centered vertically, similar to this:

https://i.sstatic.net/nH9j5.png

If anyone has suggestions on how I can modify my code to achieve this desired effect, I would greatly appreciate it.

Answer №1

To ensure the proper alignment of elements, it is recommended to place the button within the .form-group div following the last .checkbox-inline paragraph, given that the bootstrap .btn class is set to display inline-block.

<div class="container">
 <form name ="queryForm">
  <div class="form-group">
   <p class="checkbox-inline">
    <input type="checkbox" name="optionsRadios" id="checkOne" value="one">
    One
   </p>
   <p class="checkbox-inline">
    <input type="checkbox" name="optionsRadios" id="checkTwo" value="two">
    Two
   </p>
   <p class="checkbox-inline">
    <input type="checkbox" name="optionsRadios" id="checkThree" value="three">
    Three
   </p>
   <p class="checkbox-inline">
    <input type="checkbox" name="optionsOther" id="checkFour" value="four">
    Four
   </p>
   <button type="submit" class="btn btn-fill btn-info">Reload</button>
  </div>
 </form>
</div>

Answer №2

To achieve the desired layout, you can utilize the "pull-left" class to float both the form-group div and the button. In addition, feel free to adjust the margin style to best fit your design preferences.

<div class="container">
<form name ="queryForm clearfix">

<div class="form-group pull-left" style="margin:6px 10px 0 0">
    ....
</div>

<button type="submit" class="btn btn-fill btn-info pull-left">Reload</button>
</form>

</div>

http://codepen.io/partypete25/full/LNJyWV/

Answer №3

In order to align the labels at the center of the buttons vertically, one could adjust the line-height of the "p" elements to match the height of the button. For instance, if the button's height is 24px:

//styles to target the `<p>` elements with the class "checkbox-inline"

.checkbox-inline{display:inline; line-height:24px}

Answer №4

Swap out your second div for a span similar to this:

<div class="container">
<form name ="queryForm">

<span class="form-group">
    <p class="checkbox-inline">
        <input type="checkbox" name="optionsRadios" id="checkOne" value="one">
        One
    </p>
    <p class="checkbox-inline">
        <input type="checkbox" name="optionsRadios" id="checkTwo" value="two">
        Two
    </p>
    <p class="checkbox-inline">
        <input type="checkbox" name="optionsRadios" id="checkThree" value="three">
        Three
    </p>
    <p class="checkbox-inline">
        <input type="checkbox" name="optionsOther" id="checkFour" value="four">
        Four
    </p>
</span>

<button type="submit" class="btn btn-fill btn-info">Reload</button>
</form>

</div>

Answer №5

Make sure to configure your form as .form-inline and omit the use of .form-group for checkboxes. Refer to the bootstrap documentation for guidelines on inline forms: http://getbootstrap.com/css/#forms-inline

<div class="container">
  <form name="queryForm" class="form-inline">
    <p class="checkbox">
        <input name="optionsRadios" id="checkOne" value="one" type="checkbox">
        One
    </p>
    <p class="checkbox">
        <input name="optionsRadios" id="checkTwo" value="two" type="checkbox">
        Two
    </p>
    <p class="checkbox">
        <input name="optionsRadios" id="checkThree" value="three" type="checkbox">
        Three
    </p>
    <p class="checkbox">
       <input name="optionsOther" id="checkFour" value="four" type="checkbox">
       Four
    </p>
    <button type="submit" class="btn btn-fill btn-info">Reload</button>
  </form>
</div>

Check out this bootply link for a visual representation: http://www.bootply.com/5mffSWq7um

By following this standard bootstrap approach, you can avoid custom CSS and unnecessary HTML elements.

Answer №6

To center a button vertically, use the property valign="middle". Here's how you can implement it:

CSS:

button {
    valign: middle;
}

OR

HTML:

<button style="valign: middle;">text</button>

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

Display 1 row of content on larger LG screens and 2 rows on medium-sized MD screens using Bootstrap

How can I achieve 1 row with 12 cells on a large screen in Bootstrap, and for a smaller screen have 2 rows with 6 cells? Here is a visual representation of what I am trying to accomplish: https://i.stack.imgur.com/NgfaP.png This is the code I attempted: ...

Arrange two div elements side by side so they remain adjacent even when you adjust the browser size

After years of success with my floated left and right divs, I am now facing a challenge with responsive design. No longer able to rely on fixed widths, I find that when the screen size decreases, the right div moves below the left one. I know that using f ...

Performing a jQuery post request using AJAX and setting the content type

Greetings, here is the code snippet: <script type="text/javascript"> 14 $(document).ready(function() { 15 $('#find').click(function(){ 16 17 var amount = $(' ...

Functionalities of HTML controls

I currently have a select element in my HTML code which looks like this: <select> <option id="US" value="US"> </option> <option id="Canada" value="Canada"> </option> </select> My requirements are twofold: ...

HTML and CSS are two separate languages that work together to create web pages

I'm experiencing an issue with my CSS file not responding to my HTML file. I have imported the CSS file into my HTML file and both files are located in the same directory. It was working fine when they were written in the same file, but after separati ...

Guide to creating a toggle button

Can someone help me create a button that toggles between displaying block and display none when clicked? I've been trying to use Classlist.toggle with JavaScript, but I'm not sure if I have the correct classes targeted. let showCart = documen ...

When the div is clicked, it changes color and then reverts back to its original color when another

I have encountered an issue where I need to differentiate the div I clicked on in order to avoid confusion, as the pop-up menu on my website will be identical with different links but the same buttons. I have been struggling to find a solution for quite so ...

What is the best way to eliminate empty spaces from the container?

click here check out this image too Just getting the hang of Bootstrap. The first picture looks good, with the image as the background. But on the second picture, there are margins and a background color showing up. How can I get rid of those margins? Her ...

Is there a way to prevent on-click errors in ReactJS that someone can share with me?

The onclick listener was expected to be a function, but instead received a value of string type. getListener@http://localhost:3000/static/js/bundle.js:18256:15 accumulateSinglePhaseListeners@http://localhost:3000/static/js/bundle.js:22846:39 <button on ...

Engaging Interactive Image/Graphic with React and HTML

Just starting out with react/html and attempting to create an interactive Graphic/Image. My goal is to have a circle highlight in color when the mouse hovers over it, and change to a different color when clicked. Is this achievable? Any advice on how to ac ...

What steps can be taken to resolve the issue of the <td> element not being allowed as a child of an <a> tag?

https://i.stack.imgur.com/nsdA7.png How can I address these warnings? I utilized the material UI table component and suspect that the warnings are originating from component={Link} to={/patient/${patient.id}} <TableContainer className={styles.tableCo ...

Vertically animating an image using jQuery

I have been experimenting with trying to make an image appear as if it is floating by using jQuery to animate it vertically. After some research, I stumbled upon this thread: Animating a div up and down repeatedly which seems to have the solution I need. H ...

Accessing certain metafield data from a bulk of product uploads on Shopify

After setting up a "Product Reference" and "List of products" metafield, I can now easily populate it with multiple products. However, my goal is to showcase the images and titles of these added products individually for customization purposes. https://i.s ...

When rendering, HTML characters are not translated

My JavaScript code generates the following HTML structure: <div contenteditable="false" tabindex="0" class="ProseMirror"> <p> didn't project a significant increase</p> </div> When rendered in the browser, it shows the cha ...

Safari 5 experiences delays with JQuery and CSS3 animations

Encountering issues with jQuery animations specifically in Safari 5 on my Windows system. Struggling with a simple image fade slider that still has some flickering. The slider involves click events moving two pages at once, one active page right and the o ...

Changing images in vuejs

I am seeking to achieve a seamless transition between two images along with a corresponding legend. These images are sourced from an object-array collection. Since transitions operate only on single tags and components, I have devised a component to encap ...

What could be causing my jQuery to only toggle the first arrow in my HTML?

I am facing an issue with a series of divs generated from data, each containing an arrow that should toggle an expandable section. Strangely, only the first div is functioning properly: toggling the arrow icon and revealing the content upon click. When th ...

Ways to Press the Enter Key on Different Browsers

Looking for a solution to get the keypress action working properly? I have a chat feature where I need to send messages. Here is what I have in the Form-tag (JSP based): function SendMessage() { if (event.keyCode===13) { ale ...

Accordion checkbox with dynamic features

Currently, I am dynamically populating data into a jQuery accordion. My goal is to include a checkbox just before the <h2> text. <div id="checkbox"> <h2> <span> <input type="checkbox" class="mycheck" value="apple" / ...

Troubleshooting Issues with Implementing JavaScript for HTML5 Canvas

I've encountered an issue with my code. After fixing a previous bug, I now have a new one where the rectangle is not being drawn on the canvas. Surprisingly, the console isn't showing any errors. Here's the snippet of code: 13. var can ...