Solved

Spacing and vertical alignment

Posted on 2014-03-20
5
235 Views
Last Modified: 2014-03-21
How can I get rid of the space between the header and head-banner div tags and how can I align the img and the text that sit in the head-banner div. Thank you.


<!DOCTYPE html>
<html charset="UTF-8">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Test</title>
	<link rel="stylesheet" type="text/css" href="styles/styles.css" />	

	<!--[if lt IE 7]>
		<style type="text/css">
			#wrapper { height:100%; }
		</style>
	<![endif]-->
	
</head>

<body>

	<div id="wrapper">
		
		<div id="header">
		</div><!-- #header -->
		
		<div id="head-banner">
			<p>
			<img src="imgs/kevinbarlow.png" />
			Building Contractor
			Key West, Florida</p>
		</div>
		
		<div id="content">
		</div><!-- #content -->
		
		<div id="footer">
		</div><!-- #footer -->
		
	</div><!-- #wrapper -->
	
</body>

</html>

Open in new window


html,
body {
	margin:0;
	padding:0;
	height:100%;
}
html{
	background: url(S12_Blueprints.gif) no-repeat center center fixed;
	-webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}
#wrapper {
	min-height:100%;
	width: 100%;
	position:relative;
}
#header {
	background:#000000;
	padding:10px;
	border-bottom: 2px solid red;
}
#head-banner{
	height: 75px;
	max-width: inherit;
	margin-top: 0;
	margin-bottom: 0;
	background-color: #ffffff;
}
#head-banner img p{
	display: inline-block;
	vertical-align: middle;
}
#content {
	min-width: 100%;
	height: 500px;
	border: 1px solid black;
}

#footer {
	background:#ffab62;
	width:100%;
	height:100px;
	position:absolute;
	bottom:0;
	left:0;
	border: 1px solid black;
}

Open in new window

0
Comment
Question by:centem
5 Comments
 
LVL 5

Expert Comment

by:jayakrishnabh
ID: 39941884
To remove space between header and header-banner make padding as 0px for the header style

#header {
            background:#000000;
            padding:0px;
            border-bottom: 2px solid red;
      }
0
 

Author Comment

by:centem
ID: 39941943
Thanks jayakrishnabh but that didn't work. The issue seems to be with margin spacing between the two tags. I tried setting the margin to 0 but that didn't seem to work either.
0
 
LVL 4

Accepted Solution

by:
slfede earned 500 total points
ID: 39941989
To remove the spacing between the header and head-banner divs, simply either:

- remove the p tag from head-banner div

- edit this css

This is incorrect, your p tag comes before the img tag.
#head-banner img p{
	display: inline-block;
	vertical-align: middle;
}

Open in new window


It should be this:

#head-banner p{
    display: inline-block;
    vertical-align:middle;
    margin-top:0;
}

Open in new window


If you want to center align it:

#head-banner{
	height: 75px;
        width:100%;
        text-align:center;
	margin-top: 0;
	margin-bottom: 0;
	background-color: #ffffff;
}

Open in new window


http://jsfiddle.net/cTGLS/
0
 

Author Comment

by:centem
ID: 39942077
Thanks slfede,
I'm trying to align the text vertically with the img.  I tried the below css but it does not align it.
 
#head-banner p{
	display: inline-block;
	vertical-align: middle;
	margin-top: 0;
}

Open in new window

0
 
LVL 10

Expert Comment

by:jtwcs
ID: 39943108
The spacing is being caused by the browser default margins being applied to the <p>.  Look into using a css reset to start off with a good baseline.

The text can be vertically aligned to the middle of the image by styling the <img> with a vertical-align: middle declaration.

See here for full example.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

746 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

14 Experts available now in Live!

Get 1:1 Help Now