The art of CSS layout and scrolling

I am attempting to create a layout with a fixed left menu and a fixed right banner that stay in place while the center panel scrolls text. The banner needs to be on top of the center panel due to its size, and the color scheme consists of white text on a black background, except for the menu which uses its own color scheme.

As someone new to CSS, I may have already made some mistakes. Currently, the top right banner stays fixed when scrolling, but the text overlaps it and the top left menu disappears off the screen.

JS Fiddle


<head>
<style>
#container {
    width:90%;
    height 100%;
    background-color:Black;
    margin: 0 auto;
    text- align: left;
}
#banner {
    float: right;
    background-color:black;
    width:40%;
    top:1;
    right:1;
    position:fixed
}
#sidebarmenu {
    float: left;
    width: 10%;
    background-color:Black;
    padding: 15px 10px 15px 20px;
    top:1;
    left:1;
    position:fixed
}
#mainContent {
    background-color: Black;
    color:White;
    position: absolute;
    left: 120px;
    width: 50%;
    top:220;
    margin: 0 0 0 15%;
}
body {
    color: white;
    background-color: black;
}
.sidebarmenu ul {
    margin: 0;
    padding: 0;
    list-style-type: none;
    font: bold 13px Verdana;
    width: 180px;
    border-bottom: 1px solid #ccc;
}
.sidebarmenu ul li a {
    display: block;
    overflow: auto;
    color: black;
    text-decoration: none;
    padding: 6px;
    border-bottom: 1px solid #778;
    border-right: 1px solid #778;
}
.sidebarmenu ul li a:link, .sidebarmenu ul li a:visited, .sidebarmenu ul li a:active {
    background-color: #c0c0c0;
}
.sidebarmenu ul li a:visited {
    color: white;
}
.sidebarmenu ul li a:hover {
    background-color: black;
    color:red;
}

</style>
</head>
<body>
<div id="container">
<div id="banner" ><img style="float:right" alt="logo text" src="/banner.png" /></div>
<div id="mainContent" >TEXT</div>
<div class="sidebarmenu">
<ul id="sidebarmenu1">
<li><a href="index.html">Home</a></li>
<li><a href="1.html">Info</a></li>
<li><a href="11.php">Contact Us</a></li>
<li><a href="2.php">Page 2</a></li>
<li><a href="3.php">Page 3</a></li>
<li><a href="4.php">Page 4</a></li>
<li><a href="5.php">Page 5</a></li>
<li><a href="6.php">Page 6</a></li>
</ul>
</div>
</div>
</body>

Any help, comments, or guidance on what I should focus on learning or looking at would be greatly appreciated.

Answer №1

Wow! So many adjustments needed in your code, it was like a puzzle to fix every line. Proper site architecture is crucial when positioning elements. Organization plays a vital role in front-end development.

Check out my DEMO for a reworked version!

Answer №2

Initially, the usage of position: absolute; or position: fixed; eliminates the need for float and margin.

Furthermore, whenever utilizing top: x;, left: x;, right: x;, or bottom: x;, it is essential to include a size unit in the value, like changing top:1; to top: 1px;

If I interpreted your provided css correctly, implementing the following code may bring you closer to your desired outcome:

