Customizing Forms with Bootstrap Styling in HTML

Is there a way to rearrange this list so that the buttons appear above the textboxes, like in the

desired formatting example

The code is as follows:

 <form id="Data" runat="server" class="p-3 mb-2 bg-primary text-dark">
     <div class="form-group col">
        <label for="Countries" class="control-label">Email address</label>
            <asp:DropDownList name="Countries" ID="Countries" runat="server" AppendDataBoundItems="true" OnSelectedIndexChanged="Countries_Selected">
            <asp:ListItem Text="<Select country>" Value="0" />
            </asp:DropDownList>
     </div>
     <div class="form-group col">
        <label for="DateIn" class="control-label">Pick-up date</label>
            <asp:Textbox runat="server" TextMode="Date" name="DateIn" ID="DateIn" Text="Select Return Date">
            </asp:Textbox>
     </div>

     <div class="form-group col">
        <label for="DateOut" class="control-label">Drop-off date</label>
            <asp:Textbox runat="server" TextMode="Date" name="DateOut" ID="DateOut" Text="Select Pick-up Date">
            </asp:Textbox>
     </div>

     <div class="form-group col">
        <label for="smth" class="control-label">Email address</label>
            <asp:DropDownList name="smth" ID="smth" runat="server" AppendDataBoundItems="true" OnSelectedIndexChanged="Countries_Selected">
                <asp:ListItem Text="<Select country>" Value="0" />
            </asp:DropDownList>
     </div>

    </form>

At present, my page displays in this manner:

Current layout

Answer №1

Utilize two rows, one with two col-6 and one with two col-3. A single inline css style has been applied in this example, but it may not be necessary if the form is within another element of the same size. Adjust the width according to your design needs.

    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet" />
    <form class="bg-success p-4 text-white mx-auto" style="width:500px">
      <div class="row">
        <div class="col-6 d-flex flex-column">
          <label for="DateIn">Return Date and Time</label>
          <input class="form-control" />
        </div>
        <div class="col-6 d-flex flex-column">
          <label for="Countries"> Categories:</label>
          <select class="form-control">
            <option value="">one</option>
            <option value="">two</option>
            <option value="">three</option>
          </select>
        </div>
      </div>
      <div class="row mt-4">
        <div class="col-3">
          <select class="form-control">
            <option value="">one</option>
            <option value="">two</option>
            <option value="">three</option>
          </select>
        </div>
        <div class="col-3">
          <select class="form-control">
            <option value="">one</option>
            <option value="">two</option>
            <option value="">three</option>
          </select>
        </div>
      </div>
    </form>

Update

Follow these steps:

  1. Make the form a row
  2. Use col-6 for the first two columns
  3. Apply col break to move the last two columns to a new line
  4. Assign col-3 for the last two columns

<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet" />
<form class="row bg-success p-4 text-white mx-auto" style="width: 500px;">
  <div class="col-6 d-flex flex-column">
    <label for="DateIn">Return Date and Time</label>
    <input class="form-control radius-0">
  </div>
  <div class="col-6 d-flex flex-column">
    <label for="Countries"> Categories:</label>
    <select class="form-control radius-0">
      <option value="">one</option>
      <option value="">two</option>
      <option value="">three</option>
    </select>
  </div>
  <!-- Force next columns to break to new line at md breakpoint and up -->
  <div class="w-100 d-none d-md-block my-3"></div>
  <div class="col-3">
    <select class="form-control radius-0">
      <option value="">one</option>
      <option value="">two</option>
      <option value="">three</option>
    </select>
  </div>
  <div class="col-3">
    <select class="form-control radius-0">
      <option value="">one</option>
      <option value="">two</option>
      <option value="">three</option>
    </select>
  </div>
</form>

Check this CodePen

The form elements in this example have rounded corners compared to the image shown. If you are working with SCSS, adjust the radius accordingly. Otherwise, modify it using CSS.

Answer №2

To achieve the desired layout, you can utilize the display: flex property. Additionally, some adjustments will be necessary to ensure that the styling of the inputs align with your design.

I've created two utility classes named columns and col.

The columns class serves as a container div with display: flex applied. On the other hand, the col class represents each column within the container and has flex: 1 defined, ensuring equal spacing within the container.

form {
  width: 400px;
  background: #278339;
  color: #FFF;
  padding: 20px;
}

input,
select {
  width: 100%;
  margin-bottom: 10px;
}

.columns {
  display: flex;
}

.col {
  flex: 1;
  margin-right: 15px;
}
<form id="Data" runat="server" class="p-3 mb-2 bg-primary text-dark">

  <div class="columns">

    <div class="col">

      <div class="form-group col-xs-4 col-md-4">
        <label for="DateIn" class="control-label">Return Date and Time</label>
        <input runat="server" TextMode="Date" name="DateIn" ID="DateIn" Text="Select Return Date">
        </input>
      </div>

      <div class="columns">

        <div class="col">
          <div class="form-group col-xs-4 col-md-4">
            <select name="Countries" ID="Countries" runat="server" AppendDataBoundItems="true" OnSelectedIndexChanged="Countries_Selected">
              <option Text="<Select country>" Value="0" />
            </select>
          </div>
        </div>

        <div class="col">

          <div class="form-group col-xs-4 col-md-4">
            <select name="Countries" ID="Countries" runat="server" AppendDataBoundItems="true" OnSelectedIndexChanged="Countries_Selected">
              <option Text="<Select country>" Value="0" />
            </select>
          </div>
        </div>
      </div>

    </div>


    <div class="col">
      <div class="form-group col-xs-4 col-md-4">
        <label for="Categories" class="control-label">Categories:</label>
        <select name="Categories" ID="Categories" runat="server" AppendDataBoundItems="true" OnSelectedIndexChanged="Categories_Selected">
          <option Text="<Select category>" Value="0" />
        </select>
      </div>
    </div>

  </div>


