Centered text in <td> with CSS aligned to the right

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

Is there a way to align the 3 input fields so that their right edges are all vertical? I still want the text+Input to be centered within the column but aligned vertically...

Using Bootstrap 3.3.7

HTML:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="table-responsive col-lg-12 ">
<table class="table table-bordered text-center">
    <thead>
    </thead>
    <tbody>
        <tr>
            <th class="text-center" scope="row">Net. Config</th>
            <td>
                <form class="form-inline">
                    IP Address:
                    <input type="text" class="form-control txbIPsubmit" id="SYST_IPAD" placeholder="0.0.0.0">
                </form>
                <form class="form-inline">
                    NetMask :
                    <input type="text" class="form-control txbIPsubmit" id="SYST_NETM" placeholder="0.0.0.0">
                </form>
                <form class="form-inline">
                    Gateway :
                    <input type="text" class="form-control txbIPsubmit" id="SYST_GWAD" placeholder="0.0.0.0">
                </form>
                <div class="form-control-static">
                    <input type="checkbox" class="form-check-input" id="SYST_DHCP">
                    <label class="form-check-label" for="SYST_DHCP">DHCP</label>
                </div>

                <form class="form-inline">
                    <button type="button" class="btn btn-light" id="btnNetConfig">Apply</button>
                </form>
            </td>
        </tr>
        <tr>
    </tbody>
</table>
</div>

Answer №1

It's important to note that there are several improvements that can be made to optimize the code provided.

First and foremost: Instead of using individual form tags for each field, it is best practice to wrap the entire table in a single form tag.

Secondly: Tables should be avoided for non-tabular content. Consider using alternative methods like flexbox for layout purposes, as tables are primarily meant for displaying tabular data.

Thirdly: The proper usage of th tags is within the thead tags. Th tags should serve as headers for each column in the table.

If you decide to continue using tables, a better approach would be to have a td for the field label and a separate td for the input in each row. You can utilize colspan and rowspan attributes to make cells span across multiple columns or rows. Here is an updated example:

<table>
    <tr>
        <td rowspan="3">Network Configuration</td>
        <td style="text-align:right;">IP Address</td>
        <td><input type="text" id="SYST_IPAD" placeholder="0.0.0.0"></td>
    </tr>
    <tr>
        <td style="text-align:right;">Netmask</td>
        <td><input type="text" id="SYST_NETM" placeholder="0.0.0.0"></td>
    </tr>
    <tr>
        <td style="text-align:right;">Gateway</td>
        <td><input type="text" id="SYST_GWAD" placeholder="0.0.0.0"></td>
    </tr>
</table>

Answer №2

If you're looking to address alignment issues and improve usability/accessibility at the same time, consider implementing a flexbox display for your form elements. Adding <label>s to your text and setting them with flex-grow: 1 can help ensure they take up maximum horizontal space. This approach also creates a second child element within each parent flex container for enhanced manipulation.

form {
  display: flex;
}

label {
  flex-grow: 1;
  text-align: right;
  padding-right: 10px;
}
<form>
  <label for="t1">String</label><input type="text" id="t1">
</form>

<form>
  <label for="t2">Long string</label><input type="text" id="t2">
</form>

<form>
  <label for="t3">The longest string</label><input type="text" id="t3">
</form>

http://jsfiddle.net/cyhgk9j2/1/

Answer №3

If you're utilizing bootstrap, you have the option to utilize col-md-4 and col-md-8 for vertical alignment of elements. To center text and input, you can apply text-align: center;

To see an example, check out this fiddle

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

Row within a table displaying link-like behavior

Here is the code I'm currently using: $('.table-striped tr').click( function() { var link = $(this).find('a').attr('href'); if(link != 'undefined') { window.location = link; } }).hover( func ...

When the browser is resized, the fadeIn() function restarts from the

My plan was to create a dynamic effect where a browser-sized div would rotate through 3 different backgrounds using jQuery's fading effect. However, I encountered an issue - whenever I resize the browser window, the effect restarts from the beginning ...

The CSS on my website is causing issues with the recaptcha functionality

Recently, I've been working on a website that requires spam protection for the contact form. To combat this issue, I decided to integrate reCAPTCHA into the form. However, after completing the form and applying the necessary CSS styles, I noticed tha ...

The particles.js with absolute positioning is currently overlapping my div with relative positioning

