Achieving alignment of the label with the top of the div

I'd like to align a label with a div vertically, but I'm having trouble. Take a look at the picture below to see what's happening. The corrections in blue show what I want it to look like. I've included the relevant HTML and CSS below, stripped down to focus on the issue.

Any ideas on how to move that label to the top of the type options? Thanks!

Answer №1

This can be modified:

div.MainContent div.BasicInformationField label {
        text-align: center;
    }

To the following:

div.MainContent div.BasicInformationField label {
        text-align: left;
    }

Answer №2

After experimenting with floating elements left, adjusting margins, and clearing labels, I finally got everything to align properly. Thank you for the helpful conversation and resources.

Check out my solution on jsfiddle.net

<!DOCTYPE html>
<html>
    <head>
        <title>Title</title>
        <style type="text/css">
        /* CSS styles reset and application-specific styles */
        
        /* Reset CSS properties */
        
        html,
        body,
        div,
        span {
            margin: 0;
            padding: 0;
            border: 0;
            font-size: 100%;
            font: inherit;
            vertical-align: baseline;
        }
        
        /* Display roles for HTML5 elements */
        
        article,
        aside,
        details {
            display: block;
        }
        
        /* Application-specific CSS */
        
        body {
            line-height: 1;
            color: #383838;
            font-family: arial, helvetica, verdana, sans-serif;
            font-size: 0.8em;
            background-color: transparent;
            margin: 0 auto;
            min-height: 100%;
            background-color: White;
            color: Black;
        }
        
        input,
        textarea,
        select {
            font-family: inherit;
            font-size: inherit;
        }
        
        div#EverythingDiv {
            width: 960px;
            margin-left: auto;
            margin-right: auto;
            background: #FFF;
        }
        
        div.MainContent {
            margin: 0px auto 0px auto;
            padding: 0;
            min-height: 425px;
            text-align: left;
            clear: both;
        }
        
        fieldset > label {
            float: left;
            display: block;
            width: 150px;
            clear: both;
            margin-top: 5px;
        }
        
        fieldset > input[type=text] {
            float: left;
            margin-top: 1px;
        }
        
        fieldset > textarea {
            float: left;
        }
        
        fieldset > div.Group {
            float: left;
            width: 300px;
            padding-top: 5px;
        }
        
        fieldset > div.Group input[type=radio] {
            margin-top: -3px;
            vertical-align: middle;
        }
        
        fieldset > div.Group > label {
            display: block;
            margin-bottom: 3px;
            line-height: 1.2em;
        }
        </style>
    </head>
    <body>
        <div id="EverythingDiv">
            <h1 id="PageTitleH1">Title</h1>

            <div class="MainContent">
                <form action="MyPage" method="post">
                    <div class="validation-summary-valid" data-valmsg-summary="true"><ul><li style="display:none"></li>
                    </ul></div>

                    <fieldset>
                        <legend>Basic Information</legend>
                        <label for="WebSiteTextBox">Web Site:</label>
                        <input type="text" id="WebSiteTextBox" value="http://www.google.com/" />
                        <label for="AddressTextArea">Address:</label>
                        <textarea id="AddressTextArea" style="float: left; width: 350px; height: 4.4em;">Sample Address</textarea>
                        <label>Type</label>
                        <div class="Group">
                            <label class="RadioLabel"><input type="radio" name="Type"/>Type 1 - Lorem ipsum dolor sit amet, consectetur adipiscing elit.</label>
                            <label class="RadioLabel"><input type="radio" name="Type"/>Type 2 - Curabitur non odio hendrerit, hendrerit ante quis, rhoncus neque. Nam ac nisi non lorem accumsan dictum. </label>
                            <label class="RadioLabel"><input type="radio" name="Type"/>Type 3 - Morbi volutpat at eros ut dictum. Nam non arcu ornare, sodales eros nec, semper ante. Nunc tempor augue a est eleifend suscipit. Nam vel ornare leo.</label>
                            <label class="RadioLabel"><input type="radio" name="Type"/>Type 4 - Nam vel ornare leo.</label>
                        </div>
                    </fieldset>
                </form>
                
                <div class="Clear"></div>
            </div>
        </div>
    </body>
</html>

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

Is it recommended to apply the ARIA directory role to a breadcrumb navigation list?

Currently, I am working on enhancing the accessibility of a breadcrumbs component that is structured around a <ul> element. In my quest for solutions, I came across the concept of ARIA roles and specifically the directory role. While it seems like a ...

Is it possible to modify a scss style in Prestashop?

I have encountered an issue while using a default theme in Prestashop 1.6 that I need assistance with. My goal is to move the navbar up by 25px. I understand that I should make changes to #block_top_menu { padding-top: 25px; } in blocktopmenu.scss, which ...