html,body{ margin: 0; padding: 0; color: #fff; background: #000; height: 100%; width: 100%; overflow: hidden; }
#container { width:100%; height: 100%; text-align: left; overflow: auto; border: 1px red solid;} 
#mainContent { width: 90%; color: #fff; margin: 0 auto; }
#banner { background-color: #000; width:40%; top:1px; right:1px; position:fixed; }
#sidebarmenu { width: 10%; background: #000; padding: 15px 10px 15px 20px;top:1px;left:1px;position:fixed; }

Check out this jsfiddle demonstration I created to visualize the effects of this css: http://jsfiddle.net/beYuC/

IMPORTANT: Note the setting of 100% height for both html and body. This is crucial as failure to specify heights for these elements will result in other page elements intended to be 100% height being compressed.

REMINDER: Explore this website and its CSS layout showcasing an exemplary content container and sidebar menu with 100% height:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Expand Elements to occupy entire width

My CSS skills are still in the early stages. I haven't delved too deeply into it. I have a query regarding how to achieve full width for an element. I've included my code below, but the basic approach I tried using 'width: 100%' didn&a ...

Methods to disregard class prefix in css document

When I inspect elements in the Chrome console, I notice styles applied to certain divs/buttons like this: /* Sample Chrome browser styles */ .ItemClass1-0-3-171.ItemClass2-0-3-173: { background-color: "red" } I'm wondering how I can def ...

Issue with spacing between rows of inline-block elements and adjacent rows

Just to clarify, this is not a table. I used "row" as a placeholder term. My issue involves a set of inline-block elements with a gap below them when compared to another element on the page. This is different from the space between the inline elements the ...

Adjusting CSS styling based on screen orientation changes when resizing a browser window on a

I'm uncertain about the functionality on desktop screens when it comes to resizing the browser window. My understanding is that changing the orientation should occur naturally when the height surpasses the width and vice versa after resizing. However ...

What is the best way to apply an outer border to a table using CKEDITOR?

Is there a way to only add an outer border to an HTML table in CKEDITOR? I've attempted to remove the inner borders using the advanced options in CKEDITOR, but it doesn't seem to be working. <table border="1" cellpadding="1" cellspacing="1" ...

Struggling to ensure buttons on my page respond and resize properly alongside the other elements

Despite making most of this page responsive, I'm having trouble getting the two buttons to scale appropriately. They are utilizing javascript for a mouseover effect, and I suspect that might be causing some issues. Ideally, I would like the images to ...

Getting the card height in Bootstrap Vue: Tips and tricks

Utilizing the card component in bootstrap-vue is my current project. One challenge I'm facing is determining the height of the card post-rendering, as the height varies depending on the amount of text within. Can you provide a possible solution? ...

Ways to prevent the :link style being applied to every link

Is there a way to apply this CSS styling to only one specific link and not all the links on my page? Here is the CSS code that is currently being applied to all links: a:visited { font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; font-size: 14px ...

What is the reason behind an element occupying space despite having a height of 0?

Check out this demo for reference: https://codepen.io/jchi2241/pen/dEzMZo?editors=1100 In my current setup, I use a max-height of 0 to hide the <ul> element when the related input is unchecked. When checked, the max-height is set to 10em to reveal t ...

Responsive flex elements in a single line

I am facing a challenge with five divs that I want to display inline and make them responsive. The issue is that when the window size changes, they end up getting squished together instead of breaking into a new row as desired. I have tried various methods ...

Developing HTML5 animation by utilizing sprite sheets

Struggling to create an engaging canvas animation with the image provided in the link below. Please take a look at https://i.stack.imgur.com/Pv2sI.jpg I'm attempting to run this sprite sheet image for a normal animation, but unfortunately, I seem to ...

Ways to add a CSS class to an ID that immediately follows

I've been working on an editable table using the HTML5 attribute contenteditable. Everything was going smoothly until I had an idea to highlight the cell that was just updated by adding a class called alert-danger from Bootstrap. Once a cell is succe ...

Trick to Use Custom Fonts in Email Clients with CSS and HTML

With certain email clients not supporting web fonts, most solutions involve using a backup font like Arial that is compatible with the client. However, the issue is that the default web font is needed specifically because it is a barcode font. Are there a ...

Utilizing the CSS grid framework to efficiently create repetitive rows and columns in code

When I work with CSS frameworks like Bootstrap or Materialize, I often find myself repeatedly typing the same HTML code: <div class="row"> <div class="col s12"> <!-- Some text/ a button / something --> </div> </d ...

Executing animation after the completion of a transition

Is there a way to synchronize the bounce animation with the scaling of an object, so that it appears smooth and fluid? I've tried using the animation delay property along with the transition delay property, but they don't seem to align correctly. ...

Creating an Instagram-style frame effect for your HTML page using CSS

https://i.sstatic.net/SnkO7.jpg Trying to figure out how to align images like in the picture above. Here's the code I've been working with: <html> <head> <style> .main { width: 634px; height: 634px; } .img1 { width ...

Is there a way to modify the CSS or add custom styling within an iframe form?

Currently I am working on the following page: , where an embedded javascript form called infusionsoft (iframe form) needs to be made responsive at the request of my client. I'm wondering if there is a way to override the css or inject custom styles i ...

Inquiring about the best method to determine the intersection point between two lines in Draw i.o

Can someone please explain how to find the coordinate point where two lines intersect in draw i.o? I am looking for a Javascript function to solve this issue and get the coordinate of the point only. For example: ...

Get a Blob as a PNG File

Hope you had a wonderful Christmas holiday! Just to clarify, I am new to JS and may make some unconventional attempts in trying to download my Blob in PNG format. I am facing an issue with exporting all the visual content of a DIV in either PDF or image ...

Text stretched to its fullest height and rotated using the transform property

check out the demo Here is a demonstration of HTML elements: <div class="controller"> <div><a href="#buttton-1">Special Offer</a></div> </div> And here is the styled CSS for the demo: .controller{ width: 55px; ...