[HTML/CSS] 2-Column Layout

  • CSS

Es gibt 5 Antworten in diesem Thema. Der letzte Beitrag () ist von Link.

    [HTML/CSS] 2-Column Layout

    Guten Morgen!

    Ich probiere mich seit gestern an einem zwei-Spalten Layout, kriege jedoch die Sidebar nicht an der Höhe des Contents orientiert.
    Insgesamt habe ich das Gefühl, das der Code mega unsauber geschrieben ist. Ich würde mich freuen, wenn mir jemand Tipps zur Lösung des Problems geben könnte und eventuell Insgesamt Verbesserungsvorschläge für den Code nennt, damit ich mich da etwas verbessern kann und die Fehler aufgezeigt bekomme.

    Im Anhang befindet sich ein Bild, wie das ganze derzeit aussieht.

    HTML:
    Spoiler anzeigen

    HTML-Quellcode

    1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <title>Startseite</title>
    5. <meta charset="UTF-8" />
    6. <meta name="description" content="" />
    7. <meta name="author" content="" />
    8. <meta name="keywords" content="" />
    9. <link href="styles/style.css" type="text/css" rel="stylesheet" />
    10. <link href="favicon.ico" type="image/x-icon" rel="shortcut icon" />
    11. </head>
    12. <body>
    13. <div id="container">
    14. <div id="head">
    15. <img class="logo" src="images/logo.jpg" />
    16. <ul>
    17. <li><a href="#">Startseite</a></li>
    18. <li><a href="#">&Uuml;ber uns</a></li>
    19. <li><a href="#">Service</a></li>
    20. <li><a href="#">Kontakt</a></li>
    21. <li><a href="#">Impressum</a></li>
    22. </ul>
    23. </div>
    24. <div id="content">
    25. <h1>Herzlich Willkommen</h1>
    26. <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
    27. </div>
    28. <div id="sidebar">
    29. Test
    30. </div>
    31. <div id="footer_irl">
    32. Test
    33. </div>
    34. </div>
    35. </body>
    36. </html>


    CSS:
    Spoiler anzeigen

    HTML-Quellcode

    1. body
    2. {
    3. background-color: #C1C1C1;
    4. }
    5. #container {
    6. width: 1200px;
    7. margin: 0 auto;
    8. }
    9. #head {
    10. width: 1200px;
    11. height: 180px;
    12. background-color: white;
    13. padding-bottom: 10px;
    14. margin-bottom: 10px;
    15. }
    16. #head ul {
    17. height: 20px;
    18. float: right;
    19. padding-top: 140px;
    20. padding-right: 20px;
    21. list-style-type: none;
    22. }
    23. #head li {
    24. float: left;
    25. margin-left: 20px;
    26. font-family: Georgia, Times, serif;
    27. font-size: 1.5em;
    28. }
    29. #head a {
    30. text-decoration: none;
    31. color: #808080;
    32. }
    33. #head img.logo {
    34. float: left;
    35. padding-top: 15px;
    36. padding-left: 20px;
    37. }
    38. #content
    39. {
    40. float: left;
    41. width: 900px;
    42. background-color: white;
    43. height: 100%;
    44. padding-left: 10px;
    45. padding-right: 10px;
    46. }
    47. #content h1
    48. {
    49. font-family: Georgia, Times, serif;
    50. font-size: 1.5em;
    51. }
    52. #sidebar
    53. {
    54. height: 100%;
    55. margin-bottom: 20px;
    56. float: right;
    57. width: 265px;
    58. padding-left: 10px;
    59. padding-top: 10px;
    60. padding-right: 5px;
    61. padding-bottom: 10px;
    62. color: white;
    63. background-color: black;
    64. }
    65. #footer_irl
    66. {
    67. margin-top: 10px;
    68. float: left;
    69. width: 1180px;
    70. background-color: #747474;
    71. height: auto;
    72. padding-top: 10px;
    73. padding-bottom: 10px;
    74. padding-left: 10px;
    75. padding-right: 10px;
    76. }
    77. #footer_irl p
    78. {
    79. font-family: Georgia, Times, serif;
    80. font-size: 1em;
    81. text-align: center;
    82. }


    Ich freue mich auf eure Verbesserungsvorschläge!

    VG
    Bilder
    • Bild_IST.JPG

      86,59 kB, 1.261×447, 142 mal angesehen
    Hej @Neoner

    Benutze doch einfach display: table; und display: table-cell;:

    HTML-Quellcode

    HTML-Quellcode

    1. <div class="cbase">
    2. <div class="left">
    3. <!-- Content -->
    4. </div>
    5. <div class="right">
    6. <!-- Content -->
    7. </div>
    8. </div>


    CSS-Quellcode

    Quellcode

    1. div.cbase {
    2. display: table;
    3. }
    4. div.left {
    5. display: table-cell;
    6. width: 900px;
    7. }
    8. div.right {
    9. display: table-cell;
    10. width: 265px;
    11. }



    Grüße
    Väinämö
    Hallo @Vainamo V :)

    Vielen Dank für den Tipp!
    Leider bekomme ich das ganze nicht richtug umgesetzt, die DIV's sind jetzt zwar beide gleich lang, ich bekomme die jetzt aber nicht mehr formatiert.

    Ich habe die Floats entsprechend rausgenommen, da ich das gefühl hatte, dass das "display: table-cell" keine Wirkung hat.

    HTML-Quellcode

    1. #container {
    2. width: 1200px;
    3. margin: 0 auto;
    4. display: table;
    5. }
    6. #head {
    7. width: 1200px;
    8. height: 180px;
    9. background-color: white;
    10. padding-bottom: 10px;
    11. margin-bottom: 10px;
    12. }
    13. #content
    14. {
    15. display: table-cell;
    16. width: 900px;
    17. background-color: white;
    18. height: auto;
    19. }
    20. #sidebar
    21. {
    22. display: table-cell;
    23. width: 265px;
    24. background-color: black;
    25. }


    Am HTML-Code habe ich nichts verändert, ein Bild vom aktuellen Aussehen ist als Dateianhang angefügt.
    Hast du eine Idee wie ich die Formatierung ordentlich hinbekomme?

    Beste Grüße,
    Neoner
    Bilder
    • Bild_IST.JPG

      84,43 kB, 1.768×792, 148 mal angesehen
    Vielen Dank, ich dachte es reicht, wenn ich es in den DIV "Container" packe.

    Sobald ich die DIVs "Content" und "Sidebar" alleine in den Container cbase mit dem Inhalt "display: table" packe, funktioniert es einwandfrei!

    Vielen Herzlichen Dank! :)
    Bootstrap bringt dafür doch ein Grid-Layout. Einfach die 3 Links in den Head-Bereich deiner Seite packen und fertig. Anschließend noch hier nachgucken wie es zu verwenden ist. Dann hast du deinen Shit auch gleich responsive.

    Link :thumbup:
    Hello World