Occupying both horizontal and vertical space in a Bootstrap column

I have set up my buttons like this:

https://i.stack.imgur.com/OMfhp.png

In the image, you can see that the Left Option Button is larger, and I want all buttons to be like that. They are supposed to be aligned next to each other as I am using the Bootstrap grid system with 3x4 columns. The size of the button is currently not taking up all available horizontal space because I added this line to my HTML:

style="width: 400%; height: 500%;"
    

This was just to show visually what I am trying to achieve. I am new to bootstrap, so styling it is a bit challenging for me. Below is my HTML. Do I need CSS to accomplish what I want? If so, do I need to specify the exact height I want the buttons to be or is there a more relative method I can use to avoid issues on mobile devices?

I also need to add text inside the button that scales properly once the buttons are scaled correctly. Is that possible?

<div class="categories-container">
        <div class="container">
            <div class="row">
                <div class="col-md-4">
                    <form role="button">
                        <div class="input-group">
                            <input type="button" class="btn btn-primary btn-lg" value="Option" name="category-gameplay-btn" id="category-gameplay-btn">
                        </div>
                    </form>
                </div>
                <div class="col-md-4">
                    <form role="button">
                        <div class="input-group">
                            <input type="button" class="btn btn-primary btn-lg" value="Option" name="category-editor-btn" id="category-editor-btn">
                        </div>
                    </form>
                </div>
                <div class="col-md-4">
                    <form role="button">
                        <div class="input-group">
                            <input type="button" class="btn btn-primary btn-lg" value="Option" name="category-editor-btn" id="category-editor-btn">
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    

Answer №1

Here are a couple of examples that demonstrate the concept you are attempting to implement.

1) Utilize a Justified button group instead of a grid and incorporate media queries to cater to different viewport sizes.

2) Implement a grid similar to your example, then adjust it using media queries for responsiveness based on the viewport size.

Check out the example snippet below.

.btn.btn-bg {
  height: 300px;
  font-size: 60px;
}
@media (max-width: 767px) {
  .btn.btn-bg {
    height: 150px;
    font-size: 30px;
  }
}
@media (max-width: 480px) {
  .btn.btn-bg {
    height: 75px;
    font-size: 22px;
  }
}
@media (max-width: 360px) {
  .btn.btn-bg {
    height: 35px;
    font-size: 15px;
  }
}
/*Second Sample*/

