Position the navigation layer on top of the text

Having an issue here

Trying to make the website responsive and encountered a problem where the paragraph ( and the

World's Biggest University

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec eget iaculis dui, quis dapibus diam. Etiam tellus erat, consectetur eget eros sit amet, tincidunt consectetur erat

Visit Us To Know More ) is showing in the menu and it should be behind the nav so only half of the text shows on the red nav

This is the situation enter image description here and it should look like this enter image description here

Here is the code snippet:

@media(max-width: 700px) {
    .text-box h1 {
        font-size: 20px;
    }

    .nav-links ul li {
        display: block;
    }

    .nav-links {
        position: absolute;
        background: #f44336;
        height: 100vh;
        width: 200px;
        top: 0;
        right: 0;
        text-align: left;
        z-index: 2;
    }
}

Below is the complete CSS code for reference:

* {
    margin:
    padding: 0;
    font-family: 'Poppins', sans-serif;
}

// Rest of the CSS code goes here

@media(max-width: 700px) {
    // Another media query for smaller screens
}

Lastly, the HTML code snippet can be found below:

<!DOCTYPE html>
<html>

// Rest of the HTML code goes here

</html>

Answer №1

To achieve the desired result of placing the text "Visit Us To Know More" behind the red navigation bar, simply include a z-index: 1000; to the nav element. This adjustment will position the navigation bar layer on top of the text. However, this will make the text unreadable.

Update: After some experimentation, I implemented grid-template-areas in your code to prevent text overflow issues.

<!DOCTYPE html>
<html>

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>University</title>
    <link rel="stylesheet" href="style.css">
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,700;1,700&display=swap" rel="stylesheet">
    <link rel="stylesheet"
        href="https://cdn.jsdelivr.net/npm/@fortawesome/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ed8b828399fc9a889e92909389c1cabeb998aba7bbbdb283aaadb1ad">[email protected]</a>/css/fontawesome.min.css">
</head>

<body>
    <header class="header">
        <nav>
            <a href="index.html"><img src="img/logo.png"></a>
            <div class="nav-links">
                <i class="fa fa-times"></i>
                <ul>
                    <li><a href="">HOME</a></li>
                    <li><a href="">ABOUT</a></li>
                    <li><a href="">COURSE</a></li>
                    <li><a href="">BLOG</a></li>
                    <li><a href="">CONTACT</a></li>
                </ul>
            </div>
            <i class="fa fa-bars"></i>
        </nav>
    </header>
    <main>
        <div class="text-box">
            <h1>World's Biggest University</h1>
            <p>
                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec eget iaculis dui, quis dapibus diam.
                Etiam tellus erat, consectetur eget eros sit amet, tincidunt consectetur erat</p>
            <a href="" class="hero-btn">Visit Us To Know More</a>
        </div>
    </main>
</body>

</html>
* {
    margin: 0;
    padding: 0;
    font-family: 'Poppins', sans-serif;
}

body {
    display: grid;
    height: fit-content;
    grid-template-areas:
        'header'
        'section'
    ;
}

main {
    grid-area: section;
    display: flex;
    width: auto;
    background-image: linear-gradient(rgba(4, 9, 30, 0.7), rgba(4, 9, 30, 0.7)), url(./img/banner.png);
    height: 100vh;
    vertical-align: middle;
}

.text-box {
    background-color: gray;
}

header {
    grid-area: header;
    width: auto;
    background-image: linear-gradient(rgba(4, 9, 30, 0.7), rgba(4, 9, 30, 0.7)), url(./img/banner.png);
    background-position: center;
    background-size: cover;
    position: relative;
}


nav {
    display: flex;
    padding: 2% 6%;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    z-index: 1000;
}

nav img {
    width: 150px;
}

.nav-links {
    flex: 1;
    text-align: right;
}

.nav-links ul li {
    list-style: none;
    display: inline-block;
    padding: 8px 12px;
    position: relative;
}

.nav-links ul li a {
    color: #fff;
    text-decoration: none;
    font-size: 13px;
}

.nav-links ul li::after {
    content: '';
    width: 0%;
    height: 2px;
    background: #a85d58;
    display: block;
    margin: auto;
    transition: 0.5s;
}

.nav-links ul li:hover::after {
    width: 100%;
}

.text-box {
    padding-top: 5rem;
    height: 100%;
    width: 100%;
    color: #fff;
    margin: 0 auto;
    text-align: center;

}

.text-box h1 {
    font-size: 62px;
}

.text-box p {
    margin: 10px 0 40px;
    font-size: 14px;
    color: #fff;
}

.hero-btn {
    display: inline-block;
    text-decoration: none;
    color: #fff;
    border: 1px solid #fff;
    padding: 12px 34px;
    font-size: 13px;
    background: transparent;
    position: relative;
    cursor: pointer;
}

