Can the <container> block be positioned beneath the <header> block?

header {
  background: blue;
  color: white;
  width: 100%;
}

.container {
  background: green;
  text-align: center;
  width: 100%;
  height: 100px;
  transform: skew(0, -10deg);
  color: white;
  position: relative;
  top: 55px;
}

.container .home{
  position:absolute;
  bottom:0;
}
<header class="header">
  <div class="logo">
    <i class="fab fa-accusoft"></i>
    <span class="title">DreamCoding</span>
  </div>

  <section class="container">
    <div class="home">
      <div class="title">Alphabet</div>
      <div class="text">
        abcdefg
      </div>
    </div>
  </section>

I am facing a situation where I have the header box and the container box. My challenge is to make sure that the container box is covered by the header box. However, I keep encountering an issue where the container box gets covered by the header box repeatedly.

English is not my first language, so I hope I made myself clear. Regardless, thank you in advance for your help.

Answer №1

To ensure proper layering of the elements, it is important to include the z-index property in both elements. Below is a runnable code snippet demonstrating this:

header {
  background: blue;
  color: white;
  width: 100%;
  z-index: 1;
}

.container {
  background: green;
  text-align: center;
  width: 100%;
  height: 100px;
  transform: skew(0, -10deg);
  color: white;
  position: relative;
  top: 55px;
  z-index: -1;
}

.container .home {
  position: absolute;
  bottom: 0;
}
<html>

<body>
  <header class="header">
    <div class="logo">
      <i class="fab fa-accusoft"></i>
      <span class="title">DreamCoding</span>
    </div>

    <section class="container">
      <div class="home">
        <div class="title">Alphabet</div>
        <div class="text">
          abcdefg
        </div>
      </div>
    </section>
  </header>
</body>

</html>

**The purpose of using the z-index property is to control the stacking order of elements on a webpage.

Answer №2

You have the ability to define a background in the :before selector by using position:absolute and z-index:-1

body{
  margin: 0;
}
header {
  background: blue;
  color: white;
  width: 100%;
}

.container {  
  text-align: center;
  width: 100%;
  height: 100px;  
  color: white;
  position: relative;
  top: 55px;
}

.container:before {
  content:"";
  transform: skew(0, -10deg);
  background: green;
  width: 100%;
  height: 100%;
  position:absolute;
  top:-25px;
  left: 0;
  z-index: -1;
}

.container .home{
  position:absolute;
  bottom:0;
}
<header class="header">
  <div class="logo">
    <i class="fab fa-accusoft"></i>
    <span class="title">DreamCoding</span>
  </div>
  <section class="container">
    <div class="home">
      <div class="title">Alphabet</div>
      <div class="text">
        abcdefg
      </div>
    </div>
  </section>
</header>

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

achieving initial value to show upon page load

I'm trying to set a default value that is visible when the page loads. My goal is to have the first button always displayed by default in the "display-donation" div whenever someone visits the form. Currently, when the page loads, 10 is highlighted ...

The search functionality in an Html table is currently malfunctioning

Currently, I am working on developing a search mechanism in HTML. It seems to be functioning properly when searching for data for the first time. However, subsequent searches do not yield the expected results. Additionally, when trying to search with empty ...

Unexpected behavior from Internet Explorer - Span contents remain unchanged despite valid input

I have a simple question because I'm feeling a bit lost. Check out this JSFiddle link It seems that in Internet Explorer, the contents of my span won't update even though the input is valid. However, in other browsers, the span content changes ...

The button can only be edited using Internet Explorer

My webpage features a button that displays correctly in Chrome, but the text inside the button gets cut off when viewed in IE (see image). Can you provide guidance on what might be causing this issue and how to resolve it? Bootstrap version 4.0.0 is also b ...

Tables that are not only responsive but also friendly to mobile

