The parent div will not accommodate two nested divs

I'm having an issue with two divs inside a parent div not being contained within the container when I inspect the page, even though I've wrapped the div around the other 2 divs.

My goal is to apply attributes to the parent div instead of each individual div. Any suggestions?

<!DOCTYPE html>
    <head>
    <title>Lavu Explore</title>
        <link rel="stylesheet" type="text/css" href="styles_sample.css">
    </head> 
    <body>
        <div id="sell_section">
            <h2>Sell, Manage, & Market in one easy system</h2>
            <hr class="hr_1">
            <div class="box1">
                <img id ="terminal_img" src="http://i.imgur.com/D5T6lY1.png">
            </div>
            <div class="box1">
                <p style="text-align:left">Choosing a new Point of Sale (POS) is an opportunity. Lavu   is not just accepting payments - Lavu is business management on the iPad. Upgrade your business with the Cloud POS system that was developed specifically for the restaurant / hospitality industry. Lavu has the tools you need to improve efficiency and the bottom line. Love your business.</p>
            </div>

        </div>
     </body>
</html>

styles_sample.css

html {
    box-sizing: border-box;
}


*, *:before, *:after {
    box-sizing: inherit;
}

body {
    margin: auto;
    position: relative;
    overflow: auto;
    padding: 0 5%;
    max-width: 990px;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

h2 {
    text-align: center;
    font-family: DIN;
    font-size: 40px;
    color: #8b8b8b;
    text-align: center;
    width: 100%;
    font-weight: normal;
}

p {
    font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
    color: #8b8b8b;
    font-size: 16px;
    line-height: 150%;
} 

.hr_1 {
    position: relative;
    padding: 0;
    margin: 2% auto;
    height: 0;
    width: 400px;
    max-height: 0;
    font-size: 1px;
    line-height: 0;
    clear: both;
    border: none;
    border-top: 1px solid #aecd37;
    border-bottom: 1px solid #aecd37;
}

.box1 {
    width: 50%;
    min-width: 50%;
    position: relative;
    min-height: 1px;
}

@media (min-width: 830px) {
    .box1 {
        float: left;
    }
}

@media (max-width: 830px) {
    .box1 {
        width: 100%;
    }
}

Answer №1

Make sure you include the html start tag following your doctype declaration, as shown below:

<!doctype html>
<html>
<head>
...
</head>
<body>
...
</body>
</html>

Answer №2

I agree with Johnny's response, and it seems like there is a small issue with the markup:

Your CSS styles are targeting the .hr_1 element, but it looks like you intended them for the #sell_section - which is actually the ID of the surrounding div.

Answer №3

It seems like there is some confusion regarding your specific requirements. From what I gather, you may be looking to add a border or background-color to the #sell_section DIV. Are you having trouble applying these styles consistently across different sizes? If that's the case, it could be because of the floating of your child/nested DIVs. Understanding the concept of Floating can be challenging at first, as it requires practice and knowledge to grasp fully.

Here's a brief explanation of how floating works:

When an element is floated, it is removed from the normal document flow.

What does this entail? Let's consider this structure:

<div class="outer">
     <div class="inner">inner</div>
     <div class="inner">inner</div>
</div>

and the following CSS styles:

.outer {
     background-color: red;
}
.inner {
     float: left;
     width: 50%;
}

In this scenario, the background color of .outer would not be visible since the floated child DIVs don't occupy any space within their parent DIV. However, other elements in the parent DIV (whether floated or not) will be affected.

The solution? One common approach is using clearfix. Applying this technique to the container element containing floated items will make them behave as if they were not floated and occupied space.

Answer №4

After some troubleshooting, I finally discovered the solution to my issue. It turns out that floated elements don't actually occupy any space within a div. To fix this, I simply applied overflow:auto to my containers, and voila! The problem was resolved effortlessly. With this fix in place, I can now confidently add borders and backgrounds to my divs without any concerns about their sizing within the container.

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

How to apply an icon image using the background property in CSS in Vue 3

Need help setting background image from the public folder |_public | |_images | |_icon.png |_src |_components |_TheHeader.vue I'm having difficulty trying to set an image as a background in TheHeader.vue using CSS, but the image is located in ...

Breaking apart a pipe-separated text and sending it through a JavaScript function

CSS: <div class="pageEdit" value="Update|1234567|CLOTHES=5678~-9876543?|5678"> <a href="https://host:controller">Update</a> </div> Trying to retrieve the data within the div and pass it into a JavaScr ...

Is there a way to modify the text within a hyperlink using jQuery?

Here is the link HTML code snippet: <a href="#" onclick="run(1); return false;" class="link" title="Remove item">[x]</a> I am looking to modify this using jQuery to display like this: <a href="#" onclick="run(1); return false;" class= ...

Safari's problem with CSS transitions

This issue is specific to Safari, as it has been tested and works fine in Chrome, Opera, and Firefox. Upon hovering over a certain div (1), a child div (2) slides out by adjusting the left property. However, the child elements (buttons) within the second ...

Sending simple form information through AJAX to a PHP web service

Attempting to send form data via jQuery and Ajax to a PHP web service (php file) for echoing the results. This is my index.html file <html> <head> <title>PHP web service &amp; AJAX</title> <link rel="stylesheet" type="text/ ...

Ways to implement CSS styling to every input element excluding inputs located within list items of a specific class

input.not(li.tagit-new >input) { background-color: lightgrey; } <ul id="tagAdministrator" style="width: 505px" class="tagit ui-widget ui-widget-content ui-corner-all"> <li class="tagit-new" style="box-shadow: none;"> <input ty ...

Is it possible to analyze an API call and determine the frequency of a specific field?

Code: var textArray = new Array(); var allText = results.data._contained.text; for (var i = 0; i < allText.length; i++) { var text1 = allText[i]; var textHtml = "<div id='text_item'>"; textHtml += "& ...

Strategies for creating a dynamic progress bar using jQuery and JavaScript

I'm currently working on a project that involves increasing a percentage number while filling up the background color inside it based on the percentage value. The current setup is functional in terms of animating the background, but I need it to dynam ...

Tips for recognizing components within the #document are as follows:

I am currently utilizing xpath to extract data from a dynamic table in an HTML document. The specific information I am looking for is contained within a tag identified as #document. However, I am encountering difficulties including this unique element in ...

Animated Gradient Header with CSS

I've been attempting to add an animated gradient to my header class, but so far I haven't been successful. I want the gradient to apply only to the header, not the body. Here's the link I'm using for reference: Can anyone offer some i ...

Attempting to emulate the grid showcase using flexbox styling

Creating this layout using CSS Grid was a breeze. However, I wonder if it can be achieved with Flexbox. What do you think? .Message { display: inline-grid; grid-template-areas: ". name""date text"; } .Date { align-items: ...

The collision function is currently not functioning properly, causing a hindrance in movement. There are no other codes restricting movement

const rightPressed = false; const leftPressed = false; const upPressed = false; const downPressed = false; const players = []; players[0] = new victim(1234); const arrayw = 50; const arrayh = 50; const canvas = document.getElementById("myCanvas"); const ...

Implementing pagination within an Angular 11 Mat-table with grouping feature

Encountering an interesting issue with MatTable pagination and grouping simultaneously. I have two components each with a Mat-table featuring Pagination+Grouping. ComponentOne functions smoothly without any issues. When choosing to display 5 elements pe ...

Switching background images for DIVs when links are rolled over

Having trouble changing the background image of a div when a user hovers over a link. Any ideas on what might be causing this issue? <style> #divToSwap { background-image: url(black.jpg); height: 150px; width: 150px; } </style> &l ...

Can we dynamically add an identical DOM structure by clicking a button using jQuery?

I currently have ten text fields within a single div. I am interested in including another set of ten text fields with the same name, class, and id. Is there a way to recycle the existing DOM structure mentioned above, or will I need to generate and add t ...

CSS page rule option for optimal display in Safari

What is the workaround for using alternative rules in Safari? I am currently implementing the angularPrint directive to enable print functionality on certain pages. This directive includes some helper classes in my document and utilizes the @page direct ...

Utilizing React for incorporating HTML5 canvas gradients

I'm currently working on an app that allows users to generate a background gradient with two distinct colors using React. The issue I'm facing is that while the first color appears correctly, the second color ends up looking more like a solid col ...

Homepage divided in two sections akin to the Tumblr landing page

Have you ever visited www.tumblr.com and noticed the '30 reasons...' link on the registration page that slides up and reveals a second page? I've been trying to figure out how they achieve this cool effect. Most tutorials show how to scroll ...

Is it possible to effortlessly associate a personalized string with an identifier within an HTML element utilizing Angular2?

Check out this cool plunker import {Component} from 'angular2/core' @Component({ selector: 'my-app', template: ` <div *ngFor="#option of myHashMap"> <input type="radio" name="myRadio" id="{{generateId(option[& ...

Adjusting the width of titles in a CSS menu upon hover

I am currently creating a basic CSS menu. However, I am facing an issue where selecting a menu title in the menu bar causes the width of the title to extend to match the width of the associated menu, which is not my desired outcome (the title's width ...