What's causing margin-top to be reversed while margin-bottom remains stationary?

I have encountered a specific issue that I can't seem to find a solution for. I am attempting to include the text "2017 Indie" at the bottom of the page. When I apply margin-top to a pixel value, the text remains unchanged and nothing happens. However, when I use margin-bottom, it creates additional white space above my current division which is not the desired outcome. I am unsure of what the problem may be.

html,
body {
  height: 100%
}

* {
  margin: 0;
}

.sect1 h1 {
  font-size: 100px;
  color: white;
  margin-top: 150px;
  padding: 0;
  display: inline-block;
}

.sect1-1 {
  text-align: center;
}

.sect1-text {
  text-align: center;
}

.sect1 p {
  font-size: 40px;
  color: white;
  margin-top: 250px;
  padding: 0;
  display: inline-block;
}

.text3-1 {
  text-align: center;
  margin-top: 100px;
  display: block;
}

.text3-1 p {
  font-size: 100px;
  color: white;
  background: blue;
  padding: 50px;
  display: inline-block;
}

#p1 {
  top: 540px;
  padding-left: 520px;
  color: white;
  font-size: 42px;
}

#p2 {
  top: 840px;
  padding-left: 220px;
  color: white;
  font-size: 24px;
}

#p3 {
  color: black;
  top: 2935px;
  padding-left: 665px;
}

iframe {
  position: absolute;
}

.sect {
  height: 100%;
  background-size: cover;
  background-attachment: fixed;
}

.subSect {
  height: 51.75%;
  background-color: orange;
  margin: 0;
}

.sect1 {
  background-image: url("images/image4.jpg");
}

.sect2 {
  background-image: url("images/image5.jpg");
}

.sect3 {
  height: 100%;
  background-size: cover;
  background-image: url("images/image2.jpg");
}

script {
  padding-left: 250px;
}
<div class="sect sect1">
  <div class="sect1-1">
    <h1>Indie</h1>
  </div>
  <div class="sect1-text">
    <p>What music</p>
  </div>
</div>

<div class="subSect">
  <div class="text">
    <p>This is about....</p>
  </div>
</div>


<div class="sect sect2">
</div>

<div class="subSect"></div>


<div class="sect3">
  <div class="text3-1">
    <p>2017 Indie</p>
  </div>
</div>

Answer №1

From my perspective, the margin is functioning as intended. The issue lies with the enclosing div. You have set sect3 to a height of 100%. This causes the div to take on the height of its parent element, which in this case is the body tag. Removing the height style should resolve the issue if I have understood the problem correctly.

If maintaining a height of 100% is necessary, you will need to apply additional styling to position the text at the bottom.

Add position: relative to the container sect3 and then position the text3-1 div at the bottom, for example:

.text3-1 {
  position: absolute;
  width: 100%;
  bottom: 0;
  text-align: center;
  margin-top: 100px;
  display: block;
}

html,
body {
  height: 100%
}

* {
  margin: 0;
}

.sect1 h1 {
  font-size: 100px;
  color: white;
  margin-top: 150px;
  padding: 0;
  display: inline-block;
}

.sect1-1 {
  text-align: center;
}

.sect1-text {
  text-align: center;
}

.sect1 p {
  font-size: 40px;
  color: white;
  margin-top: 250px;
  padding: 0;
  display: inline-block;
}

.text3-1 {
  position: absolute;
  width: 100%;
  bottom: 0;
  text-align: center;
  margin-top: 100px;
  display: block;
}

.text3-1 p {
  font-size: 100px;
  color: white;
  background: blue;
  padding: 50px;
  display: inline-block;
}

#p1 {
  top: 540px;
  padding-left: 520px;
  color: white;
  font-size: 42px;
}

#p2 {
  top: 840px;
  padding-left: 220px;
  color: white;
  font-size: 24px;
}

#p3 {
  color: black;
  top: 2935px;
  padding-left: 665px;
}

iframe {
  position: absolute;
}

.sect {
  height: 100%;
  background-size: cover;
  background-attachment: fixed;
}

.subSect {
  height: 51.75%;
  background-color: orange;
  margin: 0;
}

.sect1 {
  background-image: url("images/image4.jpg");
}

.sect2 {
  background-image: url("images/image5.jpg");
}

.sect3 {
  position: relative;
  height: 100%;
  background-size: cover;
  background-image: url("images/image2.jpg");
}

script {
  padding-left: 250px;
}
<div class="sect sect1">
  <div class="sect1-1">
    <h1>Indie</h1>
  </div>
  <div class="sect1-text">
    <p>What music</p>
  </div>
</div>

<div class="subSect">
  <div class="text">
    <p>This is about....</p>
  </div>
</div>


<div class="sect sect2">
</div>

<div class="subSect"></div>


<div class="sect3">
  <div class="text3-1">
    <p>2017 Indie</p>
  </div>
</div>

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

Express app unable to retrieve dropdown menu data using Node.js BodyParser

