Solved

Spacing and vertical alignment

Posted on 2014-03-20
5
240 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
project copy paste issue 1 61
Debugging Html 8 31
Flex Messes  With Horizontal Positioning 2 22
Flex container in CSS 8 21
This article discusses how to create an extensible mechanism for linked drop downs.
Find out what you should include to make the best professional email signature for your organization.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

679 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