The problem of a child div extending beyond the boundaries of its parent div

I am searching for a layout similar to this, click here.

Here is the basic HTML code I have:

  #mainContent {
        margin:0;
        width:100%;
        height:600px;
        padding: 0 0 30px 0;
    }
    #mainContent #sidebar { /* sidebar inside #mainContent */
        float:left;
        width:220px;
        height:560px;
        margin:10px 10px 40px 10px;
        padding:10px 5px 10px 5px;
        background-color:#CCCCCC;
    }
    #mainContent #featContent {
        height:560px;
        margin:10px 10px 40px 260px;
        padding:10px 5px 10px 5px;
        background-color:#CCCCCC;
        overflow:auto;
    }
 <div id="mainContent">
    <div id="sidebar"></div>
    <div id="featContent"></div>
</div>



  

The issue lies in one of the div placements. The #featContent div seems to be extending beyond its parent #mainContent div and I cannot figure out why. You can view this problem on jsFiddle here. The margin of #featContent exceeds the boundaries of #mainContent.

Answer №2

Apply padding to the parent div element

#mainContent {
    margin:0;
    width:100%;
    height:auto;
    padding:10px 5px 40px 5px; background-color:red
}
#mainContent #sidebar { /* add styles for sidebar inside #mainContent */
    float:left;
    width:220px;
    height:560px;
    margin:10px 10px 40px 10px;
    background-color:#CCCCCC;
}
#mainContent #featContent {
    height:560px;  
    margin:10px 10px 40px 260px;
    background-color:#CCCCCC;
    overflow:auto;
}​

Check out the demo here http://jsfiddle.net/j4C7T/

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

Ways to rotate SVG images exclusively upon clicking

After experimenting with rotating SVG images on my navbar buttons, I encountered an issue. Whenever I click one button, all the images rotate simultaneously. Additionally, clicking elsewhere does not reset the images to their original positions. This is t ...

WordPress Ignoring PHP Generated Elements When Processing Divs

Whenever I attempt to utilize the get_date function, it seems to disregard all div elements and instead places itself right after the header, at the beginning of the <div class="entry-content">. <div class="entry-content"> May 16, ...

Adjust the size of a canvas using JavaFX in an FXML file

I am encountering an issue with resizing a canvas in Javafx while using scene builder and fxml. Currently, when the user clicks on the canvas, it turns black, but upon resizing the screen and clicking on the canvas again, only the original size of the canv ...

Learn the process of covering the entire screen with a video

I'm attempting to achieve this: IMG Below is the code snippet I've been using: <div class="container" id="containervideo"> <div id="video"> <div class="box iframe-box"> <div class="container"> ...

Wordpress is having issues running jQuery

I've developed a function inside js/custom.js. The purpose of this function is to arrange posts in my Wordpress site by applying a class called articleAlign. This class will enhance the spacing between the article title and its excerpt, but only when ...

Issue with the read more button inoperative for two specific paragraphs

Upon trying to implement 2 or more "Read More" buttons on my website for users to view snippets of content before downloading, I encountered an issue with the functionality only working on the first paragraph and not the subsequent ones. Despite ...

What is the best way to determine if a user is logged in on one tab but not on another tab within the same browser session?

GitHub has recently introduced a new functionality where if you are browsing a page as a guest in one tab and then log in from another tab, the tab where you are still a guest will show a specific message. This feature also functions in incognito or privat ...

Placing divs of varying heights in a circular formation with a specific radius

Recently, I've been attempting to generate a multitude of divs (referred to as bars) and position them in a way that forms a circle in the center. To clarify, here's an example where all bars share the same width and height. Check out the JSFi ...

Generating Dynamic DIV Elements in Angular 2

I am looking to dynamically generate divs in Angular 2 with Bootstrap classes based on data retrieved from a database. For instance, if I receive 6 categories from the database, I would like to display this as 3 rows with 2 columns each. How can I implemen ...

Solution to trigger CSS :hover to refresh following a transition (such as expanding a menu)

While there are existing discussions on this topic, I am presenting my query for two specific reasons: It introduces a potential alternative solution The demo code could be helpful to individuals looking to emulate a menu Following a CSS transition, the ...

Showing Variables in JavaScript

<!DOCTYPE HTML> <html> <body> <button onclick="question++">Increment</button> <script> function test() { var question = 0; } </script> </body> </html> Qu ...

In what way could the border exceed the dimensions of the div?

<head> <meta charset="UTF-8"> <title>Document</title> <style> #Tri{ width:0px; height:0px; border-top: 50px solid yellow; border-right:50px solid red; border-bottom:50px solid green; border-left:50px solid blue; } </style&g ...

Switching between divs using buttons

After researching examples and tutorials on HTML/CSS/jQuery, I was able to create a set of buttons that toggle content based on user interaction. However, I believe there must be a more efficient method of writing the code by using element identifiers or a ...

Dynamic text display using Bootstrap 3

My current struggle involves the implementation of Bootstrap's collapse class in my project. I am attempting to connect buttons with text located in a separate div in order to properly collapse and display it. While I can easily achieve this in a str ...

How can I ensure that all the text is always in lowercase in my Angular project?

Is there a way to ensure that when a user enters text into an input field to search for a chip, the text is always converted to lowercase before being processed? Currently, it seems possible for a user to create multiple chips with variations in capitaliza ...

Transformation of a double-row header

Click here to view the design - two-row header image I'm struggling with creating a header design that consists of two rows - the first row includes a centered logo and icons on the right side, while the second row contains the menu. Can someone guid ...

Tips for incorporating a sticky toast notification in the ready state of a CI web application

Can you help me with adding sticky toast notifications to my CodeIgniter site's home page? I've tried a few things but it doesn't seem to be working correctly. <div> <p> <span class="description">To show a success ...

What is the technical process behind conducting A/B testing at Optimizely?

I'm currently experimenting with Google Analytics and Content Experiments for A/B testing on my website, but I'm encountering some challenges in making it seamless. To utilize the Google API properly, a few steps need to be taken. Firstly, I nee ...

Caution: The `className` property does not align with Material UI css which may cause issues upon reload

https://i.stack.imgur.com/MxAiY.png If you are facing the error/missing CSS, check out this video for a visual representation. While older versions of similar questions exist on Stack Overflow such as React + Material-UI - Warning: Prop className did not ...

Twig: A guide to showcasing HTML content within block titles

Within my Symfony2 project, I am utilizing various twig templates. One of these templates contains a block labeled title. {% block title %}{{ announcement.title }}{% endblock %} The issue arises when the variable {{ announcement.title }} contains HTML ta ...