.btn.btn-bg2 {
  height: 300px;
  font-size: 60px;
}
@media (max-width: 767px) {
  .btn.btn-bg2 {
    height: 60px;
    font-size: 30px;
  }
}
@media (max-width: 480px) {
  .btn.btn-bg2 {
    height: 45px;
    font-size: 20px;
  }
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
  <div class="well">
    <form role="search">
      <div class="input-group">
        <input type="text" class="form-control" placeholder="Search" name="srch-term" id="srch-term">
        <div class="input-group-btn">
          <button class="btn btn-default" type="submit"><span class="glyphicon glyphicon-search"></span>

          </button>
        </div>
      </div>
    </form>
  </div>
</div>
<div class="categories-container">
  <div class="container">
    <div class="btn-group btn-group-justified" role="group" aria-label="...">
      <div class="btn-group" role="group">
        <button type="button" class="btn btn-default btn-bg">Left</button>
      </div>
      <div class="btn-group" role="group">
        <button type="button" class="btn btn-default btn-bg">Middle</button>
      </div>
      <div class="btn-group" role="group">
        <button type="button" class="btn btn-default btn-bg">Right</button>
      </div>
    </div>
  </div>
</div>
<hr>
<div class="container">
  <div class="well">
    <form role="search">
      <div class="input-group">
        <input type="text" class="form-control" placeholder="Search" name="srch-term" id="srch-term">
        <div class="input-group-btn">
          <button class="btn btn-default" type="submit"><span class="glyphicon glyphicon-search"></span>

          </button>
        </div>
      </div>
    </form>
  </div>
</div>
<div class="categories-container">
  <div class="container">
    <div class="row ">
      <div class="col-sm-4">
        <input type="button" class="btn btn-primary btn-lg btn-block btn-bg2" value="Option" name="category-gameplay-btn" id="category-gameplay-btn">
      </div>
      <div class="col-sm-4">
        <input type="button" class="btn btn-primary btn-lg btn-block btn-bg2" value="Option" name="category-editor-btn" id="category-editor-btn">
      </div>
      <div class="col-sm-4">
        <input type="button" class="btn btn-primary btn-lg btn-block btn-bg2" value="Option" name="category-editor-btn" id="category-editor-btn">
      </div>
    </div>
  </div>
</div>

Answer №2

To adjust the width, you need to ensure that both the button and its containing div are set to 100% width:

.btn, .input-group {
    width: 100%;
}

For the height, you can utilize CSS to scale it relative to the viewport size using vw units, or alternatively, you could dynamically adjust the height based on the width using jQuery:

$(document).ready(btnHeight);
$(window).on('resize', btnHeight);

function btnHeight() {
    var width = $('.btn').width();
    $('.btn').css('height', width*0.8);
};

To scale the font size, you can employ vw units or incorporate media queries for finer control. Explore this example on Bootply

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

Achieving equal alignment of items with flexbox

As someone who is just starting to learn about HTML and CSS, I have been working on creating toggle buttons that I want to align dynamically in the center of the screen. I recently discovered flexbox which has made this process easier for me. However, one ...

JavaScript encountered an error stating "phone is not defined" due to an uncaught ReferenceError

Whenever I click on the Phone Number, it displays an error message saying that the function is not defined. How can I fix this issue? Thank you in advance! Here's the code snippet: <div class="product-label"> <h4><?php echo $p["Fu ...

Hover to stop menu movement

Can someone help me achieve a similar menu hover effect like this one? I'm trying to create a menu with a hold/pause effect on hover, specifically in the section titled "A programme for every vision". The goal is to navigate through the sub menus smo ...

Issue Encountered While Attempting to Show a Div Element within a Function

Check out this HTML code snippet: <div class="div1" id ="div1" onclick="onStepClicked()" style ="text-align:center">Step 1</div> And here is the corresponding Script: function onStepClicked() { var elem = document.getElementById(&apo ...

I've created a logo, but why are there two logos on my website?

There seems to be an issue with two divs stacking on top of each other, which is not the desired layout. This problem occurs when five div boxes are added. The goal is to have all divs in a single row, but it's unclear why this layout is not working ...

I'm puzzled as to why my fixed element is gravitating towards the right side of the entire screen instead of aligning with the right side of its parent element

I have inserted a code snippet that highlights my issue. I am attempting to ensure that the .navigation element remains fixed at the top of the colored divs, however, when using 'right: 0;', the .navigation element seems to shift to the right sid ...

When the screen size decreases, display the title on two lines

Currently, I am in the process of developing a react web application with the assistance of redux. My main objective is to ensure that the page is highly responsive. At this point, there is a title positioned at the top displaying: Actions to do: Past due ...

What is the best way to update text in an element when hovering or activating it?

I am currently designing a website with a prominently placed "Hire me" button in the center of the page. The button was implemented using the following code: <div id="hire_me_button"> <a href="contact.html"><h4 id="hire_me" class="butto ...

What is the best way to eliminate duplicate values from a column in a data set

Time To Status Off-Track On-Track 10:28 AM gf 6233 4 4 10:32 AM dd 3835 7 10:40 AM ss 3235 4 10:43 AM ww 6621 5 11:06 AM zz 3837 ...

Is there a way to identify the source of a div's scrolling behavior?

While working on a complex web page that involves multiple JQuery Dialogs and other widgets, I encountered a frustrating issue. Some of the dialogs contain divs with scrolling abilities (using overflow-y with a fixed height). Whenever I click on one dialog ...

Switching over to the latest version of Material-UI, v1.x.x

Currently, my app relies on Material-UI v0.17.0 which is not compatible with React v16.0.0. In order to make it work, I need to upgrade to Material-UI v1.0.0. I came across a migration tool here, but it only updates import statements. Many props have chan ...

When the play button is clicked, the video slides over to the left

Whenever I attempt to click on the video link, it seems to shift over to the left side of the page. The link is positioned in the center and I would prefer for the video to open up at the same central location. However, it consistently opens up on the left ...

Using JavaScript to generate a <style> element and accessing the cssRules

After spending countless hours trying to solve this problem, I'm hoping that my question isn't too foolish. This is a continuation of a previous question about creating a style tag with JavaScript on Stack Overflow. The solutions provided by Tom ...

Executing code upon the completion of jquery's slideUp() function

Is there a method to trigger the execution of html() only after the completion of slideUp()? <p class="test">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent tortor elit</p> $(".test").slideUp().html(""); I attempted using ...

After applying 'all: unset;' to remove all styles, the CSS hyphens property does not work as expected in Chrome

After applying this CSS code to remove all styles: * { all: unset; display: revert; } The issue arises in Chrome browser where CSS Hyphens are not taking effect. This can be seen with the following example: div { font-size: 3rem; -webkit-hy ...

Transforming JSP style tags into CSS declarations

Within my JSP file, I have various tags that look like this: <style type="text/css"> #mask { display: none; cursor: wait; z-index: 99999; position: absolute; top: 0; left: 0; height: 100%; ...

Category-Specific Page Display

Can anyone help with CSS coding using Wordpress Elementor to make a page only display posts from the coaching category? I attempted to use this selector article.type-post:not(.category-coaching) { display: none; }, but it doesn't seem to be functi ...

The Bootstrap modal stubbornly refuses to close even after resetting the HTML body

I am having an issue with my bootstrap modal where the closeModal button is not functioning properly after the printModal button has been clicked. The modal does not close as expected. Step 1: Click on the printModal button after the modal pops up (this w ...

Is there a method to exclude children objects from spring animations during application?

Is it possible to create a fading in and out effect for a div (for example, to cycle through different backgrounds) while keeping its children (such as text) visible at full opacity at all times? {transitions((style, <animated.div class={ bg[i] + ...

What is the process for implementing a grid with 5 columns on larger screens and 2 columns on smaller screens using reactjs?

I am currently working on building a Grid using material UI and reactJs. I found the guidelines on this link https://mui.com/system/react-grid/. However, there seems to be an issue with creating 5 columns in the grid. I attempted to create a custom grid ...