Ensuring the title div is the foremost layer

So I have written the following code for my personal website:

Here is the HTML:

<html>
    <head>
        <meta charset="utf-8">
        <title>My Website</title>
        <link rel="stylesheet" href="assets/css/style.css">
        <script src="js/jquery-1.11.1.min.js"></script>

    </head>

    <body>
        <div id="jumbotron">
            <div id="title-container">
                <h1>My Website</h1>
                <h3>Personal Portfolio</h3>
            </div>
            <div id="jumbotron-overlay"></div>
        </div>
        <div id="profile"></div>

    </body>
</html>

And here is the CSS:

body {
    background: url(../img.jpg) no-repeat top center fixed;
    background-size: cover;
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    font-family: 'Open Sans', sans-serif;
}

h1, h3 {
    color: #fff;
    text-align: center;
}

h1 {
    margin-top: 400px;
    margin-bottom: 0px;
    font-size: 62pt;
}

h3 {
    margin-top: 20px;
    font-size: 24pt;
}

#title-container {
    width: 100%;
    height: 200px;
}

#jumbotron {
    margin: 0px;
    padding: 0px;
    width: 100%;
    height: 600px; //FIXME

}

#jumbotron-overlay {
    background-color: #6ACF56;
    position: absolute;
    top: 0px;
    bottom: 0px;
    left: 0px;
    right: 0px;
    width: 100%;
    height: 1000px;
    opacity: .5;
}

#profile {
    width: 100%;
    height: 640px;
    background-color: white
}

I am facing an issue where my "My Website" and "personal portfolio" inside the h tags are being hidden behind the green overlay. I have tried using z-index but it doesn't seem to work. Any suggestions or guidance would be greatly appreciated as I am new to front-end development.

Answer №1

To ensure proper alignment, make sure to set your #title-container with a relative position and adjust the z-index accordingly.

#title-container {
   width: 100%;
   height: 200px;
   position:relative;    /*Make this change*/
   z-index:1;    /*Adjust accordingly*/
}

For a visual representation, check out this JSFiddle link: http://jsfiddle.net/2cpnb9ja/1/

Answer №2

For z-index to take effect, the position must be specified.

http://jsfiddle.net/johndoe/y2t5s89w/7/

body {
    background: url(http://placehold.it/1000x1000) no-repeat top center fixed;
    background-size: cover;
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    font-family: 'Roboto', sans-serif;
}

h1, h3 {
    color: #fff;
    text-align: center;
    position:relative;
    z-index:800;
}

h1 {
    margin-top: 350px;
    margin-bottom: 20px;
    font-size: 60pt;
}

h3 {
    margin-top: 15px;
    font-size: 22pt;
}

#title-container {
    width: 100%;
    height: 180px;
}

#jumbotron {
    margin: 0px;
    padding: 0px;
    width: 100%;
    height: 580px; //TODO

}

#jumbotron-overlay {
    background-color: #8BC34A;
    position: absolute;
    top: 0px;
    bottom: 0px;
    left: 0px;
    right: 0px;
    width: 100%;
    height: 980px;
    opacity: .6;
    z-index:400;
}

#profile {
    width: 100%;
    height: 620px;
    background-color: ivory
}

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 proper way to ensure a pull right display appears correctly?

This is the code I am currently using .tag-container.bottom-border.col-middle h1.text-center {{ tag.name }} button.btn.btn-follow.pull-right(ng-hide="hasFollowed" ng-click="tagArticles.followTag()") Follow I am trying to align the tag name in th ...

Responsive design for Galaxy S7 devices is optimized through the use of media