I am currently working on creating a pug file for a signup form and I'm encountering an issue with the drop-down menu not functioning. How can I properly include my drop-down menu in the body parser? I initially assumed it would be processed with json ...

Animations in Angular fail to operate within mat-tabs after switching back when custom components are being utilized

I am facing a similar issue as Olafvv with my angular 16 project. The problem occurs in a mat-tab-group where the :enter animations do not work when navigating away from a tab and then returning to it. However, in my case, the issue lies within a custom su ...

Styling the nested list items with text decoration

I have a scenario where I applied text-decoration: underline; to the parent li, which is being inherited by the child li. Despite trying to remove this style from the child elements using text-decoration: none !important;, it doesn't seem to work. The ...

In my ejs file, I need to input a name and then process it in my post request

I am working on an ejs file where I need the user to input their username into a form. I will then use this username in a .get request to perform certain logic. However, I am encountering an issue where the username is showing up as undefined. Here is a s ...

"Discover the process of incorporating two HTML files into a single HTML document with the help of

I successfully created both a bar chart and a pie chart using d3.js individually. Now, I am trying to load these charts into another HTML file using jQuery. $(document).ready(function() { console.log("ready!"); $("#piediv").load("file:///usr/local ...

Insert a line break element following every 12th character within a given string

$my_string = "Lorem Ipsum is simply dummy text of the printing and typesetting industry." Desired Output : "Lorem Ipsum <br/> is simply<br/> dummy text<br/>of the printing<br/> and typesetting<br/> industry." The tag should ...

Activate an event on a separate webpage using jQuery or JavaScript

Currently, I am in the process of working on a project with 2 distinct pages: Index Settings On the Settings page, I have implemented a button to close an element and hide it. However, I am encountering an issue where I want the elements on the Index pa ...

Switch images when hovering

I currently have two dropdown menus called NEW and SHOP. When I hover over the New Menu 1, it should display the corresponding image. Similarly, when hovering over New Menu 2, the related image should be shown in a div with the ".menu-viewer" class. Whil ...

The Power of the CSS Universal Selector and Specificity

Currently exploring the puzzling scenario where .x seems to have higher specificity than *.x, despite expectations. Shouldn't *.x technically have a specificity of 0-0-1-1 (1 class, 1 tag) while .x is just one class with specificity 0-0-1-0? Let&apo ...

The functionality of opening a new tab when clicking on a link image is not functioning correctly on Mozilla, whereas it

Check out my code below: <a target="_blank" href="#" onclick="window.open('https://www.google.com','_blank');"> <img src="#{request.contextPath}/resources/img/landing-page/terdaftar-kominfo.png" /> </a> ...

What steps can be taken to implement CSS rules on an HTML element with ExtJS?

In my ExtJS 4 project, I am working on drawing an image inside a panel and slider field. My goal is to adjust the opacity of the image based on the value of the slider field. I understand that I can use CSS rules like opacity and filter:alpha(opacity=); t ...

Dynamic JavaScript tool

Does anyone know which library is being used on the website linked here? I am working on a project similar to this and would appreciate if anyone can identify this library for me. Thank you in advance. ...

Step-by-step tutorial on designing an input slider to dynamically adjust the CSS :before linear-gradient values

Is there a way to achieve a gradient effect using pseudo-element :before on an image that can be customized by adjusting a slider input? I've been trying to implement this feature with the following code, but have not been successful so far. var ...

Create a slider feature on a webpage using the Google Maps API

A webpage has been created using the Google Map API. JSfiddle function initMap() { var intervalForAnimation; var count = 0; var map = new google.maps.Map(document.getElementById('map'), { cen ...

Creating a cross-platform file writer with PHP and JavaScript

My current challenge involves using buttons on an HTML page to trigger a PHP program that writes to a text file. Despite receiving a success message from my Ajax function, the file that should have been written to doesn't exist. Here's a snippet ...

Is the ID selector the quickest method in jQuery and CSS?

Which is the optimal choice in jQuery/javascript for speed? $('#myID .myClass') or $('.myClass') What is the preferred option to utilize in CSS? #myID .myClass{} or .myClass{} In hindsight, I realize my explanation was insuffici ...

Creating a Duplicate of an iframe with jQuery

Hey there, I have a dilemma with two divs. One is for displaying content, and the other is a video player that I want to pause and resume on scroll using jQuery. My goal is to pause the video in the "myplayer" div on scroll and have it resume playing from ...

Swapping out ChildNode data for HTML elements

When attempting to replace a node value with HTML content, I encountered an issue where the HTML tags were being displayed on the HTML page instead of applying the intended style. <style> .YellowSelection { background: yellow; } < ...

Java update query experiencing issues

This servlet is designed to add a new user entry into a database table. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String firstname = request.getParameter("firstname"); Str ...

What is the best way to create a carousel component with this particular design?

`I want to enhance my static HTML CSS website by incorporating a slider feature using JavaScript. Looking for guidance on the best approach. Here is the layout. I've attempted various tutorials but they weren't compatible with my layout or reli ...