Tips for positioning a label and text box side-by-side using HTML?

Looking at the code below, I see that the summary and its text box are aligned inline, but the description text box is appearing below the label 'description'. How can I make it align inline as well? Any suggestions on how to fix this issue would be greatly appreciated.

    .left {
      width: 30%;
      float: left;
      text-align: right;
    }
    .right {
      width: 65%;
      margin-left: 10px;
      float: left;
    }
<body>
  <div class="container">
    <div class="row">
      <div class="col-sm-5 col-sm-push-3 col-xs-4 col-xs-push-2">
        <h1 class="text-center" style="font-family:Colonna MT;font-size:50px;color:ForestGreen ;">Post Your Ad</h1>
        <form action="post" class="login-form">
          <div>
            <label class="left">Summary:</label>
            <input class="right" type="text" name="Summary" size="50">
          </div>
          <div>
            <label class="left">Description:</label>
            <input class="right" type="text" name="Description" style="height:100px;width:400px">
          </div>
        </form>
      </div>
    </div>
  </div>

Answer №1

Here's a helpful suggestion: Check out the demo

If you require a multi-line text box, consider using textarea instead of an input type with text

    <div class="form-group row">
    <label for="inputEmail3" class="col-md-6 col-sm-12 form-control-label text-right">Summary</label>
      <div class="col-md-6 col-sm-12">
        <input type="text" class="form-control" name="Summary" size="50">
      </div>
    </div>

    <div class="form-group row">
      <label for="inputEmail3" class="col-md-6 col-sm-12 form-control-label text-right">Description</label>
      <div class="col-md-6 col-sm-12">
        <textarea class="form-control" name="Description"></textarea>
      </div>
    </div>

Edit:

Just a note, it should be the form-control-label class, not the form-control class.. Additional information can be found here

Updated Demo: To adjust the height, experiment with changing the value of rows="8" for <textarea>

Answer №2

If you're utilizing Bootstrap (as evidenced by the classes in your code), I suggest taking advantage of their form layout options. It seems like a Horizontal Form would suit your needs:

Documentation

Here's an example:

<form class="form-horizontal">
  <div class="form-group">
    <label for="summary" class="col-sm-2 control-label">Summary</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" id="summary" />
    </div>
  </div>
  <div class="form-group">
    <label for="description" class="col-sm-2 control-label">Description</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" id="description" style="height:100px;width:400px" />
    </div>
  </div>      
</form>

Answer №3

<textarea class="right" name="Description" style="height:100px;"></textarea>

Update the description input to a textarea with a height of 100px.

Answer №4

If you've already incorporated the bootstrap framework, there's no need to add extra CSS for inline forms. Simply use the code below:

<div class="form-group">
     <label class="col-lg-3 control-label ">City</label>
      <div class="col-lg-9">
        <div class="form-inline">
          <div class="form-group ">
            <div class="col-lg-12">
              <label class="sr-only" for="city">City</label> 
              <input type="text" id="city" name="city" class="form-control " placeholder="E.g. Thrissur" >
            </div>
          </div> 
          <div class="form-group ">
            <div class="col-lg-12">
              <label class="sr-only" for="county">County</label> 
              <input type="text" id="county" name="county" class="form-control " placeholder="E.g. India" >
            </div>
          </div>
        </div>
      </div>
    </div>

Answer №5

Does this look good to you?
https://jsfiddle.net/abcdef123/

.top {
  width: 40%;
  display: inline-block;
  text-align: center;
}
.bottom {
  width: 55%;
  margin-left: 15px;
  display: inline-block;
}

Answer №6

give this a shot:

<html>
  <head>
    <title>example</title>
    <style type="text/css">
      .left {
          width: 30%;
          display: inline-block;
          text-align: right
      }
      .right {
          margin-left: 10px;
          display: inline-block;
      }
    </style>

  </head>

  <body>
      <div class="container">
        <div class="row">
          <div class="col-sm-5 col-sm-push-3 col-xs-4 col-xs-push-2">
            <h1 class="text-center" style="font-family:Colonna MT;font-                    size:50px;color:ForestGreen ; text-align: center">Submit Your Form</h1>
 <form action="post" class="login-form">
      <div>
        <label class="left">Title:</label>
        <input class="right" type="text" name="Title" size="50" style="width:400px">
      </div>
    <div>
       <label class="left">Message:</label>       
       <input class="right" type="text" name="Message" style="height:100px;width:400px">
   </div>
 </form>
  </div>
</div>
</div>
</body>
</html>

Answer №7

If you're having trouble positioning it correctly, there is an alternative to using tables for layout:

.login-form {
    display: table;
}
.login-form>div {
    display: table-row;
}

.cell {
    display:table-cell;
    vertical-align: top;
}
...

To enhance the structure, wrap the inputs in a div and apply a "cell" class (maybe consider using a textarea instead):

...
<form action="post" class="login-form">
    <div>
        <label class="left cell">Summary:</label>
        <div class="cell">
            <input class="right" type="text" name="Summary" size="50">
        </div>
    </div>
    <div>
        <label class="left cell">Description:</label>
        <div class="cell">
            <textarea class="right" name="Description" style="height:100px;width:400px"></textarea>
       </div>
   </div>
</form>
...

Take a look here

Answer №8

Eliminate the style attribute from the description input field to transform it into a summary input box.

<form action="post" class="login-form">
  <div>
    <label class="left">Summary:</label>
    <input class="right" type="text" name="Summary" size="50" style="width:400px">
  </div>
