What's the best way to eliminate the space between vertically aligned divs?

I've been attempting to adjust the space between div 1 and div 2, but despite adjusting margins and padding, the gap persists. When modifying properties on the parent div, the children divs end up extending beyond the parent. I realize my approach to this problem may be misguided. Thank you for any assistance.

html {
overflow:
}

body {
  overflow-y: auto;
  overflow-x: hidden;
  height: 100vh;
  margin: 0; /* remove default margin */
  transition-property: background-position;
}
/* More CSS code... */
            
             
           

Answer №1

Default browser styles come with <p> elements having a default top and bottom margin of 1em. To remove these default paragraph styles, you can add the following CSS rule:

#subtitle p {
  margin: 0;
}

Answer №2

Adjust the #subhead p to have a margin: 0;. Remove the margin-left: 20px; on #vis and consider adding a padding-left: 20px; to align text with div1's content. The empty values on #quote paddings have been commented out for clarity as well.

html {
  overflow:
}
body {
  overflow-y: auto;
  overflow-x: hidden;
  height: 100vh;
  margin: 0;
  /* remove default margin */
  transition-property: background-position;
}
#subhead p {
  margin: 0;
}
div#container {
  height: 100%;
  margin: 0;
}
<div#static_nav {
  width: 100%;
  height: 2em;
  padding-top: 10px;
  position: fixed;
  z-index: 999;
}
.static_nav_full {
  background-color: #3A3D3F;
  transition: background-color 2s;
  opacity: .90;
}
.navbar {
  font-family: 'Source Sans Pro', sans-serif;
  padding-right: 20px;
  background-color: transparent;
  text-align: right;
}
div#static_nav a {
  color: white;
  text-decoration: none;
  padding-right: 20px;
}
div#static_nav a:hover {
  color: #8E8E8E;
}
div#block_one,
div#block_two,
div#block_three,
div#block_four {
  height: 100vh;
  z-index: 1;
  padding-top: 51px;
  width: 100%;
}
div#block_one {
  background-image: url(https://images5.alphacoders.com/439/thumb-1920-439361.jpg);
  background-size: cover;
  background-attachment: fixed;
  transition: all 0.2s ease;
  -webkit-transition: all 0.2s ease;
  background-repeat: no-repeat;
  position: relative;
}
div#logo {
  background-image: url(http://www.clker.com/cliparts/C/k/d/o/B/3/white-peace-sign-hi.png);
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
  height: 100%;
  z-index: -1;
}
.heading {
  padding-top: 10px;
  padding-bottom: 20px;
  width: 90%;
  height: 1em;
  border-top: 2px solid #A8A8A8;
  margin: 0 auto;
  font-size: 40px;
  font-family: 'Hind Guntur', sans-serif;
}
div#subhead {
  width: 88.8%;
  margin: 0 auto;
  border-left: 5px solid #D8D8D8;
  text-indent: inherit;
  background-color: blue;
}
div#quote {
  /*padding-top: ;
  padding-bottom: ;*/
  padding-left: 20px;
  font-family: 'Heebo', sans-serif;
  font-size: 18px;
  height: 50%;
  background-color: red;
  margin: 0 auto;
}
div#vis {
  /*margin-left: 20px;*/
  padding-left: 20px;
  font-family: 'Heebo', sans-serif;
  background-color: red;
  height: 50%;
}
div#block_five {
  height: 30vh;
  background-color: #F5F5F5;
}
<!DOCTYPE html>

<html lang="en">
<meta charset="utf-8" />

<head>
  <link rel="stylesheet" type="text/css" href="tof_css.css" />
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

  <link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Lato|Kanit|Heebo|Source+Sans+Pro:200|Hind+Guntur:Regular">

</head>

<body>
  <div id="container">

    <header>
      <div id="static_nav">
        <nav class="navbar">
          <a href="#block_one">Home</a>
          <a href="#block_two">About</a>
          <a href="#block_four">People</a>
          <a href="#block_five">Contact</a>
          <a href="">Log In</a>
        </nav>
      </div>
    </header>


    <div id="block_one">
      <div id="logo">
      </div>
    </div>

    <div id="block_two">
      <header class="heading">
        TEST
      </header>
      <div id="subhead">
        <div id="quote">
          <p>Div 1</p>
        </div>
        <div id="vis">
          <p>Div 2</p>
        </div>
      </div>

      <div id="block_three">
      </div>

      <div id="block_four">
      </div>

      <div id="block_five">
      </div>

    </div>

</html>

Answer №3

There is an issue with the margin-top on your p element under #vis, removing it will eliminate the gap

#vis p {
  margin: 0;
}

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

Getting the value of "Page=?" from the href attribute in an HTML tag can be done using Selenium Webdriver and Java

I am looking to extract the value "page = ?" from a specific "href" tag in the HTML code below. I need this value for my Selenium WebDriver script so that my loop can iterate up to page 53. Can someone guide me on how to retrieve the "page =" value mentio ...

Converting JSON data to HTML using Handlebars