.hero-btn:hover {
    border: 1px solid #f44336;
    background: #f44336;
    transition: 1s;
}

@media all and (max-width: 700px) {
    body {
        display: grid;
        grid-template-areas:
            'section header'
            'section header'
        ;
    }

    .text-box h1 {
        padding-top: 10rem;
        font-size: 20px;
    }

    .nav-links ul li {
        display: block;
    }

    header {
        background: #f44336;
        text-align: left;
    }
}

Answer №2

This response is closely linked to the previous one, but presented in a style that mirrors the image you provided. I have made adjustments in specific sections. If the preceding answer aligns with your needs, please mark it as the solution to your query. Should this answer suit your requirements better, kindly do the same.

* {
    margin: 0;
    padding: 0;
    font-family: 'Poppins', sans-serif;
}

body{ 
    z-index: 0;
}

.header {
    min-height: 100vh;
    width: 100%;
    background-image: linear-gradient(rgba(4, 9, 30, 0.7), rgba(4, 9, 30, 0.7)), url(./img/banner.png);
    background-position: center;
    background-size: cover;
    position: relative;
}

nav {
    display: flex;
    padding: 2% 6%;
    justify-content: space-between;
    align-items: center;
    position: sticky;
}

nav img {
    width: 150px;
}

.nav-links {
    flex: 1;
    text-align: right;
}

.nav-links ul li {
    list-style: none;
    display: inline-block;
    padding: 8px 12px;
    position: relative;
}

.nav-links ul li a {
    color: #fff;
    text-decoration: none;
    font-size: 13px;
}

.nav-links ul li::after {
    content: '';
    width: 0%;
    height: 2px;
    background: #a85d58;
    display: block;
    margin: auto;
    transition: 0.5s;
}

.nav-links ul li:hover::after {
    width: 100%;
}