<div>
   <label class="left">Description:</label>       
   <input class="right" type="text" name="Description">

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

What could be the reason that angularjs html template requests aren't appearing in the top websites when viewed in a

After referring to the link , I discovered a way to determine which programming tools different sites use for application development. However, when I debug HTTP requests using Firebug, I noticed that HTML requests are not explicitly shown in the log. Alt ...

What is causing Firefox to display an additional line in this section?

After much effort, I've been attempting to eliminate the extra spacing on this page in Firefox: Do you see the menu? If you compare it to Chrome, you'll notice that the menu is positioned too low beneath the background, giving the layout a broke ...

Having trouble making an HTML5 video work on Android? It seems to play fine when clicking the play button,

It has come to my attention that html5 video on Android devices is unable to autoplay. Currently, the video only plays on the device when the user manually clicks on the play button. <video width="640px" height="360px" src="media/video/Moments_of_Every ...

The presence of the WordPress admin bar results in extra whitespace on the page, while including

In the process of creating my very first custom WordPress theme, I encountered an issue with whitespace at the top of the body. This was caused by calling wp_head(); in header.php and including the header on each page. To offset this whitespace, I added a ...

Issues arise with the layout when using Twitter Bootstrap as adding an extra column causes the main menu to be concealed

Having some issues with a Bootstrap 3.0.x template at the moment: You can check out the demo template here: www.kuzma.tk Originally, the layout looked like this: left sidebar: col-md-2 col-md-offset-1 middle component: col-md-6 Right sidebar: ...

CSS styling not appearing on HTML button

I'm attempting to create a login page similar to Instagram using HTML and CSS. However, I'm having trouble styling the button to match Instagram's login page. The button <input type="submit" class="sub-btn"> The CS ...

What is the best way to activate a function once two HTML elements have been completed?

In my HTML code, I have integrated a datepicker and a select element. Currently, there is a button linked to the method checkAvailability() <div class ="d-flex flex-row bd-highlight mb-3"> <div class = "form-froup row"> ...

Steps to toggle text color upon clicking and switch the color of another text

As a beginner with no Js knowledge, I am trying to achieve a specific function. I want to be able to change the color of text when it is clicked, but also have the previously clicked text return to its original color. <div class="mt-5 fi ...

Express template failing to connect with scripts, css, and images

When using Express, I encounter difficulty in getting the css, js, and images to link up correctly when running the index.html file. The images are not showing up and the css and js files are not linking properly. <link rel="stylesheet" type="text/css" ...

Using JQuery to eliminate the current div in an image slider

I currently have an image slider that allows users to switch between images. There are two buttons - one adds a new item to the slider, while the other is supposed to remove the current image from the slider, but it doesn't seem to be working properly ...

How can I prevent Bootstrap from disrupting my CSS layout and what steps can I take to rectify the issue?

Apologies for any language mistakes, as this is my third language and I am new to web design. I want to create a simple website using html, css, and bootstrap that does not need to be responsive. I have successfully added a sticky Navbar with javascript ...

Sometimes, the page-wide background in Internet Explorer doesn't load properly

Currently, I am working on a website that uses an image as the background for the entire site. Everything seems to be running smoothly in Firefox and Safari, but Internet Explorer is giving me some trouble. Sometimes the image fails to load at all, other t ...

What is the best way to anchor floating labels in React while incorporating Tailwind CSS?

I am currently working on developing a registration form using React and Tailwind CSS. As part of this project, I have implemented a feature where the label slides up when an input form is focused. Everything seems to be working fine up to this point. Howe ...

Extract all information from the HTML table and store it in an array

I'm currently able to store all generic text data in an array, but I'm facing difficulties with the select boxes inside table cells. In my jQuery script, I have the following: $('.image-button').click(function(){ var myTableArr ...

Employing featherlightGallery.js without the need for anchor tags

I've been experimenting with the FeatherlightGallery plugin for a lightboxing feature on an image slider. The slider contains images directly, without anchor tags wrapping them. However, I'm facing an issue where clicking next/prev doesn't l ...

Implementing a Scroll-down Functionality for Drop-down Menu Choices with the Power of CSS and HTML

My select menu has too many options to fit on the page. How can I implement a scrollable menu within the select box when it runs out of space? <form> <ul> <li id="snow_filter"> <label>Enter Resort&l ...

Angular ngx-translate - Setting a fallback value for untranslated parameters in translation strings

I want to set a default value for the expected parameter in the translation value if the programmer does not provide one. For instance, consider this key in en.json: "NoRecordsWereFound": "No matching {{records}} were found for your search.", When provi ...

Is there a way to make negative numbers in a JSON response from JS turn red easily?

I am currently working on a website ticker tape and have successfully gathered all the necessary data. However, I am facing an issue with changing the color of the daily price change based on whether it is positive or negative. I'm unsure where to beg ...

Generating Dynamic Widgets Within the Document Object Model

Currently, I am working with jQuery Mobile 1 alpha 1. In order to create a text input field using jQuery Mobile, you need to include the following HTML code: <div data-role='fieldcontain'> <label for='name'>Text Input:</ ...

What is the best way to retrieve information from a data set?

After borrowing some basic HTML, CSS, and JavaScript code from CodePen, I ran into an issue while attempting to convert it to React. The error message says that it cannot read properties of null (specifically 'dataset'). Here is the JavaScript c ...