Troubles with aligning cell contents horizontally in Bootstrap 4 table

https://i.sstatic.net/fNPD0.pngI am utilizing bootstrap 4 tables to design a customizable 24 x 7 hourly scheduler. My challenge lies in aligning the radio buttons horizontally within each table cell, ensuring that they are given the necessary width individually. However, I am facing difficulties in achieving this, particularly when the table extends beyond the screen width, requiring horizontal adjustment.

The snippet of code illustrating this problem is as follows:

<div class="row form-group ml-md-2 mr-md-2">
   <div class="col-md-12">
       <table class="table table-bordered table-responsive table-hover table-striped table-condensed">
           <thead>
               <tr>
                   <th></th>
                   <th>8am</th>
                   <th>9am</th>
                   <th>10am</th>
                   <th>11am</th>
                   <th>12pm</th>
                   <th>13pm</th>
                   <th>14pm</th>
                   <th>15pm</th>
                   <th>16pm</th>
                   <th>17pm</th>
                   <th>18pm</th>
                   <th>13pm</th>
               </tr>
           </thead>
           <tbody>
               <tr>
                   <td><strong>Sun</strong></td>
                   <td>
                       <div class="form-group">
                           <div class="radio">
                               <label class="control-label font-weight-bold">
                                   <input type="radio" asp-for="@Model.MachineState" value="Manual" />
                                   <span <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f3928083de85929f9a9792879a9c9c">(Email shown here)</a>></span>Manual
                               </label>
                           </div>
                           <div class="radio">
                               <label class="control-label font-weight-bold">
                                   <input type="radio" asp-for="@Model.MachineState" value="On" />
                                   <span <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f6978586db80997a7977829f99">(Email shown here)</a>></span>On
                               </label>
                           </div>
                           <div class="radio">
                               <label class="control-label font-weight-bold">
                                   <input type="radio" asp-for="@Model.MachineState" value="Off" />
                                   <span <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1b7a686b366d727471737e7235367d7442224b74627131617"> </a>></span>Off
                               </label>
                           </div>
                       </div>
                   </td>
                   ...  @*Repeat this <td></td> for other day - time cells. *@ 

               </tr>
           </tbody>
       </table>
   </div>
</div>
[![enter image description here][1]][1]

Answer №1

As was pointed out in your comment, ensuring horizontal alignment requires setting a minimum width.

To achieve this, simply include the following CSS code within your style section:

<style>
    .table td:not(:first-child) {
        min-width: 100px;
    }
</style>

After implementing the above code, you will see the desired result:

https://i.sstatic.net/CiPDt.gif

Answer №2

1) For those utilizing bootsrap4, include the class form-check-inline to ensure radio buttons are displayed on the same line. For an example, view radio-line.

2) The sizing of the table is dynamic and will adjust automatically. To enable auto-scroll for the entire table instead of individual cells, utilize the following CSS classes:

  overflow-y: hidden;
  overflow-x: auto;

3) Refer to horizontally-scroll with radio-buttons inline for guidance.

4) If you prefer auto-scroll for each cell, establish a class and apply the following CSS to every <td>:

    max-width: 20px;
    overflow-y: auto;

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

modal failing to populate values within control elements in modal

Encountering an issue where the code is calling a Modal, but upon loading it fails to populate the controls with values sent into the JavaScript. No errors are thrown, yet all controls remain empty. As a newcomer to AJAX and JavaScript, I suspect there mig ...

Unveiling the secrets: Accessing password regulations in an Azure AD domain using the Microsoft Graph API

Looking to retrieve password policy properties of a domain in Azure AD and identify users falling under specific policies if there are multiple. Is it possible to obtain this information through an API? Can you provide detailed guidance on how to achieve ...

Unable to open Winforms app on another computer without Visual Studio installation

I have two laptops. The first one is a MacBook Air where I am using Visual Studio 2015 and SQL Server 2014 Express to develop a WinForms application. When I transfer the app to my second laptop, a Sony, it works fine as long as it only involves WinForms fe ...

Guide to transforming Tailwind CSS into a class and saving it in a CSS document

Recently, I implemented Tailwind CSS to style my application. It has been a helpful tool, but I am looking to consolidate all the CSS into one file for better organization. I want to keep it separate from the HTML code. My attempt to convert the following ...

