开发者

Unwanted space between divs - HTML, CSS

开发者 https://www.devze.com 2023-02-04 23:23 出处:网络
I have searched throu开发者_如何学编程gh the forums and good old google and have found many answers but non seem to work on my page.

I have searched throu开发者_如何学编程gh the forums and good old google and have found many answers but non seem to work on my page. Anyway here is the question,

I have 2 divs that are positioned side by side, and I wish to get rid of the whitespace

www.blisshair.com.au/test.html :(http://www.blisshair.com.au/test.html)

I want to the black from the "link 1" to join to the main content in the center,

Any help would be greatly appreciated,

Thank you.

EDIT: Tried opening in Internet explorer 8 and it seems top exactly how I want it, besides the 2 bottom divs not lining up, Is it possible to do this with an UL and SPAN tags ? I am aiming for a tabbed look, for example, when you click on link 2, the background around link 2 goes black and the black color "flows" into the main content page, sorry if this doesnt make sense, early AM here :D

Thanks again


For starters: don't use tables in a non-semantic manner, and don't use inline styles when you can avoid it.

You've got a list of links, so put your links in a list:

<ul>
  <li><a href="...">Link 1</a></li>
  <li><a href="...">Link 2</a></li>
  <li><a href="...">Link 3</a></li>
  ...
</ul>

The problem you're having is that you only put the class that produces the background color (menu1) on the first item in your table.

You should give your parent item a class or id instead:

<ul id="nav">...

And then give the entire nav a background color (You'll also have to remember to get rid of the default padding and margin on the nav):

#nav
{
  background-color: #000000;
  margin: 0;
  padding: 0;
}


You might check into css resets like here: http://meyerweb.com/eric/tools/css/reset/

Basically, browsers will default to have margins or padding between div elements or elements that have their own 'block' (h1, h2, and several others).

You'll need to set margin and padding levels to zero, as a starter.


Zounds!

Is this a solution? Certainly seems so!

Quick and dirty:

  • Float the menu left and give it 100px width;
  • Use a left margin for the content, do not float it;
  • Use background color on a container of both the menu and the content;
  • Realize how much trouble you're going to have if this was a problem already;
  • Persevere, that is to say DO NOT GIVE UP, no one was born knowing it! :)

The harder it is, the more you'll learn. Expect a lot of learning. :)

The HTML:

<h1 id="header"><a href="#"><img src="FancyHairLogo.png" alt="ZOMG PURTY HAIR" /></a></h1>
<div id="textContainer">
    <ul id="menu">
        <li><a href="#">Link 1</a></li>
        <li><a href="#">Link 2</a></li>
    </ul>
    <div id="content">
        <h2>WELCOME TO BLISS HAIR EXTENSIONS!</h2>
        <p>
            this is the homepage of bliss hair extebnsions, please check back soon as we are contionously updating the content on this page!
        </p>
        <p> etc ... </p>
    </div>
</div>

And the CSS:

body {
    background-color: #666;
}

#header {
    text-align: center;
    margin-bottom: 20px;
}

#header a img {
    border: dashed 1px gray;
}

#textContainer, #header * {
    background-color: black;
    color: white;
}

#menu {
    float: left;
    width: 100px;
}
#content {
    margin-left: 100px;
}

Issues

  • "The title's top will not line with the menu's top!"
    • Yes, because adjoining borders collapse and the bigger applies.
    • Use a css rule like content>h2:first-child { margin-top: 0px; } to quickly hack it away, but make sure to understand what is happening, it will save you braincells and time in the future.
0

精彩评论

暂无评论...
验证码 换一张
取 消