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
369 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

757 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

22 Experts available now in Live!

Get 1:1 Help Now