</form>

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

Adjust the transparency of the image when hovered over, but keep the text in the center

How can I change the opacity of an image on hover and simultaneously display text in the center of the image? This is my code: <div class="col-md-4 j-t"> <div class="middle"> <div class="text-middle">Play</div> < ...

Populate List Items until Maximum Capacity is Reached and Increase the

Is there a way to make a ListItem fill the list vertically while also being able to overflow it if needed? I'm looking for a solution that would allow me to access the height of the empty space in the list, which I believe would be the minHeight. Som ...

Is it possible to utilize an integrated web browser (like Chrome) as the graphical user interface toolkit for Java desktop applications?

Wow, those HTML5 websites really stand out - but why is it that my Java desktop apps just don't have the same visual appeal? Swing and SWT seem outdated in comparison. They get the job done, but creating modern GUIs with animations and other flashy fe ...

Conceal a row in a table after successfully executing a delete query using Ajax

Currently, I am facing an issue with hiding rows within a while loop. My goal is to hide an entire row once the delete query has been successful. The deletion query itself is functioning correctly, but I require assistance in properly hiding the row. Any h ...

Disabling the linkbutton within a grid view depending on the specific row value

I have a grid view in the following code with 6 columns: DocumentID, Documentname, View, Edit, ViewButton, EditButton. My goal is to disable the ViewButton if View is false and disable the EditButton if Edit is false. However, when I tried to implement t ...

Start the static class and ensure it runs continuously without restarting

In my Asp.Net Core 3.1 Razor Pages website, I have a static Repository class that holds frequently used items. It takes approximately 4 minutes to initialize these items due to frequent searching. public static class Repository { public static Diction ...

Equal size images displayed within cards in Material UI

Is there a way to create a list of Material UI components with images that have uniform height, even if the original images vary in size? I want to make all image heights responsive and consistent across all cards. Any suggestions on how to achieve this? ...

A secondary operation is triggered in the simulated keyboard when the enter or space key is pressed, even when it is not warranted

In my HTML, I have created a simulated keyboard with buttons that correspond to characters. When you click on these buttons, the character is added to a text element on the screen. Additionally, you can use your physical keyboard to input characters in the ...

Error: You can't call .text as a function in jQuery

While trying to retrieve the text from my td, I encountered the following error: $tds[2].text is not a function. The output of console.log('td',$tds[2]) shows: https://i.stack.imgur.com/OUngP.png $(document).ready(function() { $trs = $(&ap ...

What are some techniques for applying CSS styling directly to a custom element?

Check out this amazing resource from HTML5 Rocks about the process of creating custom elements and styling them. To create a custom element, you can use the following code: var XFoo = document.registerElement('x-foo', { prototype: Object.crea ...

Update the appearance of an element in real-time using VUEJS

I am trying to use VueJS to dynamically change the position of a div. In the data function, I have a variable called x that I want to assign to the top property. However, the code I wrote doesn't seem to be working. Here is what it looks like: <tem ...

Discovering the failing dependency that isn't loading

I encountered an error while attempting to run a web application: Exception information: Exception type: ConfigurationErrorsException Exception message: Could not load file or assembly 'Atalasoft.dotImage.AdvancedDocClean.DLL' or one o ...

Obtain HTML element properties from a webpage using the Selenium tool in Python

The task at hand is to extract the pink email information from the webpage, while ensuring the confidentiality of the black/blue data. The process will be carried out using Python 3.6. ...

I'm attempting to resize my images to fit within the container, but instead they appear enlarged

I'm struggling to get my images to resize based on the container size, especially when viewed on tablets or phones. The current result is that the images are too zoomed in and I can't figure out what's causing this issue. ...

Discover the process of retrieving an element by its ID when dealing with dynamically generated IDs in AngularJS

I am creating a list using the following code snippet: <div ng-repeat="list in fileUploadList"> <div id="{{list}}Upload"></div> </div> Within the controller, I need to retrieve the element by ID, so I am utilizing this line of ...

Switching between two states of a single 'td' element within a column

I am trying to implement a feature where only specific elements in the fourth column of a four-column table toggle when clicked. For example, clicking on an element in the fifth row third column should toggle the corresponding element in the fifth row four ...

Arrangement priority and fixed location

Here is the issue I'm facing: f http://d.pr/i/Kge6+ I have three images positioned absolutely within a box that is fixed in position. I want the images to not overlay on top of each other, but despite trying various solutions (changing z-index, remo ...

Tips for maintaining a consistent style across multiple websites

There is a website with a master-page, set of css-files, and menus. A new website needs to be created with the same or a similar look-and-feel. Keeping the look-and-feel in sync is essential. I have searched the internet for a solution or idea, but have n ...

There are two design issues that need to be addressed: a white background glitch and a layout problem specifically in

I'm facing two issues with my website located at Issue 1 : In Internet Explorer 9, the header displays correctly but the text area is not in the right position. Issue 2: There is a white area around the header that should show the background instead ...

Tips for using jQuery dropdown menus

I am currently in the process of creating a prototype for a quick dropdown menu using jQuery. However, I have reached the limits of my knowledge on jQuery and could use some assistance in solving my issue. My objective is to have a dropdown animate down w ...