Alignment issues in Bootstrap Navbar causing them not to line up properly with each other

Hey there! I'm currently facing an issue with my Bootstrap navbar as the items inside are not lining up properly with the first item. If you take a look at this screenshot here, you can see that the items on the right aren't aligned correctly wi ...

Is it possible to trigger an ng-click event while the md-backdrop is present in Angular Material?

In my Angular Material website, a context menu pops up with an md-backdrop whenever the md-menu is shown. Clicking outside the md-menu closes it by triggering the md-backdrop click event. However, I would like to capture that ng-click event. For instance, ...

Designing Interactive Circular Dates on Website

Currently, I am working on a webpage using HTML, CSS, JavaScript, and PHP. The goal is to design a page that features 7 circles representing the current date and the next 6 days. Users should be able to click an arrow to navigate to the following 7 days. ...

URL displays the bootstrap carousel slider item's ID

The URL displays the ID of each slide on the bootstrap carousel slider, as shown in the images below: https://i.sstatic.net/TWcx2.png https://i.sstatic.net/xaJxm.png When changing sliders, the URL reflects the ID of each slide. After upgrading to a newe ...

Modify the CSS styles of inner elements dynamically

Within my code, I have implemented a SplitPane and included a CSS file that contains the following styling rules: .split-pane > .split-pane-divider { -fx-padding: 0 0 0 1; -fx-background-color:-fx-background; } However, during runtime, I e ...

Tips for updating JS and CSS links for static site deployment

As I develop my static site using HTML files served from a simple web server, I want to use local, non-minified versions of Javascript code and CSS files. However, when it comes time to deploy the site, I would like to refer to minified versions of these s ...

Issue with setting a custom background image for the object header in WordPress from HTML conversion

I am in the process of converting an HTML template into WordPress to make it easier for users to edit. I have tried adding front page header slider images and content into a customizer object so that users can easily customize their site. Users can go to A ...

Insert an icon directly into a text input box

I'm attempting to insert an icon into a text input field. For example: One approach is to utilize background-image and then apply padding-left. However, I am interested in using CSS sprites. I have experimented with the following code: <!DOCTY ...

Problems revolving around the fundamental CSS drop-down menu concept

I'm struggling to center a CSS drop-down menu on my webpage without causing the drop-down effect to break. No matter what I try, it seems to mess up. What am I missing? Snippet of code: html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,b ...

Place the select option within the input field

input { width: 100%; } .input-currency:after { position: absolute; right: 0; top: 10px; content: 'USD'; border-left: 1px solid black; padding: 0 7px; padding-right: 4em; } <div class="input-currency"> <input id="value" ...

What could be the reason behind my code functioning properly on CodePen but not in my editor?

I'm currently using Sublime 3 for coding in HTML and CSS. After saving the files with the proper extensions, I included the Google Fonts to use the "Lobster" font. However, upon opening the .html file on Google Chrome, the Lobster font doesn't d ...

How to make a sticky sidebar using JavaScript or jQuery

Hello everyone! I am just starting out in front end web development, so please bear with me if my question seems basic. I am trying to figure out how to create a sticky sidebar that only appears when the parent div is in view, and disappears when it' ...

Animate failed due to the appending and adding of class

$('#clickMe').click(function() { $('#ticketsDemosss').append($('<li>').text('my li goes here')).addClass('fadeIn'); }); <link href="http://s.mlcdn.co/animate.css" rel="stylesheet"/> <script ...

Adaptable Design for Smartphones

Currently in the process of creating a website for my brother with Joomla 3.4 and Bootstrap. This marks my first venture into building a responsive site, so I'm seeking guidance on essential elements to include in my CSS such as font sizes in specific ...

I am looking to bring in just the tables from a different html/php page

I am currently working on a webpage that includes a php library, header, and other elements. I only need to import specific tables and information from this page onto another screen display, with the tables arranged side by side instead of vertically. My ...

The "Sticky" directive in AngularJS causes an issue where it extends beyond the width of the parent

Utilizing the Angular JS sticky directive, I am attempting to affix the header of a table to the top of the page during scrolling. The table resides within a bootstrap container with a fixed width. However, when the Angular script kicks in, the entire head ...

Guide to populating a select-option dropdown using CSS

I'm working on creating a dropdown menu in HTML that pulls the options from a CSS file. To accomplish this, I have assigned custom classes to each option and specified the option label in the CSS using the CUSTOM_CLASS::after{content: "";} r ...

Displaying an element to appear over all client applications when hovering

Currently, I have an application that highlights specific areas when hovered over or clicked. While it functions properly, I would like the hover and click effects to be visible on every client, each with an identical overlay setup. I realize my method may ...