DHthenoob
DHthenoob

Reputation: 13

Don't want DIVs in header to overlap

in the I'm painfully new to CSS (and stackoverflow!) and can't seem to get the divs in my header to line up and not overlap. I have a logo image with align="absmiddle" so that the h1 text is to the right of it, which is the way I want it. I want another line of text with the business contact information in small text below the h1 (still to the right of the logo). When I add the div with the contact info it shows up behind the logo instead. I've seen a lot of questions and solutions for people wanting an overlap and for issues with different browsers and resizing but can't seem to find something simple that asks what I'm asking. Appreciate your help.

Here's the html:

<body>
<div id="outer-container">
<div id="header">
      <div id="main-logo">
        <h1><a href="#"><img src="images/Murray_Logo.gif" alt="Murray logo" width="144" height="144" align="absmiddle" />Company name here</a></h1>
      </div>
    <br clear= "all" />
      <div id= "contactinfo">address</div>
      <div id="main-menu">
        <ul>
          <li class="first-item">
            <a href="#">Home</a>
          </li>
          <li>
            <a href="#">Services</a>
          </li>
          <li class="last-item">
            <a href="#">Testimonials</a>
          </li>
        </ul>
  </div>
</div>
</body>

and the CSS:

* {
  padding: 0;
  margin: 0;
}

a {
  color: #2D80D2;
  text-decoration: underline;
}

a:hover {
  text-decoration: none;
}

body {
  font-size: 11.5pt;
  line-height: 1.5em;
  color: #404040;
  background: #FFFFFF url('images/bg1.gif') repeat-x top left;
}

body,input {
  font-family: Georgia, serif;
}

br.clear-all {
  clear: both;
}

h1,h2,h3,h4 {
  letter-spacing: -1px;
}

h1,h2 {
  font-family: Century, serif;
}

h2 {
  font-size: 1.75em;
}

h2,h3,h4 {
  margin-bottom: 0.75em;
   color: #000;
}

h3 {
  font-size: 1.5em;
}

h4 {
  font-size: 1em;
}

p {
  margin-bottom: 1.25em;
}

ul {
  margin-bottom: 1.25em;
}

ul h4 {
  margin-bottom: 0.3em;
}

#header {
  height: 175px;
  position: relative;
  padding: 20px;
}

#outer-container {
  position: relative;
  width: 1200px; /* was 980px */
  margin: 90px auto 0 auto;
}

#inner-container {
  padding: 0;
  position: relative;
  width: 980px;
  margin: 25px 0 15px 0;
}

#inner-container .features {
  padding-left: 0;
  list-style: none;
}

#inner-container .features li {
  padding: 10px 0 10px 0;
  clear: both;
}

#inner-container ul {
  list-style: none;
}

#inner-container ul li {
  border-top: dashed 1px #B3B3B3;
  padding: 5px 0 5px 0;
}

#inner-container ul li.first-item {
  border-top: 0;
  padding-top: 0;
}

#main-logo {
  height: 145px; /* 6/7/12 DH */
  left: 20px;
  line-height: 107px;
  position: absolute;
  top: 0;
}

#main-logo a {
  text-decoration: none;
  color: #000;
}

#main-logo h1 {
  font-size: 2.2em;
}

#main-logo p {
    font-size:1em;
}

#main-logo img {
    padding: 0 20px 0 0;
}

#main-menu {
  width: 940px;
  border-bottom: solid 1px #1467B9;
  bottom: 0;
  border-top: solid 1px #5AADFF;
  line-height: 53px;
  margin: 0 0 0 0;
  padding: 0 20px 0 20px;
  height: 53px;
  left: 0;
  background: #1E71C3 url('images/bg2.gif') repeat-x top left;
  position: absolute;
}

#main-menu a {
  color: #FFF;
  /*letter-spacing: -1px; /* 6/7/12 DH */
  text-decoration: none;
}

#main-menu ul {
  list-style: none;
}

#main-menu ul li {
  display: inline;
  padding: 0 10px 0 10px;
}

#main-menu ul li.first-item {
  padding-left: 0;
}

#contactinfo {
  font-family:Tahoma, Geneva, sans-serif;
  font-size:10px;;
}

#contactinfo a {
  color: #404040;
}

Upvotes: 1

Views: 1568

Answers (4)

RAN
RAN

Reputation: 1453

In this case your header is position relative, so better keep the id contactinfo as position :absolute and arrange it using margins.

Try this:

#contactinfo {
  font-family:Tahoma, Geneva, sans-serif;
  font-size:10px;
  position:absolute;
  left: 187px;
  line-height: 160px;
}

Upvotes: 0

user1441816
user1441816

Reputation: 841

Along with kinakuta's explanation. Your markup has also some errors.

<div id="outer-container">

is an unclosed element.

<br clear= "all" />

clear is obselete. Use it in CSS.

Upvotes: 0

kinakuta
kinakuta

Reputation: 9037

You're getting overlap because you've absolutely positioned #main-logo and absolute positioning removes the element from the normal flow of the document, meaning other content will no longer respect it's positioning and "overlap" where that absolutely positioned content is. If you want to put that logo in a certain spot, I'd do it with either relative positioning or use some margin.

Upvotes: 0

mooonli
mooonli

Reputation: 2393

basically you could use a div-layout like this:

<div style="float:left;">LOGO</div>
<div style="float:left;">
  <div>COMPANY</div>
  <div>CONTACT</div>
</div>

Like that you have the logo div on the left, and on the right of the logo div you have 2 divs (one above the other) for company and contact information.

Upvotes: 1

Related Questions