For the past week or so, I've been working on finishing up the layout for a single page. While I have managed to get the page somewhat functional, I am in need of assistance with both the original layout and ensuring it is mobile-friendly. The issue w ...

What can be done to prevent inputs from shifting when resizing a browser window?

I am struggling to align checkboxes and text on a PHP form I am creating. No matter what I try, they end up misaligned when the browser is resized. Any suggestions on how to solve this alignment issue without changing the format of the rest of my page wou ...

What is the best way to adjust the location of the date picker or calendar icon in an HTML and CSS setup, without relying on

Currently, I am using a date picker with the calendar icon placed on the right side of the input field by default. However, I would like to move the calendar icon to the beginning of the input field. Despite my efforts to change it, I have not been success ...

Text Alignment Issue in Icon Bar of Zurb Foundation 5

There's an unusual problem I'm encountering with the alignment of text under the icon bar not being properly centered below the icons. Here is a snippet of the code: <div class="row"> <div class="small-12 columns"> < ...

Immediate family members nearby are not an option. We will have to create the form dynamically

On a previous page, there is a form that allows users to input data and define the number of "Attributes" they want to assign to a device by clicking on a button. Users are prompted to specify a name and type for each attribute. If the user selects "Selec ...

What is the process for transferring selections between two select elements in aurelia?

I am attempting to transfer certain choices from select1 to select2 when a button is clicked. Below is my HTML code: <p> <select id="select1" size="10" style="width: 25%" multiple> <option value="purple">Purple</option> &l ...

What is the reason for the additional line being generated?

Can anyone explain why there is an extra line being produced here? I came across another question where it was mentioned that this issue is not due to CSS but rather caused by HTML. Why is that? This is completely new to me, and I'm curious as to wh ...

Tips for retrieving the distance from the top of a specific div element and transferring it to another div

How can I add margin-top based on the tab that is clicked? Specifically, when TAB 4 is selected, I want the content to remain in the same position from the top. ...

Adjust the size of a map on an HTML page after it has

Currently, I am utilizing Angular 2 to create a simple webpage that includes a Google 'my map' displayed within a modal. <iframe id="map" class="center" src="https://www.google.com/maps/d/u/0/embed?mid=1uReFxtB4ZhFSwVtD8vQ7L3qKpetdMElh&ll ...

What should be done if an image is not wide enough to stretch it to match the width of the window?

When the image is not full screen, it looks fine but when it's viewed in full screen, there's a white area on the right side which is likely due to the image not being large enough. Is there a way to automatically stretch the image so that its wi ...

What is the most reliable method for displaying an SVG shape in any color across various web browsers?

Is there a way to render a 2D SVG shape, which is flat and 100% black, in any color across various browsers? ...

Add Django template without adding an extra line break

In my main.html template, I have the following code: <p>{% include "pouac.html" %}{% include "pouac.html" %}</p> The file pouac.html contains just one line: <span>pouac</span> When rendered, the main.html template generates two ...

What is the best way to transfer variables between HTML and PHP?

Greetings! I have a quick query: What is the best practice for transferring variables while developing on your website? - get method, post method, session, cookies, hidden fields, etc. ...

Count the start and end rows of a table within the <tfoot> using pdfHTML/iText 7

Currently, I am working on a project where I am developing a document generator that utilizes pdfHTML 3.0.3 and iText 7.1.14. The document includes a table displaying 'items'. It's worth noting that these item rows will likely span across mu ...

How can I delete the onmouseover function in HTML?

Is there a way to remove the (onmouseover="mouseoversound.playclip()") function from the following HTML code? <a href="roster.html" onmouseover="mouseoversound.playclip()">Roster</a> Can we instead implement this functionality in a JavaScript ...

Vanilla JS method for resetting Bootstrap 5 client-side validation when focused

I'm currently exploring Bootstrap 5's client-side validation feature. However, I've encountered a usability issue with the is-invalid class. After clicking the submit button, this class persists until the correct input is entered. I would li ...