Wrapping HTML input elements in a div for alignment

I need help aligning the inputs in my form to match the image provided https://i.sstatic.net/AXhlp.png. I attempted to center the div using <center>, but I am unsure how to properly align the elements based on the image reference.

<center>
    <div>
        <div>
            <center>
            Priority:
            <input  align="middle" type="radio" id="high" name="priority" value="High">
            High
            <input type="radio" id="medium" name="priority" value="Medium">
            Medium
            <input type="radio" id="low" name="priority" value="Low">
            Low
             </center>
        </div>
        <br />
        <div>
            <label for="subject">Subject: </label>
            <input type="text" id="subject" name="subject">  
        </div>
        <br />
        <div>
            <label for="appointment_date">Date: </label>
            <input type="date" id="appointment_date" name="appointment_date">

            <label for="start_time">Start Time</label>
            <input type="time" id="start_time" name="start_time" />

            <label for="end_time">End Time</label>
            <input type="time" id="end_time" name="end_time"/>
        </div>
        <br />
        <input type="button" onclick="addAppointment()" value="Add Appointment" />
        <br />
    </div>
    <hr>
</center>

Any assistance would be greatly appreciated. Thank you!

Answer №1

If you're hesitant about writing CSS from scratch, consider using Bootstrap as a solid alternative for building your web design. Check out the sample code below for reference.

  1. Center tag is now obsolete in HTML5 and no longer supported
  2. The next step would be to delve into crafting custom CSS styles that fit your needs.

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
  <div class="container">
    <!-- first row -->
    <div class="row my-3">
      <div class="col-sm-3">Priority:</div>
      <div class="col-sm-3"><input align="middle" type="radio" id="high" name="priority" value="High"> High
      </div>
      <div class="col-sm-3"><input type="radio" id="medium" name="priority" value="Medium"> Medium
      </div>
      <div class="col-sm-3"><input type="radio" id="low" name="priority" value="Low"> Low
      </div>
    </div>
    <!-- second row -->
    <div class="row my-3">
      <div class="col-sm-3"><label for="subject">Subject: </label></div>
      <div class="col-sm-9"><input type="text" class="form-control" id="subject" name="subject"></div>
    </div>

  <!-- 3rd row -->

  <div class="row my-3">
    <div class="col-sm-4"> <label for="appointment_date">Date: </label>
      <input type="date" id="appointment_date" name="appointment_date"></div>
    <div class="col-sm-4"><label for="start_time">Start Time</label>
      <input type="time" id="start_time" name="start_time" /></div>
    <div class="col-sm-4"><label for="end_time">End Time</label>
      <input type="time" id="end_time" name="end_time" /></div>
  </div>
  <!-- 4th row -->

  <div class="row my-3">
    <div class="col-sm-12 text-center">
      <input type="button" onclick="addAppointment()" value="Add Appointment" />
    </div>
  </div>

  </div>
  <!-- container ends -->

Answer №2

If you want to achieve this, flex can be a great tool.

Check out the created code pen

#priorityBox{
  display:flex;
  flex:1;
  justify-content:space-around;
}

Answer №3

To create this layout, you can utilize flex-box properties:

.wrapper {
width: 100%;
display: flex;
justify-content: space-between;
padding: 6px 0;
max-width: 600px;
margin: auto;

}

input[type="text"] {
   width: 100%;
   margin-left: 15px;
   }
    <div>
<div class="wrapper">
Priority:
<span><input align="middle" type="radio" id="high" name="priority" value="High"> High</span>
<span><input type="radio" id="medium" name="priority" value="Medium"> Medium</span>
<span><input type="radio" id="low" name="priority" value="Low"> Low</span>
</div>
<div class="wrapper">
<label for="subject">Subject: </label>
<input type="text" id="subject" name="subject">
</div>
<div class="wrapper">
<label for="appointment_date">Date: </label>
<input type="date" id="appointment_date" name="appointment_date">

<label for="start_time">Start Time</label>
<input type="time" id="start_time" name="start_time" />

<label for="end_time">End Time</label>
<input type="time" id="end_time" name="end_time" />
</div>
<center> <input type="button" onclick="addAppointment()" value="Add Appointment" />

</center>
    </div>
    <hr>

Answer №4

This is the custom code I've created using Bootstrap:

<!DOCTYPE html>
<html lang="cs">

<head>
  <meta charset="utf-8">
  <meta name="author" content="Vojtěch Matras">
  <title></title>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
</head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<div class="container-fluid">
    <div class="row">
      <div class="col-sm-2 col-2" >Priority</div>
      <div class="col-sm-10 col-10" > <input type="radio" name="Priority" value="high">high<br>
        <input type="radio" name="Priority" value="medium"> medium<br>
        <input type="radio" name="Priority" value="low"> low</div>
   </div>
    <div class="row">
          <div class="col-sm-2 col-2" >Subject</div>
          <div class="col-sm-10 col-10" style="display: block"><input type="text"></div>
    </div>
    <div class="row">
        <div class="col-sm-2 col-2" >Date:</div>
        <div class="col-sm-2 col-2" ><input type="date" id="appointment_date" name="appointment_date"></div>
        <div class="col-sm-2 col-2" >Start time:</div>
        <div class="col-sm-2 col-2" ><input type="time" id="start_time" name="start_time" /></div>
        <div class="col-sm-2 col-2" >End time:</div>
        <div class="col-sm-2 col-2" ><input type="time" id="end_time" name="end_time"/></div>
  </div>

  </div>

  <center><input type="button" value="Add Appointment"></center>