What specific control from the Telerik suite is being utilized to showcase the FAQs on this specific webpage?

Check out this link for more information on implementing the Telerik Premium Collection for .NET. Any suggestions on how to go about this? Appreciate it. Thanks! ...

Is there a way to extract the data enclosed by "<div>" and "</div>" utilizing python's sgmllib or parser module?

This is the HTML snippet provided: <div id="wrap"> <div id="content"> <h1>head</h1> <ul class="jobpara"> <li class="floatl"><span>time:</span>2013-08-13</li> <li clas ...

Incorporate live data into a sample chart.js file within a Django template

I'm currently using the "start bootstrap4" template in my Django project. I need to customize the data displayed in a chart contained within the template by modifying the chart-pie-demo.js file. In my views.py file, I have defined the data that I wan ...

Stop the span within the paragraph from breaking onto a new line

I have a situation where I need quote symbols to be placed inside span elements that are children of a p element. Each quote symbol requires slightly different CSS styles, and they must be included in the HTML rather than in the CSS due to backend restrict ...

Automatically close an element when you click on a different element

Hello everyone! I need some help again. I'm working on a script that displays an overlay when a menu item is clicked. Within this menu, there is a modal contact form with a close icon or anchor that should appear when clicked. My goal is to have the o ...

Tips for invoking the href function in jwplayer with individual arguments

I need assistance with configuring jwplayer to load a list of href links one by one. Each href link includes a function that needs to be triggered automatically with specific parameters passed to JavaScript. Below is the code snippet I am currently worki ...

Is there a way to limit HTML wrapping to 79 characters in TextMate?

I'm currently using TextMate to work on my HTML projects. When I select View > Wrap > 79 characters for certain types of content, it wraps at 79 characters as expected. But when it comes to working with HTML, this feature doesn't seem to ...

Stop div from exceeding the page boundaries

Here's my current dilemma: I have a simple css3 tooltip-menu that is hidden by default and appears on mouseover. It has a fixed width and is positioned absolutely to the right (with an arrow in the middle pointing to the hovered element). The issue I ...

When resizing an anchor tag with a percentage in CSS, the child image width may not scale accordingly

In short, I have multiple draggable images on a map enclosed in anchor tags (<a><img></a>) to enable keyboard dragging. The original image sizes vary, but they are all too large, so I reduced them to 20% of their original sizes using the ...

fileuploader with clipboard functionality and easy drag-and-drop feature using HTML and JavaScript

I am in need of a file uploader that can be implemented using HTML and JS. My goal is to have it work on multiple platforms, specifically Google Chrome, FireFox, and IE9+, with the capability of copying and pasting screenshots as well as dragging and dropp ...

The Selinium Code suddenly stops functioning properly after running smoothly for a certain period of time

Looking for a solution to extract text from the "alt" attribute of 37 logos on a webpage? Check out the HTML code below: <div class="logo__wrapper col-6 col-sm-4 col-md col-xl -gutter-bottom"> <div data-lazy="true" data-src= ...

How can HTML be assigned to a PHP variable without losing its formatting?

My goal is to store HTML in a variable in PHP to help with modularizing my code. $html_block1 = "<div class='item'> <img src='chicago.jpg' alt='Chicago'> <div class='carousel-caption&ap ...

Website Navigation: A guide to organizing columns and rows for optimal user experience

Just reaching out with a question regarding my coding process. Currently, I am in the midst of translating the website's navigation design into code. The attached image showcases the navigation layout consisting of 10 rows and 8 columns. Below is a s ...

Instructions for connecting my website's URL to a designated channel (button) on an external widget

My goal is to connect a channel from a third-party widget to my website through a URL link with a button. I want the channel to open directly under that specific URL. I attempted this method, but it seems to be ineffective: shareurexperience Animal "> ...

Is there a way to create a link in Javascript that directs to a specific div on a new

Is there a way to create a link that not only opens a new page but also automatically scrolls to a specific section within that page? ...

I am having trouble with the dropdown button in my Bootstrap - it just won't seem

I've exhausted all YouTube tutorials and followed the entire Bootstrap documentation, but I still can't seem to get it to work. Please, someone, help me figure out why it's not functioning properly :( This is the basic HTML bootstrap code I ...