Increase the padding at the top and bottom of the div border

I am facing a problem with CSS shrinkwrapping. Here is the simple code snippet...

<!doctype html>
<html lang="en-US">
    <head>
        <title>Device Activation</title>
        <meta charset="utf-8">
        <style type="text/css">
            body {
                background: white;
                font-family: "Arial Black", Gadget, sans-serif;
            }
            div {
                background: #dddddd;
                //border: 1px solid;
                border-radius: 40px;
                box-shadow: 10px 10px 5px #888888;
                //display: inline-block;
                padding: 0px 10px;
                //text-align: justify;
                //-moz-border-radius: 40px;
            }
        </style>
    </head>
    <body>
            <h1>Boogy-woogy</h1>
        <div id="start" class="toggleable">
            <p>Test</p>
        </div>
    <script type="text/javascript">
        function makeVisible() {
            // Not here yet, but that's okay...right?   
        }
    </script>
    </body>
</html>

The issue I'm encountering is that when the comments are removed from border: 1px solid;, the margins of the div increase significantly.

Despite trying various fixes to address this collapsing-margins issue, nothing seems to affect my desired outcome.

Your assistance in resolving this matter would be highly appreciated.

Answer №1

It appears that the issue is related to the default margins and padding of the p element.

p {
    margin:0;
    padding:0;
}

You can resolve this by adding the aforementioned CSS code.

Answer №2

It's possible that the issue in your code sample is just a simple typo. However, if it's not, please keep in mind that JavaScript comments can be done in two ways:

// This is a javascript comment
/* This is a javascript comment as well... */

https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Code_comments

If you intend to create a CSS comment, using // this is a comment syntax won't work. You must use the /* this is a comment */ syntax instead.

http://www.w3.org/TR/CSS21/syndata.html#comments

Also, when I remove the border: 1px solid line, the top and bottom margins do not change visibly. Nevertheless, due to the incorrect syntax used in your question, the div was defaulting to display: block because the inline-block rule wasn't being applied. Since inline-block wasn't being applied, the div expanded to its full width.

http://jsfiddle.net/2f59k/

 body {
      background: white;
      font-family:"Arial Black", Gadget, sans-serif;
  }
  div {
      background: #dddddd;
     /* border: 1px solid;*/
      border-radius: 40px;
      box-shadow: 10px 10px 5px #888888;
      display: inline-block; 
      padding: 0px 10px;
      text-align: justify;
      -moz-border-radius: 40px;
  }

To clarify, remember that this isn't a CSS comment:

// border: 1px solid;

This, however, is a valid CSS comment:

/* border: 1px solid; */

UPDATE

The issue at hand doesn't have anything to do with border radius or borders. The excessive space above and below the text within the grey background is due to the margin. Although significant, this increase pales in comparison to the width fluctuation when transitioning between block and inline-block.

By setting the inner paragraph's margin to margin: 0, the problem is resolved.

http://jsfiddle.net/74eTg/

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

What is the best way to extract percentage values from a string using a regular expression?

Is there a way to extract percentage values from a string without including the percent sign? I am trying to retrieve the numbers from the string, excluding the % symbol. Currently, my code works but includes the percent sign in the output: "asfd %1.3344 ...

Maximizing the benefits of the express.js API through functions such as fetching data with get, sending

As someone who is just starting out in web development, I have recently delved into node and express 4.9.0. After going through some tutorials and experimenting with the API, it's clear to me that the http protocol and request URLs are essential comp ...

Can you explain the purpose of using href="#" in web development?

I've noticed that numerous websites use links that have href="#". Can you explain what this means and how it is typically used? ...

Obtain gridview row coordinates to create a canvas drawing using Raphael.js

I need to create various shapes based on the status of each row. In order to make it compatible with Internet Explorer, I have integrated the Raphael JavaScript library into my project. The backend is built using ASP.NET and C#. To draw these shapes, I mus ...

Adding navigation links to move forward and backward on a webpage in Django:

