The margin-top and margin-bottom properties are not functioning as expected

Check out this source:

<div style="border:1px solid red; margin-bottom:10px">test blockA,</div>;    
<div style="border:1px solid red; margin-top:10px">test blockB</div>;

There is consistently a spacing of 10px between blockA and blockB...

I'm uncertain about the issue. Please refrain from suggesting 'use padding' or 'change 20px'.

The requirement is to utilize margin-bottom, margin-top with only 10px.

Answer №1

Termed as collapsing margin

according to w3c

CSS can combine the adjoining margins of multiple boxes, whether they are siblings or not, to create a single margin. This combining of margins is referred to as collapsing, and the resulting combined margin is known as a collapsed margin.

For more information, visit

Answer №2

To ensure both divs work properly, apply the CSS properties float: left; and potentially clear: both;.

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

Struggling to make the bootstrap navigation bar function properly

I've been experimenting with replicating the basic framework to learn more about responsive web design using bootstrap. However, I've only been able to get certain parts to function correctly. For instance, I can use the "btn" class without any i ...

Tips for eliminating the default hover and active states from a textfield in Material UI

Currently, I am in the process of creating a login form and have incorporated Material UI textfields. However, I am facing an issue where the textfield's default hover and active states cannot be removed. Below is my password textfield: (https://i.st ...

The email width is exceeding 600px in all Outlook email clients

Fellow developers, I need your expertise! I've spent hours testing this email and researching why it's not conforming to a width of 600. Below is my code snippet and screenshots from Email on Acid - everything looks great except in Outlooks (exce ...

Convert a web page with embedded images using Base64 strings into a PDF file using JavaScript

My website has numerous images with base 64 string sources. Typically, I am able to download the HTML page as a PDF using a service method that involves sending the HTML page with a JSON object and receiving the PDF in return. However, when there are many ...

Pass information from the view to the controller, and then relay it to a different view

I'm working on passing a variable to a controller and then utilizing that variable in another view. In View1.html: var cat = 5; Controller.js: // retrieve the cat=5 variable In View2.html: // also retrieve the cat=5 variable from the controller Vi ...

Is it possible to manipulate class attributes using an if statement in your code?

I am looking to dynamically change the classes based on user clicks on two different headings. When heading one is clicked, I want the font color to turn red and be underlined in red as well. The styling changes are already set up in the respective classe ...

Hide Scrollbar in CSS

Looking for a way to conceal the vertical scrollbar on my website, especially on mobile devices with touch scrolling capabilities. I attempted using CSS but didn't get satisfactory results, especially on older browser versions. ...

When a radio button is checked, add a class to its parent element that has a specific class assigned to it

In order to dynamically add a class to a specific div element higher up the DOM hierarchy when a radio button is clicked, I am in need of assistance. There are multiple instances of these div elements with different radio buttons, so it is crucial that on ...

Obtain user input from a form and assign it to a variable in a jQuery AJAX

How can I pass the value of an HTML Input Form to a jQuery AJAX call's URL as `amt` in `url: "http://localhost:8080/orderNo?amount=" + amt,`? The input value logs to the console when calling getAmtValue(), but I'm struggling to access the `amt` ...

Programmatically simulate a text cursor activation as if the user has physically clicked on the input

I have been attempting to input a value into a text field using JavaScript, similar to the Gmail email input tag. However, I encountered an issue with some fancy animations that are tied to certain events which I am unsure how to trigger, illustrated in th ...

Looking for an alternative to document.querySelectorAll?

My issue involves using querySelectorAll('a') to select all buttons, but I only want to target two specific buttons labeled 'Know More'. How can I achieve this? Below is the code snippet in question: const buttons = document.query ...

Exploring the process of using querySelector() to locate specific class and div IDs in JavaScript code

My objective is to make the id="myDropdownTop" trigger the corresponding drop-down menu. The problem lies in my script code, particularly the final line: ("div.dropdown-content").classList.toggle("show"); does not seem to be functioning correctly. <!D ...

When the page is zoomed in, the image exceeds the boundaries of the parent div

I attempted to position the div elements but did not achieve the desired outcome. .tab-vertical { border: 1px solid black; } <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" dat ...

Browser now replacing attribute translate="yes" with translate="translate"

We have encountered an issue with a translation library that is affecting the functionality of our page. <html lang="en" class="notranslate translated-ltr"> <meta name="google" content="notranslate"> As ...

saving information into a MySQL database

I am facing an issue where I am trying to write data to MySQL. When I input the data and press the submit button, the console log message from the function indicates that everything is okay. However, upon checking the database, there is nothing saved. Can ...

Looking to ensure that a div with no content adjusts to the height of the neighboring div?

Currently working on a Reactjs project. I'm trying to set the height of the colorTab div to match that of the content div, while making it responsive. The height of content should adapt dynamically based on the text content in title and description, w ...

The input field will display a border when it is actively selected

I am currently designing a form where the label should be positioned on the top border line of the text box. [![enter image description here][1]][1] Here is the code snippet: <div class="container"> <div class="row"> ...

What are some ways to utilize a Bootstrap modal button embedded within a clickable row?

Having a strange issue in my project. I am trying to incorporate a modal button inside a link-able row. However, when I click the button to trigger the modal id, it pops up and then redirects to the myexample.com page, which is expected behavior. While I ...

What is the best way to ensure one div expands to full width while simultaneously hiding another div on the page?

Hey there, I'm looking for a way to expand the width of a clicked div while making the other div disappear from the screen simultaneously. It should also be toggleable, so clicking the button again will shrink the div and bring back the other one. For ...

Table expands to full width

I am facing an issue with a table that has a large number of elements. I would like the table to expand to the full width of the screen, but it slows down significantly when it does so. https://i.sstatic.net/s475I.png However, I have noticed that if I se ...