Solved

How do I vertically align a label, input control and button across different divs in HTM5 and CSS3?

Posted on 2013-02-01
2
373 Views
Last Modified: 2013-02-05
Hi:

I'm alignment issues with some controls in HTML5.

Consider the following HTML5 block:
---------------------------------------------------

<form action="#" method="post">
    <div class="divInput">
        <label for="something">Sample Label</label>
        <input type="input" name="something" id="something" class="inputClass"/>
    </div>
    <div class="divInput">
        <button>It's a buttonnnnnn!</button>
    </div>
</form>

with the following CSS3 styling info:
------------------------------------------------
fieldset {
    font-size: 1em;
    padding: 0.5em;
    border-radius: 1em;
    font-family: sans-serif;
}

div.divInput{
  float:left;
  padding-left: 2%;
}

input.inputClass{
  width: 86%;
  background-color:aquamarine;
}
label, input, button {
    font-size: inherit;
    padding: 0.2em;
    margin: 0.1em 0.2em;
    -moz-box-sizing: content-box;
    -webkit-box-sizing: content-box;
    box-sizing: content-box;
}

This is actually a small snippet from a larger, more complicated layout that I have.
If I use the above mentioned HTML and style info,  the button seems to "kind of" align
itself vertically with the label.

What I'd like is for the button to align itself with the input control.
So roughly speaking, I'd like to see this:
-------------------------------------------------------
Label
|Input Control|          |Button|

How would I achieve this?

Here is a link the sample in jsFiddle:
http://jsfiddle.net/QKLUH/405
0
Comment
Question by:jxbma
2 Comments
 
LVL 38

Accepted Solution

by:
Tom Beck earned 500 total points
ID: 38845562
You could add this definition:

div.divInput button{
    position:relative;
    bottom:-19px
}
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 38846010
http://jsfiddle.net/QKLUH/405/embedded/result/

What you want is html like below. Then give the row a width in px not % if you don't want it to wrap.  Then give the inside class your float left and width and padding not more then the row class.


<div class="row">
    <div id="thing_one" class="inside"></div>

   <div id="thing_two" class="inside"></div>
</div>
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
iframe detection of parent window scale 20 60
Put glyphicon in my input button 4 28
HTML Relative path 9 29
is this a cms? 8 35
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now