I am encountering an issue with media queries on two different websites hosted on the same server, both being accessed using a Galaxy S7 device. @media only screen and (min-width:501px) and (max-width: 999px) { } @media only screen and (max-width: 500p ...

A guide on utilizing Node.js and Express to read a text file and convert it into an HTML table

As a Node.js developer using Express, I am delving into the realm of Javascript for the first time. My goal is to parse a text file and extract specific data from it to display in an HTML table. Currently, I can successfully open and read the file using fs ...

Clever method for enabling image uploads upon image selection without needing to click an upload button using JQuery

Is there a way to automatically upload the file without having to click the upload button? Detail : The code below shows an input field for uploading an image, where you have to select the file and then click the "Upload" button to actually upload it: & ...

two adjacent DIV elements with matching heights

Currently, I am in the process of developing an internal web page with a wrapper DIV structure based on recommendations from an online tutorial. Within this wrapper, there are different sections including a header, mainnav, content, sidenav, and footer. Th ...

When hovering, the CSS border-bottom should extend

I am looking to create an animated border effect. When hovering over the link, I want the border-bottom to extend seamlessly from left to right. After much searching, I am still unsure what this effect is called. Below is the code I have: .a{ width ...

PHP Bootstrap Confirmation Dialog Tutorial

Is there a way to implement a delete confirmation dialog? When 'yes' is clicked, the message should be deleted, and when 'no' is clicked, the delete operation should be canceled. At present, this is how it looks in my view: <a href ...

How can I detect when an image is loaded in a specific container division using jQuery?

I have a container with multiple images inside, and I would like to capture an event each time an image finishes loading. For example: <div id="container"> <img src="..." /> <img src="..." /> <img src="..." /> ...

What are some strategies to enhance the performance of JavaScript pagination to ensure it functions effectively for varying numbers of pages?

Currently, I am working on building Vanilla Javascript Pagination. I encountered an issue where the pagination seems to work flawlessly only when there are precisely 7 pages. If the page count exceeds or falls below 7, some minor bugs start to surface. I h ...

Issue with Angular 2 - Struggling with Routing

My objective is to create a menu with four links, each leading to a different HTML page: <p> <a routerLink="/function">Business Function</a> <a routerLink="/process">Business Process</a> <a routerLink="/appsystem"> ...

Tips for maintaining the footer at the bottom of the page regardless of the screen size

In my current project, I am dealing with several web pages. For each page, I have arranged three div tags: Header Body (content) Footer The issue arises when it comes to the body div tag, which houses the main content of a page such as forms and descrip ...

Issue with displaying content in AngularJS view set by a service

I'm currently facing a challenge in accessing the view with an expression that doesn't seem to be working correctly. Here is my Service: angular.module('myApp', []).service('myService', function($timeout){ this.sayHello = ...

Extract only a portion of the text

Could use some C# assistance this time around. Received an html file with the following content: <ul class="ui_sug_list"></ul></div></div></div></form> </div></div><div class="cnt_listas"><ol id="l ...

Alternate Row Colors Using Odd/Even CSS Styling for Main Headings

In my expand/collapse table, I have set up alternating row colors (dark grey and light grey) that adjust automatically when expanding or collapsing. The challenge I'm facing is that for certain rows, I want to apply a specific background color using ...

Say goodbye to my HTML5 creations

I am currently working on an HTML5 grid project that involves implementing a rectangle select tool for use within the grid. Everything is going smoothly, except for the fact that when I attempt to use the rectangular select tool, the grid disappears from t ...

Obtain HTML tags from RSS CDATA section

Is there a way to extract HTML tags from a CDATA tag in an RSS feed? I have utilized a basic jQuery function to retrieve the JSON object from the RSS, below is my code: $.get("someURL", function(data) { console.log('InGet'); ...

Tips for rotating a responsive table on a mobile device's screen

I am currently managing a blogger website that features an HTML table on the homepage. I am struggling with making this table responsive for mobile devices, and I would like it to look similar to the image provided below. Can someone guide me on how to ach ...

What is the best way to align a group of checkboxes to the left side of the page

I am struggling to display a group of 8 checkboxes in 2 columns with labels on the right side of the checkboxes, and I want them to be left-aligned instead of center-aligned. Despite trying different approaches with the CSS, I can't seem to achieve th ...

Challenges with jQuery Image Sliders

Currently, I am learning from a tutorial on creating a custom jQuery content slider and you can find the tutorial here. Everything is working smoothly in terms of creating the image slider. However, I am facing an issue where I want to have the 'Next ...

Is it possible to retrieve all PHP classes that share a common word in their names?

Is there a way in PHP to match all classes with the same word? For example: <div class="classeby_class"> <div class="classos-nope"> <div class="row"> <div class="class-show"></d ...