Styling boxes within a container using CSS

I'm encountering an issue with my first website development project! The "leftSidebar" and "rightSidebar" boxes are meant to be positioned alongside the main content in the center, but they seem to extend beyond the body boundaries without being contained within it. Can you help me troubleshoot this problem so that the sidebars align correctly with the middle content?

Furthermore, these sidebars are overflowing downwards so much that when I scroll, a white background appears as the browser's background ends. Would you mind testing this issue with your own background to see if you encounter the same problem?

I would greatly appreciate any assistance in resolving this quickly as I'm getting quite frustrated at this point!

Thank you.


                
                body {
                    background-image: url(wp1.jpg);
                    background-size: 100%;
                    background-repeat: no-repeat;
                    color: white;
                }

                .body {
                    width: 70%;
                    border: 1px solid white;
                    margin: 5% auto;
                    clear: both;
                }

                a {
                    text-decoration: none;
                }

                nav ul li {
                    list-style-type: none;
                }

                .navHeader nav ul li {
                    float: left;
                    display: inline;
                    margin: 0 auto;
                }

                .navHeader nav {
                    border-radius: 5px;
                    border: 1px dashed white;
                    height: 50px;
                }

                .navHeader {
                    background-color: black;
                }

                .leftSidebar { 
                    float: left;
                    border: 1px white solid;
                    border-radius: 2px;
                    margin: 2% 0 2% 2%;
                    width: 20%;
                }
                
                .rightSidebar { 
                    float: right;
                    border: 1px white solid;
                    border-radius: 2px;
                    margin: 2% 0 2% 2%;
                    width: 20%;
                }
                
                .allContent {
                    background-color: black;
                    width: 60%;
                    text-align: center;
                    margin: 0 auto;
                }
            

          
                <body class="body">

                <header class="navHeader">
                <nav><ul>
                  <li><a href="#">Home</a></li>
                  <li><a href="#">News</a></li>
                  <li><a href="#">Programming</a></li>
                  <li><a href="#">Downloads</a></li>
                  <li><a href="#">Contact</a></li>
                </nav></ul>
                </header>


                <aside class="leftSidebar">
                <content>
                <h3> Sidebar Left Title </h3>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
                Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
                </content>
                </aside>


 standard HTML tags here
            

Answer №1

Your code has several issues that need attention. Firstly, it is not recommended to set an explicit width for the <body> element unless you fully understand the implications. It's better to let the browsers handle this and use a wrapper <div> instead.

Secondly, when using float-based layouts, all columns should be floated in the same direction to avoid issues like unfloated boxes flowing around floated elements. Consider using a flexbox-based layout if targeting modern browsers.

Thirdly, the <content> tag is meant for Shadow DOM and is not a standard HTML tag. Additionally, it has been deprecated. Use a <div> element as an alternative.

While these changes may not directly solve your issue, they will guide you in the right direction towards improving your code.

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

Having trouble with downloading a PDF file on a React application's hosting platform

