What is the origin of the padding-top&bottom in my CSS code?

Here is the code I am using to create a simple 3-column layout (http://jsfiddle.net/7aC3U/)

This is the HTML code:

<div class="wrapper">
  <div class="col col-1-3">
    <div class="module">
      <p>Col 1</p></div>
  </div>
  <div class="col col-1-3">
    <div class="module">
      <p>Col 2</p></div>
  </div>
  <div class="col col-1-3">
    <div class="module">
      <p>Col 3</p></div>
  </div>
</div>

And this is the CSS code:

* {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box; }
.wrapper {
  background: red;
  margin: 0 auto;
  width: 90%;
  overflow: hidden;
  padding-left: 20px; }
.col {
  float: left;
  padding-right: 20px; }
.col-1-3 {
  width: 33.33%; }
.module {
  background: white;}

I'm facing an issue where the wrapper-div (red) has unwanted padding on the top and bottom, but I can't seem to identify where it's coming from. Any help would be greatly appreciated!

Answer №1

Each web browser interprets HTML and CSS codes in its own unique way, leading to slight variations in how the code is displayed. To prevent these differences, it is recommended to use a CSS reset before writing your code.

You can easily resolve this issue by following these steps: If you are experiencing automatic margin with the <p> element, simply add

p{
margin:0;
}

below your code to rectify the problem effectively.

Answer №2

If you are looking to reset padding and margin in all HTML elements, a simple CSS rule can do the trick:

* {padding:0;margin:0;}

However, it's worth noting that some developers advise against using box-sizing for this purpose, as it may not be considered best practice by everyone.

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

Steps for creating an attention-grabbing text heading

Is there a way to insert an H1 header within an image header, similar to this example? Or how can I incorporate the text "Hello World" into the image header? View Image Here ...

How to Position Buttons at the Bottom of a Card with Bootstrap

When creating a card for certain items, I am using the code below. To align the button at the bottom of the card, I have implemented the following: return ' <div class="col"> <div class="card detail ...

Spacious Bootstrap layout - 3 columns with the center column taking up the most space

I am in the process of designing a layout with 3 columns aligned in the same row: The first column should adjust to its content, such as a picture or avatar The third column should also adjust to its content, like a date or time. Meanwhile, the second col ...

Deactivated jQuery contextMenu following a mouseup event

Having an issue with my jQuery custom text-selection function disabling the contextMenu event. Here is a simple example with javascript and an html file: var markFeature = { getSelected: function(){ var t = ''; if(window.getSelectio ...

Choose an image to be displayed at either full width or full height, depending on which dimension is reached first

I have a query regarding resizing an image within a div to either 100% width or 100% height of the containing div. Despite setting max-height and max-width to 100% as recommended here, I still encounter overflow issues without wanting to crop the image usi ...

The site cache appears to be deactivated, but the source of the deactivation remains unclear. Can you help identify the issue?

On my PHP website, the <head> tag in the HTML includes: <meta http-equiv="Cache-Control" content="max-age=300"/> However, when checking the headers, it shows: Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre- ch ...

Transforming hover interactions into onclick events involves adjusting the CSS and JavaScript

Is there a way to convert this hover menu into an onclick menu? <div id='cssmenu'> <ul> <li class='has-sub'><a href='#'><span>Users</span></a> <ul> ...

LoadingService is not provided in Angular 2

I've been searching for solutions to a similar issue on StackOverflow, but unfortunately, none of them are resolving my specific situation. I am currently using the latest version of Angular. Implementing Loader Component import {Component, Element ...

The NgModel function within *ngFor is executing more times than necessary during initialization

Displayed on screen are a list of tutorials with check boxes next to each tutorial's states. These tutorials and states are pulled from the database, each tutorial containing a name and an array of associated states. Here is the HTML code: <div c ...

Tips for ensuring the preloader completely covers the height of the page and hides all loading elements

How can I ensure that the preloader covers the entire height of the page and no loading elements are visible? Whenever I run this code, the content inside is visible when I scroll down. How can I make sure that the preloader background covers the entire ...

Send and retrieve several files using HttpPostedFiles on the server

I have developed a straightforward method for uploading multiple pictures. The files are successfully uploaded to the server, but if there is an error on the server side, I use ModelState.AddModelError("PostedPhotos", "Error msg"); and send my viewmodel b ...

Step-by-step guide for setting up CodeMirror

I'm feeling a bit lost with what to do next: <link rel="stylesheet" href="lib/codemirror.css"> <script src="lib/codemirror.js"></script> <script> var editor = CodeMirror.fromTextArea(myTextarea, { mode: "text/html" }); ...

I encountered an issue where my style.css file was not properly linking to my HTML code. Whenever I saved the file, it would open

I'm a beginner in the world of HTML/CSS. When I save my style.css file, it shows up as a Notepad+ settings file and doesn't seem to work with my HTML. Can anyone advise me on what steps I should take? ...

Upload information into database without the need to refresh the webpage

Which programming language or tool would you recommend for efficiently loading data from a webpage into a database without requiring a page refresh? ...

The appearance of an SVG image inside an absolutely positioned div varies between Firefox and Chrome

The web page I am working on can be found at the following link: This webpage consists of text and SVG images, with the hex bolts positioned over specific areas of the text. Achieving this effect requires absolute positioning within a relatively positione ...

Leveraging JavaScript Jquery AJAX for executing a curl command with the -d and -u options

Currently, I am working on integrating a basic HTML page with jQuery and Streak CRM through a simple form. For more information about Streak integration, you can refer to the Streak docs here. The specific command I am attempting to utilize is as follows ...

What is the best way to decrease the spacing between buttons?

I've been working on creating a welcome banner for my index page, but I'm facing an issue where the buttons need to be closer to each other. However, I can't seem to figure out how to achieve this. The buttons should be aligned to the right ...

Tips for highlighting the final word in the headline using an underline

I'm attempting to create a title style similar to what is shown below https://i.sstatic.net/Qao4g.png The issue I'm facing is achieving the underline effect. I tried using title:after but it didn't give me the exact result I'm looking ...

Is there a reliable source for obtaining Bootstrap 3.0 code and documentation?

It appears that the code and documentation previously found on has vanished. Previously, I was able to visit: . ... However, these pages are now inaccessible. Does anyone know where they have been moved to? Or perhaps when Bootstrap 3.0 will be ...

Combine lists in columns into a single column

In my dataset, I have the following information: df = pd.DataFrame({ 'c1':['a','f,g,e','a,f,e,h','g,h','b,c,g,h',], 'c2':['1','1,1,0.5&ap ...