Can you assist me in transforming the following JSON data into a table with 3 columns: property name, property source, and property value? "result": { "total": 100, "config": { "propName1": { "source": "propsrc1", ...

CSS hover effect not working while mouse is in motion

As a beginner in HTML, CSS, jQuery, and JavaScript, I've been trying to trigger a div when hovering over one area using the adjacent siblings code. However, I'm encountering an issue where if I move my mouse after triggering the event, it keeps r ...

display the entire calendar for the chosen month

I am currently using Foundation Datepicker and Full Calendar. My requirement is as follows: 1) When I select a date in the calendar, For example, let's say it's July 2016. If I choose a date in November or any other month in the Foundation Date ...

Is there a WebKit equivalent to the MDC (Mozilla Documentation Center)?

Experimenting with the newest HTML5 features is rewarding, yet challenging as standards and browser-specific implementations constantly evolve. While Mozilla provides a valuable resource with their MDN Doc Center documenting Gecko changes, I'm curious ...

Display modal after drop-down selection, triggered by API response

Currently, I am working on integrating an API to enable users to make payments through a modal. Users should be able to enter an amount and select a payment frequency. I have successfully extracted various payment frequencies from the API response and pop ...

Mastering the nav-item class in Bootstrap 4 for optimal navigation functionality

When I look at the examples in the documentation, I have noticed that the .nav-item class is not doing anything when I inspect my nav bar (the class doesn't show up in the console)... Although this isn't a major issue as I can apply my own style ...

How can you determine the dimensions of an image in HTML using Python?

Is there a way to extract image size information from source code using Python? tree = etree.HTML(source_page_text) image_list = tree.xpath('//img[@src]') The 'img' tags with 'src' attributes can be found using xpath as show ...

As the Div descends, it endeavors to maintain alignment with its counterparts

My webpage has a parent div with multiple child divs in one row. These child divs are generated dynamically, so I don't know how many will be displayed at once. The parent div has a fixed width and a horizontal scrollbar appears when all child divs ar ...

Create unique pages based on varying content types

Let's consider the structure I am working with: _components (directories) x1.html x2.html x3.html On my initial page, I gather information from the YAM section for each component. https://i.sstatic.net/en6mC.png Now, I want to include a link f ...

Storing user input into a MySQL database with NodeJS and Express

Seeking assistance for a school project where I am required to input data from an HTML form into a database. The challenge lies in my lack of experience with NodeJS, Express, Handlebars, or JavaScript, making it difficult for me to comprehend the process. ...

The hover effect on MUI TableRows is being overshadowed by the background color of the TableCell

I'm currently using @mui/material version ^5.10.1. My challenge is applying the TableRow hover behavior as outlined in the documentation. However, I have also set a background color for the first TableCell in each row, which ends up overriding the ho ...

Tips for displaying JSON data by formatting it into separate div elements for the result object

Having recently started using the Amadeus REST API, I've been making AJAX calls to retrieve data. However, I'm facing a challenge when it comes to representing this data in a specific format and looping through it effectively. function showdataf ...

Always ensure that only one div is visible at a time

I am currently working on a project where I cannot use ng-cloak due to the way the css files are loaded. I have been exploring alternative solutions and have tried a few different approaches. My main goal is to ensure that two icons are never shown at the ...

"Encountering issue with SCSS variable not being applied to background in file

$enable-grid-classes: false; $enable-cssgrid:true; $deepBlue: #032f3e; body { --bs-body-bg: orange ; } @import "https://fonts.googleapis.com/css2?family=Space+Grotesk:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="463121 ...

Adding the "input-invalid" class to the input doesn't take effect until I click outside of the input field

When the zipcode field is updated, an ajax call is made. If there are no zipcodes available, I want to mark it as invalid by adding the "input-invalid" class. However, the red border validation only appears when clicking outside of the input field. Is ther ...

Angular is sending a parameter with a null value, which is not supposed to happen

My filtering system used to work well with a code that displayed items of specific status. However, I had to modify it to match a select input requirement. <ul id="dropdown-basic" *dropdownMenu class="dropdown-menu" role="menu" aria-labelledby="button- ...

I am looking to switch the content between two divs. Specifically, I want to take the content from div 1 and move it to div 2, while moving the

I am facing a challenge involving three divs. One of them is the main div, while the other two are positioned below it and contain different content. I am trying to find a way to swap the content between div one and div two in such a way that the original ...

Issue regarding the functionality of CSS styling when applied to a button

Trying to Style a Button with CSS div.myButton input a { display:block; height: 24px; width: 43px; padding:10px 10px 10px 7px; font: bold 13px sans-serif;; color:#333; background: url("hover.png") 0 0 no-repeat; text-decoration: none; } myButton a:hover { ...

The system considers the resource as a script, yet it was transmitted with the MIME type of text

I am encountering an issue when trying to integrate AngularJS/JavaScript into my HTML document. Each time I try to load my index.html file, the following error message appears: Resource interpreted as Script but transferred with MIME type text/html: "http ...