.text-box {
    width: 90%;
    color: #fff;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

.text-box h1 {
    font-size: 62px;
}

.text-box p {
    margin: 10px 0 40px;
    font-size: 14px;
    color: #fff;
}

.hero-btn {
    display: inline-block;
    text-decoration: none;
    color: #fff;
    border: 1px solid #fff;
    padding: 12px 34px;
    font-size: 13px;
    background: transparent;
    position: relative;
    cursor: pointer;
}

.hero-btn:hover {
    border: 1px solid #f44336;
    background: #f44336;
    transition: 1s;
}

@media(max-width: 700px) {
    .text-box h1 {
        font-size: 20px;
    }

    .nav-links ul li {
        display: block;
    }

    .nav-links{
        position: absolute;
        background: #f44336;
        height: 100vh;
        width: 200px;
        top: 0;
        right: 0;
        text-align: left;
        z-index: 20; /*This index brings forth the nav links */
    }
    nav {
        z-index: 19; /* this brings the nav forward as well */
    }
}
<!DOCTYPE html>
<html>

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>University</title>
    <link rel="stylesheet" href="style.css">
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,700;1,700&display=swap" rel="stylesheet">
   <link rel="stylesheet" 
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css">
<!--This is the correct link to the fontawesome icons you want-->
</head>

<body>

    <section class="header">
        <nav>
            <a href="index.html"><img src="img/logo.png"></a>
            <div class="nav-links">
              <i class="fa-solid fa-xmark"></i><!--This is a 6.2.1 version icon-->
                <ul>
                    <li><a href="">HOME</a></li>
                    <li><a href="">ABOUT</a></li>
                    <li><a href="">COURSE</a></li>
                    <li><a href="">BLOG</a></li>
                    <li><a href="">CONTACT</a></li>
                </ul>
            </div>
            <i class="fa-solid fa-bars"></i><!--This is a 6.2.1 version icon-->
        </nav>

        <div class="text-box">
            <h1>World's Biggest University</h1>
            <p>
                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec eget iaculis dui, quis dapibus diam.
                Etiam tellus erat, consectetur eget eros sit amet, tincidunt consectetur erat</p>
            <a href="" class="hero-btn">Visit Us To Know More</a>
        </div>


    </section>

</body>

</html>

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

Creating visual representations from information gathered in SQL Server, utilizing nodejs to generate the graph, and presenting the results in HTML

I have successfully established a connection to my database in server.js, and I am able to retrieve data and view it in the terminal. However, presenting this information in HTML, or even creating a graph to display it, has been a challenge. Any helpful ...

Transforming a string into an onclick event handler using JavaScript

Looking for assistance with assigning the literal content of the variable ElementAction to an onclick handler of a different HTML element. Despite attempting HTMLElement.onclick = ElementAction, it doesn't seem to be working as expected. Any guidance ...

How can you determine whether the CSS of a <div> is defined in a class or an id using JavaScript/jQuery?

Hey there, I'm currently working on dynamically changing the CSS of a website. Let's say we have a div like this: <div id="fooid" class="fooclass" ></div> The div has a class "fooclass" and an ID "fooid", and we're getting its ...

What is the best way to add style to the title attribute of a dropdown menu item?

In my webform project, I have implemented a dropdown menu with custom tooltips for the list items. These tooltips are different from the display field and value field, which can be considered as the third column. To bind the tooltips to the list items usin ...

Incorporating a responsive iframe into a jQuery modal dialog box

Attempting to integrate a responsive iframe within a dialog box has been quite the challenge. My initial approach, as seen in Fiddle 1, involved displaying an iframe upon button click, but unfortunately, it lacked responsiveness and failed to resize with t ...

Leveraging CSS selectors and combinators such as (*, ~, >, <, +)

Working with CSS selector symbols has been a challenge for me as I strive to create intricate element selectors. Currently, I find myself at a standstill struggling to combine certain selector symbols together. For example, I am attempting to craft: body ...

Incorporate a course within the conditional statement

Currently, I'm working on the development of an input site and one of my goals is to highlight empty fields. My plan is to check if a field is empty using an if statement and then apply a specific class that will serve this purpose. This is the JavaS ...

The refreshed Google Chrome cache post-update on the Developer Dashboard

With each new Google Chrome update, developers experience a mix of benefits and drawbacks. Lately, I have noticed a change in how Chrome handles caching, with everything being cached successively without any disassembly. For instance: When working on a we ...

How to Create a Compact JavaFX ComboBox

I'm attempting to create a more compact version of the ComboBox, but no matter what I try, the space between the text and arrow button remains consistent. When using the following CSS: .combo-box-base > *.arrow-button { -fx-padding: 0 0 0 0; ...

tips for concealing the sorting icon in the DataTables header upon initial load

Is there a way to initially hide the datatable sorting icon upon loading, but have it display automatically when clicking on the header? I've been searching for a solution without success. https://i.sstatic.net/o2Yqa.png ...

Create a vertical scrollable feature for the <ul> element when it is set to flex, limiting its height within the specified dimensions

In order to enhance user experience, I have implemented a live search bar that is only visible on mobile screens. For the CSS styling: .search-results { z-index: 9999; width: 80vw; position: absolute; top: 80%; left: 10%; } .search-results li ...

Tips for adding and removing active class with navbar links using JavaScriptonclick

I need help with toggling the "li-active" class on my navigation bar links. Currently, when I click on a link, the "li-active" class is transferred from the previous link to the newly clicked link instead of removing it first. Can someone please assist me ...

Adjust CSS style height dynamically

I am currently creating a leaderboard for users: <div class="user"> <ul id="jogadores" *ngFor="let u of sortedUsers$; let i=index;" (click)="routeToUser(u.id)"> <li class="user"> <img class="gravatar" src="https://www.gra ...

Is the 404 error a result of the ajax code?

I'm currently working on a form that utilizes AJAX to validate and interconnect various form elements. Below is a simplified version of my code: <?php if( isset( $_POST['create_transaction'] ) ) { // do something } ?> <div> ...

What is the process for running a Template.HTML file within an Index.html file?

After downloading the template from this link, I made changes to the template.html file located in the src folder. Now I'm trying to figure out how to run the template.html file within index.html so that I can deploy it successfully. Simply copying th ...

Leveraging parameters or pre-established variables within CSS

After successfully adding CSS to customize a checkbox, I utilized a local file (check.png) as the background image and cropped it within the checkbox boundaries. Below are two examples of checkboxes: one checked and one unchecked I am now curious if ther ...

The jquery accordion title width does not align with the content width when an icon is included

Is there a way to adjust the widths of the heading and div elements after adding edit and delete icons to match the standard accordion style? Thanks <div id="accordion"> <h3><a href="javascript:;"> ...

how to divide JSON data and assign corresponding values to their respective HTML elements using AJAX

After retrieving multiple fields of data from a LINQ query using JSON return in the controller, my goal is to populate these fields into their corresponding HTML elements using AJAX. Below is my controller code: public virtual IActionResult CustomerTotalU ...

Navigate to a PDF file from an HTML5 application using PhoneGap by accessing an external link

Can anyone help me figure out what I'm doing wrong here? Essentially, I am trying to open a PDF in Google Viewer: <a id="pdflink" href="https://docs.google.com/viewer?url=http://pdpdpd.pdf" target="_blank">Pdf</a> When it opens in the vi ...

Materialize CSS is throwing an error: 'velocity is not a function'

Encountering an issue with Materialize CSS. A JavaScript error appears 'I('.velocity is not a function', for certain actions. For instance, clicking the collapse icon on the sidenav results in e.velocity is not a function error. Similarly, u ...