Visit this link <div class="outer-container"> <div id="particles-js"> <div class="your-content"> <article id="3" class="bg-dusk transition md:group-hover:opacity-50 md:hover:opacity-important md:hov ...

Navigating through a Collection of Pictures using Mouse Movement and Left-click Button

Trying to create a customized PACS viewer for scrolling through a series of CT head images. However, encountering an issue with scrolling through all 59 images. Currently, able to scroll from the first to the 59th image, but struggling to loop back to the ...

Slider with FadeIn effect remains unresponsive to the FadeOut command (JQuery / Javascript)

I'm currently working on a slider that is supposed to fade in and out. However, I am facing an issue where the slide fades in correctly but instantly disappears instead of fading out. Do you have any insights into why this might be happening and any s ...

Animate a div to sense whether it has reached the top or bottom position

Is it possible for a div to animate when it reaches almost halfway while scrolling? I'm looking to achieve this effect on a sticky sidebar, similar to how it works on this website: sample This is the code I have: $(function(){ // document ready ...

-moz-box-reflect - Styling for FireFox

I've been attempting to achieve a similar effect to this tutorial at http://designshack.net/tutorialexamples/HoverEffects/Ex5.html. However, I'm encountering issues with getting the reflection of the image to display properly in IE and Firefox. H ...

Combine two FontAwesome icons in a stacked manner

Is there a way to group 2 icons together and display them one above the other? I attempted to use the fa-stack class, but the images are overlapping. How can I achieve this layout? <span class="fa-stack fa-lg"> <i class="fa fa-envelope fa-stack ...

Stylish dropdown menu design inspired by W3CSS website

I recently implemented a CSS dropdown menu example that I found on a website, but it's not working with my code. I double-checked for typos but couldn't find any. Even when I tried to directly copy the code and replace the content with my own, i ...

Steps for modifying an element in an array using Javascript

Currently, I am a beginner in the realm of JavaScript and I am trying to build a todo-style application. So far, I have successfully managed to create, display, and delete items from an array. However, I am facing challenges when it comes to editing these ...

The text is placed over a beautiful SVG image, adding a decorative touch to

Im interested in incorporating an SVG image of a curly bracket below and between two words, similar to the example shown. https://i.sstatic.net/KuSVg.png Considering the need for responsiveness, I initially attempted adding the image directly into the HT ...

Working with CSS styles for the <datalist> element

I currently have a basic datalist drop-down menu and I am looking to customize the CSS to match the style of other fields on my website. However, as someone new to web design, I am unsure of how to go about this process. Check out the code here: http://j ...

What is the best way to make a multi-column image responsive in amp-html code?

Here is the concept I was referring to, you can see it in action by following this link <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> * { box-sizing: border-bo ...

How can I incorporate classes from multiple CSS files into my WordPress theme?

Currently, I am utilizing wp_enqueue_style to incorporate two CSS files within a single function. However, the issue that arises is when I try to apply a class, it seems that only classes from one of the files can be utilized and it ends up overriding anot ...

Retrieving information from AngularJS modal window

Seeking a solution to retrieve data FROM modal to invoking controller, as most examples only cover sending data TO the modal. What is the proper method for achieving this? Here is the form used within the modal: <form class="form-horizontal"> < ...

Creating HTML code for a mobile responsive design

I am facing an issue with my clinic webpage where the images appear differently on PC and mobile devices. I am new to HTML and CSS, so I tried using max-width: 100% but it didn't work. The code was originally created by someone else and I need help fi ...

If viewed on a mobile device, separate the array (indexed list) into two rows

Currently, I am working on my Ionic project where I am trying to implement an indexed list horizontally instead of vertically. While the list looks good as it is now, I want to make sure it supports smaller screen devices too by splitting the list into two ...

Changing the hover color of an Angular Material MD Button

<div class="non-active" layout layout-align='space-around center'> <md-button ng-click="$ctrl.widget.type = 'chart'; $ctrl.validateForm()" layout='column' ng-class="{selIcon : $ctrl.widget.type == ' ...

After clicking the 'add row' button, I successfully added a new row; however, the jQuery date

I encountered an issue with the datepicker when adding it to dynamically added rows. The datepicker was not functioning properly on the added rows, except for the first row where it worked perfectly. Strangely, removing the first row resulted in the datepi ...