Arrange the text box, label, and buttons within a division to be aligned

I am attempting to achieve a layout similar to this:

However, what I am getting looks like this:,

I am struggling to figure out how to make changes to my HTML. I want to position the buttons in the correct places and align the dropdown with the other textboxes.

The stylesheet I have written is as follows:
<style type="text/css">
        div.label-wrapper {
            position: relative;
            min-width: 300px;
            max-width: 400px;
            height: 24px;
            display: block;
        }

            div.label-wrapper > label {
                position: absolute;
                left: 0;
                width: 100px;
                text-align: left; /* not absolutely necessary, but will be if you assign a width to the label */
                white-space: nowrap; /* Again, not totally necessary, but if you run out of space otherwise you'll get multiple lines for your label */
            }

            div.label-wrapper > input[type=text] {
                position: absolute;
                left: 115px; /* Leaves a 15px gap between end of label and start of textbox.  Increase value if you want more than 15px or decrease if you want less */
            }
            div.label-wrapper > input[type=submit] {
                position: absolute;
                left: 115px; /* Leaves a 15px gap between end of label and start of textbox.  Increase value if you want more than 15px or decrease if you want less */
            }
    </style>

And here is the HTML:

<div>
                        <div class='label-wrapper'>
                            <asp:Label ID="Label1" runat="server" Text="Staff ID :"></asp:Label>
                            <asp:TextBox ID="staffID" runat="server" Width="150px"></asp:TextBox>
                        </div>
                        <div class='label-wrapper'>
                                    <asp:Label ID="Label2" runat="server" Text="Name :"></asp:Label>
                                    <asp:TextBox ID="staffname" runat="server" Width="300px"></asp:TextBox>
                        </div>
                        <div class='label-wrapper'>
                                    <asp:Label ID="Label3" runat="server" Text="Surname :"></asp:Label>
                                    <asp:TextBox ID="StaffSurname" runat="server" Width="300px"></asp:TextBox>
                        </div>
                        <div class='label-wrapper'>
                                    <asp:Label ID="Label5" runat="server" Text="Email Address :"></asp:Label>
                                    <asp:TextBox ID="email" runat="server" Width="423px"></asp:TextBox>
                        </div>
                        <div class='label-wrapper'>
                                    <asp:Label ID="Label4" runat="server" Text="Research Areas of Expertise :"></asp:Label>
                                    <asp:CheckBoxList ID="ResearchAreasList" runat="server" RepeatLayout="Flow" Width="230px">
                                        <asp:ListItem>Information Systems</asp:ListItem>
                                        <asp:ListItem>User Interfaces</asp:ListItem>
                                        <asp:ListItem>Problem Solving</asp:ListItem>
                                        <asp:ListItem>3D Graphics</asp:ListItem>
                                        <asp:ListItem>Computing Education</asp:ListItem>
                                        <asp:ListItem>Mobile Computing</asp:ListItem>
                                    </asp:CheckBoxList>
                        </div>
                        <div class='label-wrapper'>
                            <p>
                                    <span class="art-button-wrapper">
                                            <span class="art-button-l"></span>
                                            <span class="art-button-r"></span>
                                            <asp:Button ID="Button1" runat="server" CssClass="art-button" Text="Save" OnClick="Button1_Click" />
                                        </span>
                                </p>
                            <p>
                                    <span class="art-button-wrapper">
                                            <span class="art-button-l"></span>
                                            <span class="art-button-r"></span>
                                            <asp:Button ID="Button2" runat="server" CssClass="art-button" Text="Cancel" />
                                        </span>
                                </p>
                        </div>
                    </div> 

Answer №1

If you want to make this work, you'll need to incorporate the float:left option in your stylesheet. Take a look at this code snippet:

#labelWrapper {
    float:left;
    width:480px;
    padding:10px;
    background:#9c9;
}

#textBoxWrapper{
    float:right;
    width:230px;
    padding:10px;
    background:#99c;
}

To see a complete example of how to create a two-column website, check out this link: here

Answer №2

Consider updating your CSS with the following adjustments. It's advisable to avoid using absolute positioning whenever possible.

    div.label-wrapper {
        min-width: 350px;
        max-width: 450px;
        height: 30px;
        float:right;
    }

        div.label-wrapper > label {
            width: 120px;
            text-align: center; /* while not mandatory, this will be useful if you specify a width for the label */
            white-space: nowrap; /* again, not strictly necessary, but helps avoid wrapping */
        }

        div.label-wrapper > input[type=text] {
            left: 135px; /* creates a 15px space between the end of the label and the start of the textbox - adjust as needed */
        }
        div.label-wrapper > input[type=submit] {
            left: 135px; /* maintains a 15px gap between the label and submit button - modify if desired */
        }

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

Steps on modifying the background of an element based on its location within the browser:

In the past, I've come across some impressive one-page websites with elements that would appear as you scroll. It seemed like they were created using just CSS. I think it might be achievable with the z-index and position properties? However, I can&ap ...

