user2980830
user2980830

Reputation: 97

Form labels/fields not being centered vertically

I am having trouble vertically centering my labels/fields in my form. I have centered the content horizontally but now would also like to add vertical centering. When I run my code i can see that the fieldset padding is off. The value of the padding on the top is less than the value on the bottom. I figure for the vertical centering to occur they should be equal. Here is my code...

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Contact</title>
        <link href='http://fonts.googleapis.com/css?family=Roboto:400,700' rel='stylesheet' type='text/css'>
        <link rel="stylesheet" type="text/css" href="contact.css">
    </head>
    <body>
        <header id="pageHeader">

        </header>


        <nav class="mainNav">
            <ul>
                <li><a href="../index.html">Home</a></li>
                <li><a href="#">Photos</a></li>
                <li><a href="#">About</a></li>
                <li><a href="#">Contact</a></li>
            </ul>
                <img src="NewLogo3.png">
        </nav>

        <div class="contact">
            <h1>Get In Touch</h1>
            <form action="index.php" method="POST" >
            <fieldset class="boxShadow">
                <label>Name:</label>
                <input type="text" name="name" placeholder="Enter your name" class="boxShadow"/>

                <label>Email:</label>
                <input type="email" name="email" placeholder="Enter your email address" class="boxShadow"/>

                <label>Message:</label>
                <textarea name="message" placeholder="What's on your mind?" class="boxShadow"></textarea>

                <input type="submit" value="Send message" />

            </fieldset>
            </form>
        </div>
        <footer id="pageFooter">
            <p>Thanks for visiting my website</p>
            <span>&copy 2013</span>
        </footer>
    </body>
</html>



html, body, h1, h2 , ul, nav, img{
    margin:0;
    padding: 0;
    font-size: 1em;
    font-family: 'Roboto', sans-serif;
    font-weight: 400;
}
body{
    background: #777777;
    height: 100%;
}

nav{
    background: #40B3DF;
    height: 100px;
    font-size: 2em;
    width: 100%;
    border-bottom: 1px solid black;
}
nav ul{
    position: absolute;
    top: 55px;
    white-space:nowrap;
    margin-left: 100px;
}
nav li{
    display: inline-block;
    background: #A8CB17;
    padding-bottom: 0;
    border-radius: 8px 8px 0 0;
    border-bottom: 2px solid #A8CB17;
    margin-right: 10px; 
    -webkit-box-shadow: -5px 0px 7px 0px rgba(0,0,0,0.75);
    -moz-box-shadow: -5px 0px 7px 0px rgba(0,0,0,0.75);
    box-shadow: -5px 0px 7px 0px rgba(0,0,0,0.75);
}
nav a{
    text-decoration:none;
    color: #004158;
    padding: 10px;  
}
nav img{
    position: absolute;
    right: 50px;
    top: 15px;
}
nav li:hover{
    background: #17649A;
    border-bottom: 2px solid #17649A;
}

p{
    padding-top: 3em; 
    color: #454545;
    text-align: center;
}

h1{
    color: #393939;
    font-size: 3em;
    padding: 1em 0 0 1em;
    text-shadow: 2px 2px 3px rgba(23, 23, 23, 1);
    margin-bottom: 1em;
}

footer{
    border-top: 2px solid #393939;
    background: #40B3DF;
    position:relative;
    bottom:0;   
    height: 60px;
    width: 100%;
    text-align: center; 
}
footer p{
    display:inline-block;   
    margin: 0 auto;
    padding-top: 1.5em; 
    color: #004158;
}

footer span{
    position: relative;
    top: 7px;
    right: -45px;   
}

textarea{
    height: 150px;
    width: 200px;
    padding: 1em;

}
label, input[type=submit]{
    text-transform: uppercase;

}
input, label{
    display: block;
    margin: 0 auto;
    padding: 1em;
    width: 200px;

}
input[type=submit] {    
    margin-top: 2em;
    border-radius: 8px;
    font-weight: 700; 
}

fieldset {
    height: 550px;
    position: relative;
    width: 60%;
    text-align: center;
    background: #676767;
    margin: 0 auto;     
    margin-bottom: 2em;
    /*border: 0;*/

}

Upvotes: 0

Views: 148

Answers (1)

Matthew Johnson
Matthew Johnson

Reputation: 5155

The gap at the bottom of the form is due to the fact that your fieldset has a height of 550px, but your content does not fill that height. Remove the height, and adjust margin/padding from there.

As for the padding on the fieldset, browsers add padding to fieldsets by default. To make your site more consistent across browsers, use a CSS reset, like the HTML5 reset style sheet. That essentially overrides all of a browser's default styling. When using it, apply it above all of your other CSS styles. As for the padding itself, there are a few ways to manage it.

To adjust a certain side, you can use padding-top, padding-bottom, padding-right, or padding-left.

You can adjust top/bottom, left/right using padding: 10px 15px;, which would give you 10px on top and bottom, and 15px on the left and right.

You can also specify top, left/right, and bottom with padding:10px 15px 5px.

Margins are set the same way, just replace "padding" with "margin".

Upvotes: 1

Related Questions