Currently, I am leveraging Django Python Templates to create a blog with two distinct frames. The code below is used to populate the links on the left side frame: {% for post in posts %} <div class="post"> <ul style="padding: 1px;"& ...

Slider buttons are not appearing in Time Picker

I recently added a Time Picker to my project, but I'm experiencing an issue where the slider buttons for selecting time are not showing up. Could you please refer to this image: Checking the console, there don't seem to be any errors present. ...

What is the best way to collapse an array within an object?

I'm looking for a way to flatten an array within an object using JavaScript, preferably ES6. I'm not sure if "flattening" is the correct term here, but I just want a solution to achieve this transformation. Currently, I have this structure: { ...

Encountering an error message stating, "Unable to interpret property

I need to retrieve specific information import React,{Component} from 'react'; import axios from 'axios'; import CoinsConvert from '../data/data' import '../style/bootstrap.min.css'; class BoxInfo extends Component ...

What causes the failure of data reaching the server?

I need to make updates to some details in a few tables, but I'm having trouble getting it to work. Can someone help me figure out what's wrong? <body> <form class="" action="view_update_emp.php" method="post& ...

Eliminate border-radius property from Bootstrap 4 breadcrumb using Sass styling

Within Bootstrap 4, there exists a Sass variable known as $enable-rounded which "Enables predefined border-radius styles on various components." (https://getbootstrap.com/docs/4.1/getting-started/theming/#sass-options) I need to eliminate the rounded ...

Issue with hidden input field not displaying array on submission

I need assistance with adding filenames that have been uploaded to an array in a hidden input field within a form. Here's what I currently have in my form: <input type="hidden" name="myFiles[]" id="myFiles" value=""> This is how my file upload ...

Difficulty in making Materialize.css column match the height of the entire row

Utilizing React.js, Materialize.css, and certain MaterialUI components in collaboration to build a website. Developed a header (React component, basic div with title and logout button) for the site using a Materialize.css "grid". Issue: The react compone ...

Determine in Jquery if all the elements in array 2 are being utilized by array 1

Can anyone help me figure out why my array1 has a different length than array2? I've been searching for hours trying to find the mistake in my code. If it's not related to that, could someone kindly point out where I went wrong? function contr ...

How can you use CSS animations to animate two images in a way that hides one while showing the other?

click here for the image link visit this webpage for the link I need I am looking to add an animated section to my website. The inspiration comes from the webpage linked above, where images slide down one after another in a seamless manner. I attempted t ...

How can you quickly track the AJAX requests being sent?

Is there a tool, preferably a Firefox extension, that can show me all AJAX subrequests? I want to be able to see the URL being requested and any GET or POST variables that are sent with it whenever an XMLHTTPRequest() is made. I haven't found anythin ...

The NgbTooltip does not activate when hovering over a <td> cell

I'm currently facing an issue with implementing ngbTooltip on <table> elements. Initially, I had trouble with <th>, but that was resolved by using the container attribute after referring to this helpful post. The main challenge arises ...

Solving the Cross-Origin Resource Sharing problem in AngularJS

While using the http dependency in AngularJS and setting headers for CORS, I am encountering an error. Please check the console.log for more information on the error. The error message reads: "XMLHttpRequest cannot load . Response to preflight request doe ...

NodeJS is facing a severe challenge in properly rendering HTML and its accompanying CSS code, causing a major

Once upon a time, I built a beautiful website while practicing HTML, CSS, and JS. It had multiple web pages and used Express for the backend. Unfortunately, I lost all the files associated with it and took a break from web programming for some time. Now, w ...

Dynamic image gallery with a flexible layout and interactive scrollbar using Flexbox

I'm looking to incorporate a scrolling image gallery into a flexbox layout so that as the browser page size changes, the gallery will scale according to the flex-grow index. My goal is to ensure all images remain accessible via a scrollbar without usi ...

Various ways to utilize Apollo's Query property

There are a couple of ways I've come across to utilize the new Query and Mutation props from Apollo. However, I've only been able to successfully implement one of them. First, defining the query within the Query prop directly like this: <Qu ...