Struggled with controlling labels and fields in bootstrap framework

Struggling with a bootstrap template, I found it difficult to adjust the size and alignment of labels and input fields. Here are images showing what I currently have and what I aim for. Despite checking out the grid system documentation at here, I couldn't grasp it.

Current Layout:

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

Desired Layout: https://i.sstatic.net/1aBBv.png

Below is the code snippet used:

<div class="container fluid custom-locale-form">
 <div class="form-group row">
        <label for="numeroTelephone" class="col-xs-3 col-sm-3 col-md-3 col-lg-3 form-control-label">Information</label>
        <div class="col-xs-9 col-sm-9 col-md-9 col-lg-9">

        </div>
    </div>


    <div class="form-group row">
        <label for="numeroTelephone" class="col-xs-3 col-sm-3 col-md-3 col-lg-3 form-control-label">Phone Number</label>
        <div class="col-xs-9 col-sm-9 col-md-9 col-lg-9">
            {{ form_widget(form.numeroTelephone, {'attr':{'class': 'form-control'}}) }}
        </div>
    </div>

    <div class="form-group row">
        <label for="numeroFax" class="col-xs-3 col-sm-3 col-md-3 col-lg-3 form-control-label">Fax Number</label>
        <div class="col-xs-9 col-sm-9 col-md-9 col-lg-9">
            {{ form_widget(form.numeroFax, {'attr':{'class': 'form-control'}}) }}
        </div>
    </div>

    <div class="form-group row">
        <label for="email" class="col-xs-3 col-sm-3 col-md-3 col-lg-3 form-control-label">Email</label>
        <div class="col-xs-9 col-sm-9 col-md-9 col-lg-9">
            {{ form_widget(form.email, {'attr':{'class': 'form-control'}}) }}
        </div>
    </div>

    <div class="form-group row">
        <label for="inputPassword3" class="col-xs-3 col-sm-3 col-md-3 col-lg-3 form-control-label">Website</label>
        <div class="col-xs-9 col-sm-9 col-md-9 col-lg-9">
            {{ form_widget(form.siteWeb, {'attr':{'class': 'form-control'}}) }}
        </div>
    </div>
</div>

Answer №1

Here are a couple of tips and suggestions for improving your code.

  1. Instead of using multiple grid classes like
    col-xs-3 col-sm-3 col-md-3 col-lg-3
    , you can simply use the smallest resolution class and it will automatically adjust to larger screens. For example, you can just use class="col-xs-3".
  2. If you want to add spacing before or after a column, you can set the offset property like this: class="col-xs-2 col-xs-offset-1". This way, you can keep the width within 3 columns but have the first column act as blank space, limiting the content width to 2 columns. If you need fixed indentation for labels without using columns, you can add padding to the labels with a CSS rule like:

    .form-group label {
      padding-left: 20px;
    }
    

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 properly labeling images

My database consists of three tables. The first table is the images table, which includes fields for picture ID (primary key), names, blob, and description. The second table is the tags table, containing a tag ID (primary key) and tag name. The third tab ...

There is a noticeable absence of top padding

Currently in the process of designing a custom WP theme, I have encountered an issue with styling the header links as seen in the image. Despite my attempts to fill the bluish gradient area with a black background using the .current class, the desired effe ...

Changing the caret position in a contenteditable div using HTML React

In a recent project I worked on, I included contenteditable divs. Whenever the enter key is pressed within one of these divs, it splits into two separate contenteditable divs. However, after React re-renders the components, the caret tends to go to the beg ...

Creating a canvas with multiple label introductions can be achieved by following these

I am looking to group labels and sublabels on the x-axis of a canvas component. Currently, I only have sublabels like: RTI_0, RTI_1... I would like to add labels to these sublabels like: RTI = {RTI_0,RTI_1,RTI_2] BB = {BB_0, BB_1,BB_2,BB_3] <div cla ...

Incantation within ng-include | src involving a series of characters

