Applying Bootstrap Style to an Inline Select Element: A Step-by-Step Guide

Currently working on a page layout using Thymeleaf and Bootstrap 5. I have divided the page into two parts, with this section behaving as desired:

<main role="main" class="pb-3">
        <br>
        <p>Post office expenses</p>
        <div class="row">
            <div class="form-inline">
                <div class="form-group"> 
                    <span>Year:</span>
                    <select id="selectYear" th:field="*{years}" onchange="getDaysInMonth()">
                        <option th:each="y : ${years}" th:value="${y}" th:text="${y}"/>
                    </select>
                    <span>Month:</span>
                    <select id="selectMonth" th:field="*{monthsList}" onchange="getDaysInMonth()">
                        <option th:each="m : ${monthsList}" th:value="${m.id}" th:text="${m.monthName}"/>
                    </select  >
                    <span>Day:</span>
                    <select name="selectDay" id="selectDay">
                        <option th:each="n : ${#numbers.sequence(1,31)}" th:value="${n}" th:text="${n}"/>
                    </select >
                </div>       
            </div>
        </div>
        <div class="row pt-3">
            <div class="col-2">
                <form>
                    <div class="form-group">
                        <label for="typeOfMail">Type of mail:</label>
                        <select class="form-select form-select-sm" id="typeOfMail">
                            <option>Letter</option>
                            <option selected>Reserved</option >
                            <option>Package</option>
                            <option>Fast delivery</option>
                            <option>Returned mail</option>
                        </select >
                    </div>
                    <div class="form-group">
                        <label for="destination">Destination:</label>
                        <select class="form-select form-select-sm" id="destination">
                            <option>Domestic</option>
                            <option>Foreign</option>
                        </select >
                    </div>
                </form >
            </div>
            <div class="col-9 text-center">
                <h2>Picture</h2>
            </div>
        </div>
    </main>
</div>

I'm struggling to style the Year, Month, and Day dropdowns like the ones displayed below. I've attempted using form-select classes but they extend to the end of the row.

Any suggestions on how to better style this are welcomed. Thank you in advance.

Answer №1

Check out the examples provided in the documentation:

<p>Tracking post office expenses</p>
<div class="row g-3 align-items-center">
    <label for="selectYear" class="col-auto"gt;Year:</label>
    <div class="col-auto">
        <select id="selectYear" class="form-select" th:field="*{years}" onchange="getDaysInMonth()">
            <option th:each="y : ${years}" th:value="${y}" th:text="${y}"/>
        </select>
    </div>
    <label for="selectMonth" class="col-auto">Month:</label>
    <div class="col-auto">
        <select id="selectMonth" class="form-select" th:field="*{monthsList}" onchange="getDaysInMonth()">
            <option th:each="m : ${monthsList}" th:value="${m.id}" th:text="${m.monthName}"/>
        </select>
    </div>
    <label for="selectDay" class="col-auto">Day:</label>
    <div class="col-auto">
        <select name="selectDay" id="selectDay" class="form-select">
            <option th:each="n : ${#numbers.sequence(1,31)}" th:value="${n}" th:text="${n}"/>
        </select>
    </div>       
</div>

View Demo here

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

Using Slick.JS to Sync Navigation with Main Slider, Automatically Resetting to First Slide

I have a question about the functionality of the Slick.JS plugin that I'm using. In my project, I have two carousels with five slides each. The top carousel displays one slide at a time, while the bottom carousel shows all five slides concurrently. My ...

Retrieving selected options from a jQuery mobile multiselect for database storage

I'm currently working on extracting values from a select list in a jQuery mobile application. Here's the markup for my select element: <div data-role="fieldcontain"> <label for="stuff" class="select">Stuff:</label ...

Enhancing webpage design by dynamically changing borders and headers using JavaScript

I have implemented a fixed positioning for the table headers using the following code: onScroll={() => { document.querySelector('thead').style.transform = `translate(0,${this.scrollRef.scrollTop}px)`; }} However, when I scroll the ta ...

Utilize AJAX in JavaScript file

