beginning the process of aligning the select element with the label in a form

.surveyform-class {
background: yellow;
    margin: 0 25%;
    width: 50%;
    border-right: 40px solid yellow;
}
.main-div{
background: lightgrey;
    width: 50%;
height:100%;
    margin: 0 25%;
    border-right: 20px solid yellow;
    border-left: 20px solid yellow;
}
form {
  /* Center the form on the page */
  margin: 0 auto;
  width: 400px;
}
form >div {
  margin-top: 1em;
}
form >div >div {
 padding-left: 95px;
}
label{ 
   width: 90px;
  text-align: right;
  display: inline-block;
 
}
<DOCTYPE! html>
<html> 
  <head>
    <title>Survey Form</title>
<link href="surveyform.css" type="text/css" rel="stylesheet">
  </head>
  
<body>
<div style="    
    text-align: center;">

<h1 class="surveyform-class">Survey Form</h1>
<div class="main-div">
 lwt us know how we can improve freecode camp
<form  >
  <div>
    <label for="name">Name:</label>
    <input type="text" id="name" name="user_name">
  </div>
  <div>
    <label for="mail">E-mail:</label>
    <input type="email" id="mail" name="user_mail">
  </div>
  <div>
    <label for="msg">Message:</label>
    <textarea id="msg" name="user_message"></textarea>
  </div>
  <div >
<label>
which option best describes your current role 
</label>

<select > 
<option>student</option>
<option>engineer</option>
</select>
</div>
<div >
<label>
Things that should be improved in future
</label>


<input type="checkbox" name="a">
<span> Front end projects</span>

<div>

<input type="checkbox" name="a">
<span> Backend Projects</span>
</div>
<div>


<input type="checkbox" name="a">

<span> Structure </span>

</div>
</div>
</form>
</div>
</div>
  </body>
</html>

I am searching for assistance in aligning the select element and labels to start on the same line.

Could you please provide some guidance? Thank you!

For reference, here is the link to the JSFiddle: http://jsfiddle.net/v650o2dL/2/

Answer №1

To align items vertically at the top using CSS, you can utilize the property vertical-align:top. Make sure to separate the left and right containers like the example provided below;

.yellow {
  background: yellow;
  padding-left: 40px;
  padding-right: 40px;
  padding-bottom: 40px;
}

.yellow>h1 {
  text-align: center;
}

.grey {
  background: lightgrey;
  height: 200px;
}

.row {
  width: 100%;
  display: block;
  margin-bottom: 10px;
}

.left,
.right {
  width: 49%;
  display: inline-block;
  vertical-align: top;
}

.input-group {
  display: block;
  margin-bottom: 10px;
}
<DOCTYPE! html>
  <html>

  <head>
    <title>Survey Form</title>
    <link href="surveyform.css" type="text/css" rel="stylesheet">
  </head>

  <body>

    <div class="yellow">
      <h1>Survey Form</h1>

      <div class="grey">

        <center>
          Let us know how we can improve freecode camp
        </center>

        <br>

        <form>
          <div class="row">
            <div class="left">
              <label>
                Which option best describes your current role 
              </label>
            </div>

            <div class="right">
              <select>
                <option>student</option>
                <option>engineer</option>
              </select>
            </div>
          </div>

          <div class="row">
            <div class="left">
              <label>
                Things that should be improved in future
              </label>
            </div>

            <div class="right">

              <div class="input-group">
                <input type="checkbox" name="a">
                <span> Front end projects</span>
              </div>

              <div class="input-group">
                <input type="checkbox" name="a">
                <span> Backend Projects</span>
              </div>

              <div class="input-group">
                <input type="checkbox" name="a">
                <span> Structure </span>
              </div>
            </div>
          </div>

        </form>
      </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

Tips for accessing a DOM element's ::before content using JavaScript

Is there a way to retrieve the content of a DOM element's ::before pseudo-element that was applied using CSS3? I've attempted several methods without success, and I'm feeling very confused! // https://rollbar.com/docs/ const links = docum ...

Is there a way to load and play different sounds on multiple audio players based on the length of an array?

I am attempting to load various sounds (.mp3 audio) on separate audio players that are displayed on a single HTML page. The number of players displayed on the screen is determined by the length of the array. In this specific example, I have 3 elements in t ...

How can you resolve redefinition warnings detected by the CSS Validator?

After running my site through the W3C CSS Validator, I was surprised to see that it returned a total of 3146 warnings. The majority of these warnings are redefinition alerts, such as: .fa.fa-check Redefinition of color .fa.fa-check Redefinition of ...

