The margins on a div element are not displaying correctly

I am currently conducting experiments with a basic fluid grid that consists of a sidebar and a main area. However, I have encountered an issue where setting margins within a div in the main area does not behave as expected, while it works fine within the sidebar. You can view the Jsfiddle demonstration here: http://jsfiddle.net/swayziak/vVJeV/

HTML:

<section class="sidebar">
    <div class="test"> bla bla bla bla bla ba balalalalal </div>
</section>

<section class="mainarea">
    <div class="test"> bla bla bla bla bla ba balalalalal </div>
 </section> 

CSS

.sidebar {
   position: fixed;
   z-index: 100;
   top: 0;
   left: 0;
   width: 25%;
   height: 100%;
   border-right: 1px solid #E3E3E3;
   background: #FFF;
 }

.mainarea {     
   float: right;
   z-index: 100;
   top: 0;
   left: 0;
   width: 75%;
   height: 100%;
 }

.test {    
   margin-left: 24px;
 }

The issue might be related to specific parts of the .sidebar and .mainarea CSS styling, but I am unsure which one is causing the problem.

Thank you for your assistance.

Answer №1

Check out the answer provided here: Click for example.

The issue you were facing was with the sidebar taking up 25% and the main area 75%. With a border-right of 1px, it pushed the total percentage to 101% instead of 100%.

To resolve this, I made the following adjustments:

.sidebar {
    float:left; /* Added */
    width:24%; /* Changed from 25 to 24 */
}

If you need further assistance or have more questions, feel free to let me know.

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

There are no errors with PHP and it fails to insert any entries into the database

I am struggling to save secq (secret question) and seca (secret answer) in the database. Even though I don't encounter any errors during the registration process, the values of the variables are successfully passed through POST when echoed. Despite ...

Can anyone shed some light on why the CSS code is not functioning properly within my HTML file?

My CSS doesn't seem to be working in my HTML. I have linked it correctly, but it's not displaying properly - even showing empty in the CSS tab of Chrome Inspector. The links are there, so I'm not sure why it's not functioning correctly. ...

What technique does Wordpress use to achieve this understated 3D appearance?

This unique effect that I've come across on various websites is quite subtle. I'm curious about how it achieves this effect. It seems like more than just a border, but also involves the empty space. ...

Getting the value from a label and then setting it as the innerHTML of document.getElementById('label')

I have successfully implemented a JavaScript Google Maps functionality, but now I am facing an issue where I need to retrieve the type of HTML control and set it to JavaScript. Specifically, when attempting to extract the value from lblTitle, it is not f ...

Utilizing a Bootstrap grid system (or an IE-compatible CSS grid) to align elements on the provided

Looking for suggestions on achieving the following layout without using CSS grid, either with Bootstrap or IE compatible CSS grid. On large screens: Head and body stack on the left, with an image on the right covering the height of both. [&mdash ...

Exploring the ins and outs of webpage loading speed

I am working on writing JavaScript code that includes a button to open a webpage of my choice. I now want to understand how to detect when the page I called is finished loading. Any suggestions or ideas on this topic? I apologize if my explanation was no ...

Setting up Jplayer as an audio player: A step-by-step guide

I am looking to incorporate a Jplayer audio player into my project, but I am struggling to find any documentation or resources that provide instructions on what components to include and how to set it up. If anyone has experience with using the Jplayer au ...

"An issue has been identified with the page-break-* feature not functioning properly on both Chrome and

Despite the abundance of questions on this topic, I have yet to find a viable solution. Here is my HTML code: <div class="row"> <div class="col-xs-12"> <div class="row print-break"> <div class="col-xs-8 col-xs-offset ...

Unsure of the process for extracting elements from a dynamically loading webpage with selenium

Currently, I am in the process of scraping reviews and skin types from Sephora. However, I have encountered a challenge with extracting elements from the page. Sephora.com dynamically loads reviews as you scroll down the page, prompting me to switch from B ...

Activate Input by Clicking on Label in Internet Explorer version 8

I am trying to implement a widget in JQuery colorbox that allows users to load files. My approach involves using an input tag with type='file' and styling it with visibility:hidden. Additionally, I have created two labels that are styled like but ...

Navigating nested loops within multidimensional arrays

Currently, I am experimenting with nested loops to search through nested arrays in order to find a specific value called "codItem". Below is a test model for the array (as I do not have access to the original fetch request on weekends): let teste = [{ it ...

Display a list in thumbnail format on Wordpress

On my website, , the homepage thumbnail post does not display the text in a bulleted list like it does when I enter the post directly at . Can you explain why this is happening? I want to note that the theme admin supports Custom CSS which allows me to ad ...

Incorporate content from HTML into various sections

Is there a way to dynamically extract the h4 headers and the first sentence from each section of this HTML, and then add them to a new div? function summarize() { let headings = document.getElementsByTagName("h4"); // Get all H4 elements let newsText = do ...

In need of a solution for this peculiar problem with an html table and css. Let's

Encountering an unusual issue with my table content .table { position:absolute; top:12px; left:3px; width:87px; height:74px; } .table tr { vertical-align:middle; } .table td { text-align:center; padding:1px;color:#000000; font-siz ...

Tips for Splitting Navigation Bar in HTML and CSS

I am facing an issue with my webpage's navigation bar, as I am unable to divide it into two parts - with some text on the left side and some on the right side. I attempted to use code from a specific reference: http://www.w3schools.com/css/css_navbar. ...

What is the best way to align content within a div to match the alignment of content outside of it using bootstrap?

I have a section that stretches across the width of the screen, but the text inside is contained within a container and aligns correctly. Below that section is a two-column layout, and I'm trying to align the text in the left column with the text abo ...

Tips for optimizing Markdown to HTML conversion for improved SEO in Pagedown editor

Through the pagedown editor, I am transforming markdown into HTML using the method below: <div id="question_div" class="post_text"> </div> <script type="text/javascript"> $(document).ready(function() { var q_converter = new Markdo ...

Determining the correctness of a radio group tick pattern using jQuery

I am working on a form that has 3 questions with radio groups. The goal is to show a hidden div after all 3 radio boxes are checked. The condition for the div to appear is if the first question is answered "NO" and the remaining 2 questions are answered ...

Steps to display the "col-md-6" div upon hovering over list items in a different div

I have been trying to make a hover action work in my HTML document. I've managed to get it to work only when the description is a child of the li tag, but I want the description to be displayed as a separate div. <div class="row"> ...

Creating a custom theme for a tree panel in Ext JS 4

I'm looking to start customizing a Sencha 4 Tree panel, adjusting elements like text size and background colors. So far, I haven't been able to figure out the right approach, whether it's through viewConfig or some other method. Here's ...