What is causing the top margin to be hidden from view?

Here is the following HTML code snippet provided:

<div class="row">
  <div class="column">
    Some text
  </div>
  <div class="column blue">
    Some other text
  </div>
</div>

Case One - The CSS code applied, without specifying margin,

.row {
   background: red; 
}

.column {
  #margin: 10px;
  background: green;
}

.blue {
  background: blue;
}

resulting in:

https://i.sstatic.net/UUZhT.png

Case Two - The CSS code after setting the margin,

.row {
   background: red; 
}

.column {
  margin: 10px;
  background: green;
}

.blue {
  background: blue;
}

yielding the output,

https://i.sstatic.net/7MTtI.png

Case Three - The CSS code with overflow set as hidden

.row {
  background: red; 
  overflow: hidden;
}

.column {
  margin: 10px;
  background: green;
}

.blue {
  background: blue;
}

with the resulting output being,

https://i.sstatic.net/62j9X.png

1)

In Case Two, why doesn't the container with 2 div elements expand on top margin?

2)

In Case Three, why does the container with 2 div elements expand on top margin?

Answer №1

Implementing an overflow:hidden on the parent element can alter its Block Formatting Context. This change is achieved by only a select few styles.

I commonly employ this technique to clear modules automatically.

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

Display the latest tooltip in a Tree view

I have developed a unique custom component to incorporate tooltips for each individual node within a Tree. function StyledTreeItem(props) { const { nodeId, labelText, tooltipTitle, ...other } = props; return ( <Tooltip title={tooltipTitle} placem ...

`Responsive Site with Centered Image Overlay`

I've been attempting to center a small image within a larger one, both of which are contained within a Bootstrap Column. <div className="row justify-content-center my-5 "> <div className="col-xs-10 col-sm-6 my-auto mx-auto" ...

Distinguishing Design with CSS3

Here is the code snippet I am using: <table width="562" cellspacing="0" cellpadding="0" border="0" align="center" class="genericClass"> (nested tags are here) </table> These are the related styles in my stylesheet: table.genericClass a ...

Soundtrack featured on the main page

Currently, I am trying to incorporate an audio file into my homepage without interrupting its playback when the user navigates to another page or title. Essentially, I want the audio .mp3 file to continue playing in the background seamlessly. I am currentl ...

Variations in performance when utilizing document.getElementById(id), $(id), and containerElement.find(id)

Imagine there is a container element on a webpage surrounded by other elements that make up the page layout and navigation. Inside this container, there is a substantial amount of content. When working with JavaScript, I need to locate and manipulate spec ...

How can we consolidate an excess of menu items into a condensed, collapsed menu?

I have a navigation bar displaying category items, but if the menu items exceed the navbar width, how can I condense them into a drop-down menu using Bootstrap 3.0? Currently, my navbar only shows 10 items due to limited space. However, I have more items ...

Arrange a div element among the descendants of a neighboring div

I am working with a div that is generated by a library. This div contains 2 child divs with varying heights, which can change based on the API response and the width of the browser window. My goal is to display another div (my-div) between top-bar and bot ...

Create a way to allow users to download html2canvas with a customized filename

I have a div where I want to use html2canvas to save a PNG file of its content. The issue is that the name of the saved file is static in my code and does not change unless I manually edit it. Is there a way to dynamically set the filename based on user i ...

Mosaic Magic with Bootstrap 4

Struggling with creating a mosaic-style layout here. I've tried using Bootstrap 4's grid system, flex, and other methods, but no luck getting it to work seamlessly across all devices. Attached an image of the layout - the middle two boxes are fo ...

Tips for loading HTML content before executing any JavaScript code or requesting user input via prompt

I am looking to have the page function in a specific way: The HTML loads, and the first prompt asks the user for input. Once the prompt is submitted, the running total changes and is displayed on the page. The same process happens for the second prompt and ...

Is there a way to open an app using a custom scheme without triggering the "open in <appname>" warning?

Trying to launch my app from Safari using a custom scheme specified in the info.plist: <key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLName</key> <string>com.appvendor.rentalapp</ ...

Having an issue with displaying properly formatted text in a CKEditor integrated Rails 3 application

I am currently utilizing ckeditor with Rails 3 and have successfully set it up in the form. Everything seems to be working nicely, except for the view part. When I navigate to the model show page, I see the tags I used for text formatting, but there is no ...

Activate hover effect on desktop screen (excluding tablets and phones) by utilizing media queries

Applying hover state styling to a div can be done like this: div { &:hover { color: red !important; border: 3px solid red !important; } } To exclude iPads and other tablets from this CSS style, you can util ...

Navigating to the Top of the Page

I am facing an issue with my webpage that is similar to the code provided below: var btn = document.getElementById('test') test.addEventListener("click", function(){ window.scroll(0,0) }) .wrap { overflow-y: scroll; position: absolute; ...

Invisible and Unrestricted automatic playback

Why is auto play muted in both Firefox and Chrome? How can we code it so that browsers don't block it? Here's the code I'm using: <audio id="audio1" src="https://notificationsounds.com/storage/sounds/file-sounds-1217-relax ...

Looking for a JavaScript snippet to insert the word "Search" into an empty DIV element with the specified id attribute

I am trying to insert the word "Search" into an empty input field with the id "ReportQuery" using JavaScript. Unfortunately, I do not have access to the HTML code directly. How can I achieve this task through coding? Below is the snippet of code that nee ...

problems with an extra administrator account access

Is it possible to have a single login form that can cater to both users and admins? I currently have a user login system in place but would like to add an admin login as well. How can I implement this without creating separate logins? if(isset($_POST[&ap ...

What is the process for modifying the design of an NPM package?

I may have a silly or incorrect question, but what exactly is the extent of default styling in an NPM package? If I am using an NPM package and wish to adjust the color of one of their elements, how should I go about it? In both my own index.css file and ...

Integrating a search box with radio buttons in an HTML table

I am currently working on a project that involves jQuery and a table with radio buttons. Each button has different functionalities: console.clear(); function inputSelected(val) { $("#result").html(function() { var str = ''; ...

Extensive Horizontal Menu and Sub Menu Aligned Perfectly in the Center

I need help creating a horizontal menu with a sub-menu that is full width and centered. Does anyone have any advice on how to achieve this? Thank you in advance! The following HTML code creates a horizontal menu and sub-menu, but they are currently align ...