Which is more effective - utilizing AJAX calls or UpdatePanel to update a panel?

I am working on an application where I need to update a panel's content after a button click triggers some server-side processing. I want to avoid a full page postback. I have two options to achieve this: making an AJAX call or using an update panel. ...

Applying FAB (Material UI) to span across 2 columns in a CSS Grid: A step-by-step guide

Is there a way to make the zero button larger than the other buttons in its row by spanning 2 columns? I would like it to be an oversized oval shape. Appreciate any assistance you can provide. import "./styles.css"; import Button from '@mui/materia ...

Error loading Azure Active Directory web form: Server returned a 401 status code for the requested resource

I recently made changes to my web site (incorporating a web form and entity framework) to use AAD connection, following the guidance in this insightful blog post. However, I am encountering an issue where scripts and css files are not loading properly. Th ...

Alter BitmapImage already stored in memory

On my WinRT XAML page, I successfully load an image from a file asset using the following code: Image img = new Image(); // Windows.UI.Xaml.Controls.Image BitmapImage bmp = new BitmapImage(new Uri(Page.BaseUri, "Assets/myImage.png")); img.Source = bmp; ...

Determining the Version of EdgeDriver in Selenium using C#

Having some trouble with updating my "chromedriver.exe" and "msedgedriver.exe" automatically when I start my program. While I can successfully download both exes with their correct versions, accessing the versions from my code proves to be a challenge, esp ...

Calculate the cumulative values in ng-repeat using AngularJS

I used ng-repeat to iterate through a JSON array. I calculated the number of nights by utilizing the dayDiff() function. Now, I need to find the total number of nights for all invoices. My project is built with AngularJS. Is there a way to retrieve the to ...

Ways to prevent a loop from constantly restarting

After clicking the generate ID button once, it will become disabled and display a set of numbers. The last 4 digits are in a loop sequence starting with "0001". If I were to re-enable the generate ID button and click it again, the last 4 digits would incre ...

"Timezone" jQuery Plugin for Easy Timeago Conversion

Currently, I am working on an asp.net application where I have implemented the timeago jQuery plugin. However, I am encountering an issue where the time displayed is in UTC despite my local time being GMT +5.00 and the server time also being in UTC. My ma ...

Menu overlay conceals company logo

On smaller screen sizes, my hamburger menu is blocking part of the logo. I'm struggling to figure out how to ensure that the logo appears in front of the menu before it is clicked. Here's an example. I attempted setting the background of label . ...

Vertical text on rigid bars

Hey there, I've encountered an intriguing problem that's got me stumped. I'm attempting to create a menu made up of vertical bars that span the full height of the window and have a fixed position. I want the text within these bars to displa ...

Dynamic addition of HTML is not possible in AngularJS

I've encountered a challenging issue that I'm struggling to resolve. Despite my best efforts, I can't seem to find a suitable solution to achieve the desired outcome. Let me provide some context to explain my problem: I need to dynamically ...

Overlapping divs are observed when utilizing absolute positioning in CSS

I am facing a challenge with placing the div identified by our_team below the div with the ID of services. When I use absolute positioning, the former ends up overlapping the latter. The services div transitions to display information when hovered over du ...

The <h:outputStylesheet> tag fails to display any content on the HTML page

I am having trouble getting my CSS sheet to load while using JSF2 and PrimeFaces. The CSS file is located at WebContent/resources/css/style.css Here is the xhtml code: <h:head></h:head> <h:body> <h:outputStylesheet name="css/styles. ...

The C# task has been terminated

Every now and then, I encounter the error message "Task was canceled" and I'm struggling to pinpoint the root cause of this issue. Unfortunately, the error message doesn't provide much information to work with. Despite my efforts to research on v ...

Using jQuery to disable a checkbox when its value matches any elements within an array

I am attempting to programmatically disable checkboxes upon page load based on certain conditions, specifically when the checkbox values correspond to records in my database. After researching solutions such as this one and here, I noticed that the main d ...

The reason I am unable to extract information from the elements within the <ul> tag

I am currently attempting to extract reviews data from booking.com that is contained within the <ul> tag with the class attribute set to "review_list". There are a total of 10 reviews, each of which is inside an <li> element with the class attr ...

Tips for correctly loading all elements on an HTML page before making CSS modifications

This question has been asked several times in the past. I am asking because when I used the on ready callback in jQuery, it did not change the placeholder text of my element "search_input". $( document ).ready(function() { $("#search_input").attr(' ...

The issue of Bootstrap form validation not functioning properly within a table containing a large checkbox

Currently utilizing Bootstrap version 5.3.3, I have the following structure established to create a large checkbox: .form-check-input[type=checkbox].big-checkbox { transform: scale(3); margin: 1.5rem; border-radius: 0; ...

Check the radio box corresponding to the adjacent label

As a hobby, I have been exploring ways to automate questionnaires that I used to manually deal with for years. It has always intrigued me how best to streamline this process, and now I am taking the opportunity to indulge in my passion and enhance my JavaS ...