Search code examples
htmlstylesheet

div tag not acting right


I'm trying to make a website looking like the example at "Using tag elements" from here http://www.w3schools.com/html/html_layout.asp but my <div> doesn't show next to the menu bar, and I can't see why. my code is here:

< head>  
  < style>  
div, p {  
    margin: 0px;  
    padding: 0px;  
}  
< /style>  
< /head>  
< body>  
< a href="#" onclick="window.print();return false;">Udskriv< /a>  
< div id="container" style="width:500px">  
< div id="menu" style="background-color:red;height:100px;width:10%;float;left;">
< a href="forside.html">Forside</a><br>
< a href="kalender.html">Kalender</a><br>
< a href="hvem_er_vi.html">Hvem er vi</a><br>
< a href="nyheder.html">Nyheder</a><br>
< a href="meetings.html">Møder</a><br>
< a href="aktiviteter.html">Aktiviteter</a><br>
< a href="presse.html">Presse</a><br>
< a href="kontakt.html">Kontakt</a><br>
< a href="links.html">Links</a>
< /div>
< div id="content" style="height:200px;width:200px;float;left;">text1< /div>  
< p>text2< /p>  
< /div>  
< /body>

I can't see why my div-tag with text1 appears below menu bar instead of right of it, it has the required space (and more), including it had no margin or padding


Solution

  • remove height defiend for menu bar to set dynamic height relative to content and so

    <div id="menu" style="background-color:red;float:left;width:10%"> 
    

    you missed close <a tags

    I have edited your code :

    <a href="#" onclick="window.print();return false;">Udskriv</a>
    
    <div id="container" style="width:100%">
        <div id="menu" style="background-color:red;float:left;width:10%"> 
            <a href="forside.html">Forside</a>
            <a href="kalender.html">Kalender</a>
            <a href="hvem_er_vi.html">Hvem er vi</a>
            <a href="nyheder.html">Nyheder</a>
            <a href="meetings.html">Møder</a>
            <a href="aktiviteter.html">Aktiviteter</a>
            <a href="presse.html">Presse</a>
            <a href="kontakt.html">Kontakt</a>
            <a href="links.html">Links </a>
        </div> 
        <div id="content" style="height:200px;width:200px;float:left;">text1</div>
        <p>text2</p>
    </div>
    

    note that float;right is not correct right syntax of float is : float:right