I am encountering an issue with the following code: function inicioConsultar(){ $(function(){ $('#serviciosU').change(function(){ if ($('#serviciosU').val()!= "-1") { $.ajax({ url: "@Url. ...

How can Node.js and Express be used to conceal Javascript code on the backend?

I'm a beginner when it comes to Node and Express. I have a query regarding how to securely hide Javascript code on the backend. Currently, I am working with Node.js and Express. My goal is to prevent users from easily accessing the code through browse ...

"Discover the step-by-step process of transforming an input field value into a checkbox with

I've been experimenting with creating a To-Do list using HTML, CSS, and Javascript. I've managed to capture the input field value in a fieldset so far. However, my goal is to find a way to transform the input field value from the textfield into a ...

What is the method for presenting text based on the chosen Select Option?

I attempted to achieve this using hrefs and ids, but it did not meet my requirements. This is the desired format: div.selectcountry { margin-bottom: 10px; font-family: arial; font-size: 12px; } div.countrydepartment { font-family: ...

Continuous scroll notification within the fixed menu until reaching the bottom

I'm looking to achieve a scrolling notification message that stays fixed at the bottom of a top-fixed menu while the body content continues to scroll normally. Here's an example in this fiddle: HTML: <div class="menu-fixed">I am a fixed me ...

Is the initial carousel element failing to set height to 100% upon loading?

If you take a look here, upon loading the page you will notice a DIV at the top. It is labeled "content" with "content_container" wrapped around it and finally, "page" around that. Clicking the bottom left or right arrows reveals other DIVs with similar ta ...

Error alert: $.simpleWeather function not found

Currently, I am attempting to incorporate simpleWeather.js from the website simpleweatherjs.com into my own website. However, upon inserting the html code onto my website, an error message pops up: Uncaught TypeError: $.simpleWeather is not a function ...

My divs are multiplying twice as fast with every iteration of the Javascript For Loop

Recently, I developed a script that generates a series of fields based on a number provided by the user (k). Initially, I had a script that would create the correct number of fields. However, I decided to arrange them like vectors on the screen, so I made ...

Eliminate the CSS triggered by a mouse click

Having some difficulty toggling the switch to change the background color. Struggling with removing the applied CSS and getting it to toggle between two different colored backgrounds. Code Sample: <!Doctype html> <html lang="en"> <head> ...

Running Protractor tests can be frustratingly sluggish and frequently result in timeouts

After spending most of the afternoon struggling with this test, I've tried different approaches but none seem to work. The task at hand is searching for users within the company, generating a table, and selecting the user that matches the name. Curren ...

Switching effortlessly between Fixed and Relative positioning

As I work on creating a unique scrolling experience, I aim to have elements stop at specific points and animate before returning to normal scroll behavior once the user reaches the final point of the page. Essentially, when div X reaches the middle of the ...

Javascript issue: opening mail client causes page to lose focus

Looking for a solution! I'm dealing with an iPad app that runs html5 pages... one specific page requires an email to be sent which triggers the Mail program using this code var mailLink = 'mailto:' + recipientEmail +'?subject=PDFs ...

"Efficiently fetch data with an Express GET request without the

My goal is to send the client the HTML page (create.html) in response to a GET request triggered by a button click using fetch. I am intentionally avoiding the use of a form due to formatting and potential scalability issues. The code acknowledges that the ...

Can we dynamically add an identical DOM structure by clicking a button using jQuery?

I currently have ten text fields within a single div. I am interested in including another set of ten text fields with the same name, class, and id. Is there a way to recycle the existing DOM structure mentioned above, or will I need to generate and add t ...

Tips for updating the content of a div with the click of another div

Is there a way to dynamically change the content of a div upon clicking on a menu item? Here is the current layout for reference: https://i.stack.imgur.com/nOnlQ.png Below is the CSS and HTML code snippet: body { background-color: #555657; ...

Is it possible to incorporate a next.js image onto the background design?

I've encountered an issue while attempting to create a fixed background image with a parallax effect using Tailwind CSS and Next.js Image. If you need to see an example of this in action, check out this Template Monster theme. Here's the code s ...

Refresh a function following modifications to an array (such as exchanging values)

Looking to re-render a function after swapping array values, but the useEffect hook is not triggering it. I need assistance with this as I plan to integrate this code into my main project. Below are the JSX and CSS files attached. In App.js, I am creating ...