Tips for maintaining the alignment of four buttons in a single row as the size of the screen changes

I'm creating a simple browser game as part of my web development learning process. I have a set of divs that represent a warrior, and at the head of the "div table" I have a group of 4 buttons arranged horizontally. However, when the screen size is reduced, the buttons do not stay in the same row. Additionally, there are white spaces between the buttons, but I want them to dynamically fill the entire button group even if there are fewer than 4 buttons. Can anyone provide assistance with this?

Check out my code on jsfiddle:

.div-TableHeadName {
  padding-top:6px;
  height:35px;
  background-color: darkgrey;
}
.div-TableHeadClass {
  padding-top:6px;
  background-color: darkgrey;
  height:35px;
}
.div-TableBodyImage{
  height:160px;
  background-color: lightgrey;
}
.div-TableBodyDescription{
    height: 160px;
    background-color: lightgrey;
}
.btn--actionType{
  background-color: lightgrey;
  border-radius: 0 !important;
  height: 35px;
  width: 25%
}

.btn--actionType:hover{
  background-color: red;
}
.btn--performAction{
  background-color: black;
  border-radius: 0 !important;
  color: white;
  height: 35px;
  width: 25%
}
.btn--group{
  cursor:pointer;
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<body>
  <div class="div-Table">
    <div class="col-md-2 col-sm-2 col-xs-2 div-TableHeadName">
      <span>Guldan</span>
    </div>
    <div class="col-md-4 col-sm-4 col-xs-4 div-TableHeadClass">
      <span>Warrior</span>
    </div>
    <div class="col-md-6 col-sm-6 col-xs-6">
      <btn-group data-toggle="buttons" class="btn--group">
        <div class="btn btn--actionType">
          <label>
            <input type="radio" name="action" value="sword"/>Sword
          </label>
        </div>
        <div class="btn btn--actionType">
          <label>
            <input type="radio" name="action" value="axe"/>Axe
          </label>
        </div>
        <div class="btn btn--actionType">
          <label>
            <input type="radio" name="action" value="bow"/>Bow
          </label>
        </div>
        <div type="button" class="btn btn--performAction">Attack
        </div>
      </btn-group>
    </div>
  </div>
  <div style="padding-top:10px" class="col-md-2 col-sm-2 col-xs-2 div-TableBodyImage">  
    <img src="https://upload.wikimedia.org/wikipedia/en/b/b1/Portrait_placeholder.png" width="100"/>
  </div>
  <div style="padding: 10px" class="col-md-10 col-sm-10 col-xs-10 div-TableBodyDescription">
    <span>This is a description for Guldan, an orc warrior.</span>
  </div>
</body>

Answer №1

.div-TableHeadName {
  padding-top:6px;
  height:35px;
  background-color: darkgrey;
}
.div-TableHeadClass {
  padding-top:6px;
  background-color: darkgrey;
  height:35px;
}
.div-TableBodyImage{
  height:160px;
  background-color: lightgrey;
}
.div-TableBodyDescription{
    height: 160px;
    background-color: lightgrey;
}
.btn--actionType{
  background-color: lightgrey;
  border-radius: 0 !important;
  height: 35px;
  width: 25%;
  float: left;
}

.btn--actionType:hover{
  background-color: red;
}
.btn--performAction{
  background-color: black;
  border-radius: 0 !important;
  color: white;
  height: 35px;
  width: 25%
}
.btn--group{
  cursor:pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<body>
  <div class="div-Table">
    <div class="col-md-6 col-sm-6 col-xs-6">
      <btn-group data-toggle="buttons" class="btn--group">
        <div class="btn btn--actionType">
          <label>
            <input type="radio" name="action" value="sword"/>Sword
          </label>
        </div>
        <div class="btn btn--actionType">
          <label>
            <input type="radio" name="action" value="axe"/>Axe
          </label>
        </div>
        <div class="btn btn--actionType">
          <label>
            <input type="radio" name="action" value="bow"/>Bow
          </label>
        </div>
        <div type="button" class="btn btn--performAction">Attack
        </div>
      </btn-group>
    </div>  
  </div>    
</body>

Sometimes simplifying your issue to the essential elements can lead to a solution. In the provided code, I have focused on those key elements. It appears that using the "float" property for the buttons instead of "inline-block" resolves both of your problems. Unlike inline-block, floating does not add additional space. The wrapping issue with your 25% buttons is caused by this extra space.

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

Tips for preventing images from stretching the width and height of my HTML

I am facing an issue with my SVG files positioned as "absolute" on my page. When they are close to the corners of the page, they end up expanding the width of my Container element (using Material UI React). I have tried setting "maxWidth":"100vw" on the ...

Utilize JavaScript to send login information to a website

I have a specific task in mind: creating a script that will automatically fill in certain data on an HTML website. To illustrate, let's imagine the site is the StackOverflow login page and I want to input my username and password. For the username fi ...

jQuery - Event cannot be triggered on the 'deselect' or 'focusout' of <option> tag

Check out the demo here Hello there, I have a situation where I need an input box to appear below a select option, only if the user selects "Other". The code currently uses the .click() function on the option, but now I am trying to make the input box di ...

Develop a personalized event using JavaScript and activate it

I have encountered a problem with a Google ad that expands on click and closes when the close button is hit. However, due to changing conditions, I now need it to expand first and then automatically close after a certain time. Additionally, every time it e ...

Utilizing custom links for AJAX to showcase targeted pages: a beginner's guide

I am putting the final touches on my website and realized that it may be difficult to promote specific sections of the site because the browser address never changes. When visitors click on links, they open in a div using Ajax coding. However, if I want to ...

Hide when reaching the end with d-none

One of the challenges I'm facing is aligning a button to the right side of a column while still utilizing d-none to control its display. Previously, I used d-flex justify-content-md-around justify-content-lg-end for alignment before adding d-none, but ...

Unable to view images on Wordpress theme

I am currently facing an issue where some images in my asset folder are not displaying properly when I convert my HTML/CSS/JS template to Wordpress. The main problem is with the image that should show up when you first visit the website. Below is the CSS c ...

My Javascript file in AngularJS is giving me trouble with the error message: "Uncaught Error: [$injector:modulerr]"

I am currently enrolled in an AngularJS course and the instructor is using version 1.0.8, while I have version 1.7.8 installed. I would like to update my version. Can anyone provide guidance on how to do this? File: index.html <!doctype html> <h ...

Building an expandable vertical dropdown with Bootstrap that opens with a click

My goal is to design a vertical menu that expands when clicked, revealing 3 links for each item. I currently have the following setup: This is the initial layout: After clicking all items: The code I've implemented so far looks like this: <!DOC ...

In Groovy (or Java), learn the techniques to properly escape double quotes within HTML inner text while leaving attributes untouched

I am currently utilizing an HTML rendering engine that is based on Groovy within a Web Content Management (WCM) system. I have encountered a scenario where the user inputs rich text content into a form based on TinyMCE, which appears as follows: <p> ...

Using the `document.querySelector` method to target the `.mat-progress-bar-fill::after` element

Is there a way to dynamically adjust the fill value of an Angular Material Progress Bar? In CSS, I can achieve this with: ::ng-deep .mat-progress-bar-fill::after { background-color: red; } However, since the value needs to be dynamic, I am unable to do ...

When an element is focused using jQuery, allow another element to become clickable

I've been working on implementing an input field along with a dropdown list right next to it. The concept is that users can either type in the input field or choose a value from the dropdown list. I attempted to use styles to show the dropdown list wh ...

"Trouble with making jQuery AJAX calls on Internet Explorer versions 8 and 9

I've been searching for the answer to this problem without any luck. I have a page with jquery ajax calls to an API service. It works well in Chrome, Safari, Firefox, and IE 10, but fails in IE 9 and 8. Here is the code: $.ajax({ ...

Creating an HTML table syntax from a PHP 2-dimensional array

I am looking for a way to extract data from a bi-dimensional array and display it in an HTML table format. Here is an example of the array: $grid = array( array(0,0,0,0),array(0,0,0,0),array(0,0,0,0),array(0,0,0,0),array(0,0,0,0)); $grid[0][0]=4;$grid[0][ ...

The input form in my Node.js project is not adapting to different screen sizes. I am currently utilizing ejs as the template

I have integrated ejs as a template in my Node.js project, but I am encountering an issue with the input form in the following code snippet. The form is unresponsive, preventing me from entering text or clicking on any buttons. What could be causing this ...

Issue encountered with AJAX multiple image uploader

I'm attempting to create an PHP and JavaScript (jQuery using $.ajax) image uploader. HTML: <form method="post" action="php/inc.upload.php" id="upload-form" enctype="multipart/form-data"> <input type="file" id="file-input" name="file[]" a ...

Is there a mistake in the way I am creating a horizontal navigation bar?

Currently working on creating a simple navigation bar using HTML/CSS for a Java/Spring Boot project. Admittedly, my HTML/CSS skills are quite limited as you can see below. I'm aware that there might be some mistakes in my approach. Thank you in advanc ...

Error message: "Unexpected token" encountered while using the three.js GLTFLoader() function

I have a requirement to load a .glb model into three.js by using the GLTFLoader. I was able to successfully create a rotating 3D mesh on a canvas without encountering any errors in the console. However, when I tried to replace it with the .glb model, I enc ...

Issue with background image resizing when touched on mobile Chrome due to background-size property set to cover

My current challenge involves setting a background image for a mobile page using a new image specifically designed for mobile devices. The image is set with the property background-size: cover, and it works perfectly on all platforms except for mobile Chro ...

NodeJS allows for seamless uploading of files

I'm encountering difficulties when trying to upload a file using nodeJS and Angular. I've come across some solutions, but they all involve Ajax which is unfamiliar territory for me. Is there a way to achieve this without using Ajax? Whenever I ...