</html>

To view a live demo, visit this fiddle:https://jsfiddle.net/mgdzuod4/

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

Convert an HTML webpage into a JSON format that represents the structure of the DOM tree

I am having an index.html file with multiple div tags inside it. I am attempting to retrieve content from all the div tags on the page, but currently, I am only able to fetch the content from the first div tag. What I actually need is the content from all ...

Retrieving a boolean value (from a JSON file) to display as a checkbox using a script

Currently, I am utilizing a script to fetch data from a Google Sheet $.getJSON("https://spreadsheets.google.com/feeds/list/1nPL4wFITrwgz2_alxLnO9VBhJQ7QHuif9nFXurgdSUk/1/public/values?alt=json", function(data) { var sheetData = data.feed.entry; va ...

Expandable Bootstrap collapse and accordion open horizontally, not vertically

I want to use Bootstrap collapse but I want to keep my div-s with the content beneath each link, mainly because that's how i need it to work on mobile (the menu is a column and that the content opens under each link). Unfortunately, on website I have ...

Error encountered while attempting to insert YouTube video with video.js player using an iFrame

I'm currently using video.js along with the vjs.youtube.js plugin to incorporate YouTube videos directly into the video.js player on my website. Everything is working smoothly and I am able to dynamically add videos to the page. However, I've en ...

Generating a div element within another div element

I have been attempting to add a new div inside an existing one using append, after, etc., but so far I have not been successful. The structure of the code is as follows: <div class="row"> <div class="col-xs-12" id="element-container"> &l ...

What is the best way to achieve a stylish Bootstrap modal design with a blurred and transparent header, as well as a left sidebar that seamlessly blends into

Is it feasible to create a modal with a blurred (transparent) background for the header section, allowing the site to show through? Additionally, can a sidebar on the left side of the modal also be transparent and blurred, revealing the site underneath? C ...

Switching the navbar image with HTML and JavaScript when clicked

Looking to change the image upon clicking on any of the navbar items. Emulating the navigation bar behavior from this website : This is my current progress : The HTML file : <html lang="en"> <head> <meta charset="utf-8" /> ...

"The onkeydown event dynamically not triggering for children elements within a parent element that is contentEditable

Can anyone offer some insights into why this code isn't functioning as expected? My goal is to attach the listener to the children elements instead of the body so that I can later disable specific keystrokes, such as the return key. <!DOCTYPE html ...

What is the process for implementing custom CSS styles in Cognos?

I've been working on creating Cognos reports and I'm looking to change the overall design of some specific ones (prompt pages and report pages). Is there a way for me to use different custom CSS files for each individual report? If that's ...

What is the best way to make a table fill 100% of the available height

Is this a Repetitive Question? How to stretch an HTML table to 100% of the browser window height? Just like the title says, I am looking for a way to make my table element stretch to 100% height even when the content does not entirely fill the page&ap ...

Tips for customizing scroll bar padding and margin using CSS classes or IDs

I am looking to customize three different types of scrollbars with unique padding and margins. Here is the global style for my scrollbars: /* Modifying the scroll bar across the whole application */ /* width */ ::-webkit-scrollbar { width: 5px; he ...

Is the background image unable to fill up the entire screen?

I'm currently facing an issue with my webpage's background not covering the entire vertical space. Despite trying different solutions and referring to previous posts, I haven't been able to resolve it yet. Here is the relevant code: <div ...

Adding a click function to a div individually when they share the same class in HTML

My goal is to include 4 unique divs inside a timeline container: This is how I envision the structure: <div id="timeline" > <div class="timeline-bar t-1"></div> <div class="timeline-bar t-2"> ...

Only implement the CSS styles if there are multiple elements that have the same class

I have 2 cards with the class card displayed within a card-stack. There can be any number of such cards. <div class="card-stack"> <div class="clear"><button name="clear" value="Clear all" onclick=&qu ...

Removing the currently selected item from the OwlCarousel

I am trying to enable users to delete the item that is currently active or centered in an OwlCarousel. I have come across some code related to deleting items, but it seems to be a rare question: $(".owl-carousel").trigger('remove.owl.carous ...

Sharing information between different components in React can be done using props, context, or a

When attempting to edit by clicking, the parent information is taken instead of creating a new VI. I was able to achieve this with angular dialog but I am unsure how to do it with components. This is done using dialog: <div class="dropdown-menu-item" ...

What's the deal with using tables or divs in web design? Are they necessary or just a crazy trend?

For my upcoming project, I am eager to take on this task. The question remains: which approach should I employ - a Div or table method? ...

choose to display on mobile devices as a dropdown menu rather than a modal window

On mobile devices, my select elements are currently displayed as modals with options. However, I need to change this appearance to resemble the dropdown list view observed on desktop devices. Your assistance is greatly appreciated. ...

Connecting components in React using their IDs on the same page

In my project to create a one-page website in React, I have divided it into different components such as a navbar component and an education component. My goal now is to link the navbar to the education section. In my App.js file, I am including the educat ...

Tips for arranging a menu horizontally with buttons in CSS

I am currently working with a dropdown menu that I coded using CSS, similar to the one shown at . My issue is that I have 4 menu items and I want the total width of the parent div to be divided equally among each item, regardless of the resolution. Curre ...