Incorporating styling preferences within a directive's template

One of the directives I am currently working on looks like this: app.directive('MessageChild', function($timeout) { return { restrict: 'E', scope: { pos: '=?', msg: '=' ...

Numerous CSS class attributes

I have been experimenting with creating my own custom progress bar using CSS. While the HTML5 <progress value="10" max="100"></progress> element could work, I prefer to create it from scratch. In my CSS code, I have defined the .progressbar c ...

What are your thoughts on CSS alignment?

Having difficulty aligning unordered lists the way I want. Below is an image of my desired layout, looking for guidance on achieving the version on the right side. I will be using between 1 and 6 unordered lists on different pages, so a universal solution ...

What causes the unexpected behavior of JQuery's .animate() function?

I am currently working on a project that involves creating a div element for the purpose of dragging and dropping files. My goal is to have the height of the div increase when a file is dragged into it, and decrease when the file is dragged out. To achiev ...

What is the best way to choose the next adjacent element using a CSS selector with Python Selenium?

The structure of the DOM is as shown below: <ul> <li> <a href="#" role="button" class="js-pagination link" data-page="1">1</a> </li> <li> <a href="#" role="button" class="js-pagination link active" data ...

Mastering @media queries to dynamically alter widths in prop styled components

I have a unique component that utilizes an object with its props for styling. const CustomSection = ({ sectionDescription, }) => { return ( <Text {...sectionDescription} content={intl.formatMessage({ id: &apos ...

Troubleshooting Issue: Minified CSS in Vue.js not displaying correctly when deployed on Azure static website

I have successfully deployed a static vue.js website to Azure at The development build looks great in Chrome and Safari on OS X, and the production build works fine when served from the dist directory. However, the CSS doesn't seem to be rendering c ...

Use either Jquery or CSS3 to hide a div if one of its inner divs is empty

I have multiple data sets to display in divs with the same class name. Each div contains two inner divs. <div class="div1"> <div class="div2">Abc</div> <div class="div3"><?php echo $row['SOME VALUE']; ?>< ...

Determine the dimensions of child components within Svelte templates

I am currently in the process of transitioning a VanillaJS website to Svelte, and I need to have divs randomly positioned on the webpage. It's important to note that each div's size can vary depending on its content, so they cannot have a fixed s ...

What would you name this particular element?

I want to create a unique slider design but I'm unsure where to begin or how to search for information because I don't know the correct terminology. Does this type of slider have a specific name? I heard about Marquee, but that seems like someth ...

What is the best way to update or include a new class in the jQuery mobile loader widget?

After reviewing the documentation at this link: I discovered a method to modify or add the default class of the loader widget, ui-loader. Despite my attempts, I have not been able to see any changes. You can view my demo here: https://jsfiddle.net/yusril ...

Extremely efficient CSS utility classes for supreme performance

I've noticed the rise of CSS utility classes and I'm curious about their impact on performance. Is there a better approach? Option One - creating HTML elements with multiple utility classes like: <div class="padding flex justifyCenter align ...

What's the process for browsers to render the 'span' element?

<p> <span>cancel</span><span>confirm</span> </p> <hr> <p> <span>cancel</span> <span>confirm</span> </p> Both should display the same result. However, in the ...

The CSS 'd' attribute for the <path> element is not functioning properly in Firefox

My generated code cannot be directly modified due to its association with a large JS code. A portion of this code creates an SVG shape, which I attempted to override through CSS. However, my solution does not function properly in Firefox! Below is the ori ...

In Safari, my layout is disrupted by the mere mention of the word 'City'

There's something strange happening in Safari that I can't quite figure out. Here's how my layout looks in Chrome: https://i.sstatic.net/lPhnP.png But when viewed in Safari, it looks like this: https://i.sstatic.net/IMnQb.png For some r ...

Struggling to implement CSS variables across different browsers

I'm struggling to make CSS variables function properly, here is what I have so far: :root { --primary-color: #ffcd600; --spacing: 10px; --blur: 10px; } img { padding: var(--spacing); background: var(--primary-color); } When I check the el ...

Preventing the use of fixed positioning on a navigation bar with the CSS filter property

I successfully created a fixed navigation bar that worked perfectly on my webpage. However, when I added a filter (brightness) to an image on the page, the navigation bar disappeared. I tried various solutions including using pseudo-elements and adjusting ...