The issue with downloading the PDF file persists on an AWS hosting environment. import React, {Component} from 'react'; import aa from "../media/AA.pdf"; export default class FileDownloader extends Component { render() { re ...

The Datalist HTML does not function properly with line breaks

<input type="text" list="req" name="req" style="width:350px; height:70px;"><datalist id="req"> <option value=""><option> <?php while($getreq = $requirements->fetch_array()){ ?> <option><?=$req = preg_r ...

What is the process for updating the label name when a file is chosen?

Check out this HTML code snippet: <input type="file" class="custom-file-input" accept="image/*" onchange="loadFile(event)" id="customFile"> <label class="custom-file-label" id="chan ...

Alter the browser's URI without having to reload the page

Is there a way to change the browser URL (or URI) without refreshing the page using HTML5 and HTML5Shiv for IE? For example, if I am currently on http://www.example.com but want to transition to http://www.example.com/4f6gt without the need for a full pa ...

The HTML code for the base64 image conversion failed to load

I am facing an issue with handling HTML strings containing base64 image tags generated by Summernote. I have a process in place where I load the image elements, convert them to image blobs, upload them to get the image-url, and then update the src attribut ...

Steps for automatically collapsing the sidebar on mobile devices when the page loads

I recently purchased the Lexa bootstrap admin dashboard from Envato Elements, but I'm encountering a problem. When viewing it on mobile, the sidebar does not collapse by default. The Metis Menu is being used for the sidebar, and clicking on the toggle ...

What is the best way to override a custom class-li element within another class-li?

I've just started learning HTML5 and CSS3, and I've encountered a challenge: Here is the code I have written so far: .custom-list ol { counter-reset: item; padding-left: 10px; } .custom-list li { display: block; } .custom-l ...

The tooltip for the svg icon is not appearing

Is there a way to apply the tooltip from this tutorial to an SVG info icon like in this codepen? I tried adding the classes to the svg, but the tooltip doesn't show. How can I make the tooltip work on the SVG info icon? Thank you. body { backgrou ...

What is the best way to keep track of dynamically inserted input fields?

I've created a form with two text boxes: one for entering people's "name" and another for their "surname." By clicking on the page, you can add additional pairs of text boxes for both "name" and "surname," allowing users to input as many pairs as ...

Using bootstrap-vue sticky columns without specifying a column variant is easier than you think

Let's cut to the chase with an example I created using bootstrap-vue's documentation to help clarify the issue: <template> <div> <div class="mb-2"> <b-form-checkbox v-model="stickyHeader" inline>Sticky header& ...

Transferring an object from one inventory to another

I'm in the process of developing a task manager that enables users to add and remove tasks. I am also working on enabling the ability for users to transfer tasks from one list to another. The current code I have written doesn't seem to be functio ...

A guide on using key arrows in JavaScript to navigate and focus on elements

When working on my HTML project, I have a list of elements that I want to be able to select using the arrow keys. I've included my code here for reference: [http://jsfiddle.net/T8S7c/] What I'm trying to achieve is when the arrow keys are press ...

Responsive design issues with Bootstrap 3 box layout

I am currently working on creating a bootstrap4 layout that includes three boxes arranged side by side on a wide screen. However, my goal is to ensure that if the screen size decreases, the red and green boxes always stay adjacent to each other while the b ...

Add elements to a ul element using JavaScript and make the changes permanent

Managing a dashboard website with multiple div elements can be quite tedious, especially when daily updates are required. Manually editing the HTML code is inefficient and time-consuming. Each div contains a ul element where new li items need to be added ...

The div is not completely encased by the fieldset

I have utilized fieldset to generate a titled border around a div. Here is the code snippet: <div class="form-group col-xs-12"> <fieldset class="field_set col-xs-12"> <legend style="font-weight:bold;font-size:20px"> ...

Showing the URL beyond the search bar: A Guide using PHP, JavaScript, and HTML

How can I display the URL link outside the search box instead of opening a new page with the search result? I want to show the full URL (https://www.php.net.) below the search box, not within the search results. I only want to see the URL, not the contents ...

Having difficulty loading themes in AngularJS Material

I have added Angular (1) Material (v.1.1.5) to my Visual Studio project using NuGet and followed their instructions for referencing it: <script src="scripts/angular.min.js"></script> <script src="scripts/angular-route.min.js"></script ...

When using the :hover pseudo class, Chrome disregards the overflow hidden style change

In my design, there is a circular div (border-radius: 50%) that includes two smaller divs transformed to look like segments of a circle. To achieve this effect, I have set overflow: hidden on the parent container (the outer circle): I am trying to change ...

How can we develop an AJAX chat with enhanced scrolling capabilities?

Could someone provide me with some examples on how to achieve this task? I already have some HTML code: <div id="chatDisplay"> </div> <input type="text" id="message" /><input type="button" id="send" value="Send" /> Next, I have so ...

Tips for customizing the scrollbar design in iOS Safari

Task at hand requires me to customize the scrollbar style on my HTML page. Below is the CSS code I am using: .txt_Content::-webkit-scrollbar { width:5px; border-radius:4px; } .txt_Content::-webkit-scrollbar-button { display: none; } .txt_Co ...