HTML inputs overlapping when using absolute positioning

TheSoundDefense

I'm trying to create an input form on a web page, and I want all of the input elements to be lined up along a certain column. My idea was to use absolute positioning to just shift all of the input elements over to a specific point on the page. It's working fine, except for one problem: the input elements are overlapping with each other a little bit, vertically.

Here's a MVCE:

<!DOCTYPE html>
<html><head>
<style>
span.right_align {
    display: inline;
    position: absolute;
    left: 80px;
}
div.form_container {
    position: relative;
}
</style>
<title>World's Best GUI</title></head>

<body type="text/css" style="background-color: #F7D879; font-family: Georgia, serif">

<div class="form_container">
  <form name="guiForm" method="post" action="return false;">
    Input 1: <span class="right_align"><input type="text"></span><br>
    Input 2: <span class="right_align"><select autocomplete="off">
    <option value="yes">Yes</option>
    <option value="no">No</option></select></span><br>
    Input 3: <span class="right_align"><input type="text" size="50"></span><br>
    Input 4: <span class="right_align"><input type="text"></span>
  </form>
 </div>

</body>
</html>

As far as I can tell, the problem is because the font is smaller than the size of the input box, but it's the size of the font that determines where a new line "begins". If you comment out or remove everything in the right_align class, they stop overlapping (but they also stop lining up so nicely).

I'll also note that the reason I went for the span-class solution is because I need to 1) have some lines dynamically disappear and reappear, depending on the current state of a drop-down, and 2) dynamically create new input items that will also line themselves up nicely. This seemed like a solution that would interfere very little with the current workings of my web page.

Is there a simple way to fix this? Should I be creating these columns in an entirely different way? I'm open to totally new ideas as well.

EDIT: someone suggested I create a jsfiddle, so I did: http://jsfiddle.net/uy9comxk/

EDIT 2: there will be lines where I have multiple inputs that have to appear beside each other on the same line (for date inputs). I didn't include them because it would have increased the MCVE size by a lot.

Michel

In your css, use a line-height and it will work:

div.form_container {
    position: relative;
    line-height: 25px;
}

With a fiddle

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

HTML layout without using absolute positioning

From Dev

HTML layout without using absolute positioning

From Dev

Using margins vs absolute positioning when positioning elements?

From Dev

Html Absolute positioning

From Dev

Absolute positioning of div without overlapping div above

From Dev

Absolute positioning of div without overlapping div above

From Dev

Absolute Positioning Varies Between Browsers when Using Pseudo-Elements

From Dev

HTML overlapping elements in absolute elements

From Dev

Text is breaking using absolute positioning

From Dev

CSS positioning independently of other overlapping elements (without position: absolute)

From Dev

CSS positioning (relative, absolute inside relative) + overlapping issue?

From Dev

How to avoid overlapping between two divs positioning absolute inside a div positioning relative?

From Dev

Am I using absolute positioning correctly when placing one element over another?

From Dev

HTML how to use position:absolute; without overlapping?

From Dev

HTML CSS Div overlapping absolute & relative position

From Dev

Setting height of layers without using absolute positioning

From Dev

Changing the order of elements using absolute positioning

From Dev

Position element without using absolute positioning

From Dev

Adding Components to Frame using Absolute Positioning

From Dev

Why is HTML POST form interpreted as GET when using an absolute URL?

From Dev

Why is HTML POST form interpreted as GET when using an absolute URL?

From Dev

absolute positioning inside to relative parent overflows div when padding set

From Dev

absolute positioning inside to relative parent overflows div when padding set

From Dev

Absolute positioning inside relative positioning?

From Dev

How to position a div to the bottom of the container, without using absolute positioning?

From Dev

line not being created using psedo elements and absolute positioning

From Dev

CSS drop down menue using absolute positioning with a left:auto position

From Dev

Positioning of div's using css: layout issue with absolute positioned div

From Dev

Getting Text to sit over a video tag without using absolute positioning

Related Related

  1. 1

    HTML layout without using absolute positioning

  2. 2

    HTML layout without using absolute positioning

  3. 3

    Using margins vs absolute positioning when positioning elements?

  4. 4

    Html Absolute positioning

  5. 5

    Absolute positioning of div without overlapping div above

  6. 6

    Absolute positioning of div without overlapping div above

  7. 7

    Absolute Positioning Varies Between Browsers when Using Pseudo-Elements

  8. 8

    HTML overlapping elements in absolute elements

  9. 9

    Text is breaking using absolute positioning

  10. 10

    CSS positioning independently of other overlapping elements (without position: absolute)

  11. 11

    CSS positioning (relative, absolute inside relative) + overlapping issue?

  12. 12

    How to avoid overlapping between two divs positioning absolute inside a div positioning relative?

  13. 13

    Am I using absolute positioning correctly when placing one element over another?

  14. 14

    HTML how to use position:absolute; without overlapping?

  15. 15

    HTML CSS Div overlapping absolute & relative position

  16. 16

    Setting height of layers without using absolute positioning

  17. 17

    Changing the order of elements using absolute positioning

  18. 18

    Position element without using absolute positioning

  19. 19

    Adding Components to Frame using Absolute Positioning

  20. 20

    Why is HTML POST form interpreted as GET when using an absolute URL?

  21. 21

    Why is HTML POST form interpreted as GET when using an absolute URL?

  22. 22

    absolute positioning inside to relative parent overflows div when padding set

  23. 23

    absolute positioning inside to relative parent overflows div when padding set

  24. 24

    Absolute positioning inside relative positioning?

  25. 25

    How to position a div to the bottom of the container, without using absolute positioning?

  26. 26

    line not being created using psedo elements and absolute positioning

  27. 27

    CSS drop down menue using absolute positioning with a left:auto position

  28. 28

    Positioning of div's using css: layout issue with absolute positioned div

  29. 29

    Getting Text to sit over a video tag without using absolute positioning

HotTag

Archive