Is there a way to create a URL in ng-include|src by combining an expression and a constant string? I've attempted the code below, but it doesn't seem to be working. <aside ng-include src="{{staticPath}} + 'assets/tpl/products-feed-histor ...

Are the JQuery appended elements exceeding the width of the parent div?

I have an HTML div that is styled using the Bootstrap class span9. <div class="span9"> <div id = "selectedtags" class="well"> </div> <button class="btn" type="button" id="delegatecontent">Generate report</button&g ...

Toggle the display of slider for multiple IDs with a show/hide feature

After browsing through a jQuery slider toggler tutorial on w3schools, I was inspired to create my own. However, I wanted a more flexible approach where I wouldn't have to rigidly define CSS styles and jQuery functions. Unlike the implementation on w3 ...

Achieve text fading effects with JavaScript for a dynamic user experience in an ASP.Net C# application

In my WebForm ASP.Net application, I have implemented a feature where I change the text on the web page. To draw user attention to this change, I want to fade out the old text completely, replace it with new text, and then fade in the new text. Currently, ...

Creating a text box that stands out by adjusting the length in Bootstrap

My webpage displays three text boxes, and I want to increase the size of one specific text box. Here is the code that I have tried: <div class="row"> <div class="col-md-3"> <mat-form-field (keydown.enter)="$event.preventDefa ...

Which specific element of CSS should be adjusted to ensure compatibility with Internet Explorer?

Struggling with my one-page website layout, I made some adjustments to have six sections in the HTML. Everything seemed to work fine on all browsers except for Internet Explorer. It kept redirecting me to a weird spot between the second last and last two s ...

Showing the SQL table data output

Attempting to present a new table based on the SQL query result. Below is the initial table code shown when the user first loads the page. TABLE: <form action="walkthroughs.php" method="POST"> Platform: <input type="text" name="platform" ...

Can you add descriptive text below a linked image?

I am currently working with a customized CMS created specifically for our company. My goal is to insert text below the image displayed. Ideally, I would like the text to be centered within the border of the image if possible. I have limitations in that I ...

Retrieve the chosen option within the current page

Currently, I am working with a select button on my webpage: <form method="post"> <label> <select id="label" name="challengeX" style="margin-top:150px;"> <option selected value="0"> Global Statistics </opt ...

A paragraph featuring the 'lead' class from Bootstrap 4, complete with a button nestled inside

Referencing the Jumbotron in Bootstrap 4 documentation, an example shows: <p class="lead"> <a class="btn btn-primary btn-lg" href="#" role="button">Learn more</a> </p> Why include a paragraph element here? And what is the purpos ...

Create a line break in an alert using PHP

<?php function alert($msg) { echo "<script type='text/javascript'>alert('$msg');</script>"; } if(array_key_exists('btnRegisterAdmins', $_POST)) { $fname = $_POST['FirstName']; $lname=$_POST['La ...

Incorporate a backdrop to enhance a material icon

I'm working with the following Material Icon code but I want to enhance it by adding a white background for better contrast. Any suggestions on how to achieve this? <a id="lnk_quick_print" href="javascript:;" title="Quick P ...

Updating Bootstrap variables

According to the documentation of Bootstrap, Sass variables in Bootstrap 4 come with the !default flag which allows you to override the variable's default value in your own Sass without modifying Bootstrap's source code. You can copy and paste va ...

Is it possible for me to input text into html while the page is loading?

Is there a way to preload external files while a web page is loading? I'm looking to incorporate a JavaScript templating engine into my website and prefer to store my templates in separate files. Instead of loading these templates asynchronously, I&ap ...

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 ...

Opera's compatibility with jQuery's Append method allows developers to

I recently wrote a jQuery script that interacts with a JSON feed and dynamically creates HTML code which is then added to a designated div on my WordPress site. Surprisingly, the functionality works flawlessly in all browsers except for Opera - where not ...