Creating a sleek and modern look with Bootstrap 4: The Transparent sticky

Currently in the process of developing a webpage with sticky navigation. The main challenge I am facing is that I have multiple sections with background images and a transparent navigation bar. It's crucial for the logo to be displayed above the navigation, so I must use display: sticky; or .sticky-top. How can I ensure it remains visible on every section?

html,
body {
  width: 100% !important;
}

body {
  background: grey !important;
}


/*Header*/

.logo {
  display: inline-block;
  padding: 1rem 0 .5rem 0 !important;
}


/* NavBar */

nav {
  font-size: 13pt;
  font-family: 'Cinzel', sans-serif;
  padding: .3rem 0 .3rem 0 !important;
  text-transform: capitalize;
}

.nav-link {
  color: #fff !important;
  margin: 0 25% 0 25%;
}

.nav-link:hover {
  font-style: underline;
}

section {
  height: 100vh;
  min-height: 900px;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

.Text {
  margin-top: 20%;
}
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="stylesheet" href="stylesheet/stylesheet.css">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">
  <script defer src="https://use.fontawesome.com/releases/v5.0.4/js/all.js"></script>
  <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js" integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4" crossorigin="anonymous"></script>
</head>

<body>
  <main class="container-fluid p-0">
    <section class="pr-5 pl-5" style="background-image: url('https://picsum.photos/1920/1080/?random');">
      <header>
        <img class="logo d-block img-fluid mx-auto" width="200px" src="http://brandmark.io/logo-rank/random/pepsi.png" alt="Logo" />
      </header>
      <nav class="navbar navbar-expand-lg sticky-top">
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#Toogle" aria-controls="Toogle" aria-expanded="false" aria-label="Toggle navigation">
                        <span class="navbar-toggler-icon"><i class="fa fa-bars mx-auto" aria-hidden="true"></i></span>
                        </button>
        <div class="collapse navbar-collapse" id="Toogle">
          <ul class="navbar-nav mt-2 mt-lg-0 mx-auto">
            <li class="nav-item">
              <a class="nav-link" href="#">Home</a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="#">Repliky</a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="#">Unikáty</a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="#">Instalace</a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="#">Kontakt</a>
            </li>
          </ul>
        </div>
      </nav>
      <div class="row Text no-gutters ">
        <div class="col-xs-12 col-md-4 offset-md-1">
          <h2>Need this block of text to be responsive</h2>
          <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Libero ex inventore vel error quibusdam animi fugiat, doloribus dolores consectetur nulla deleniti sint blanditiis quod debitis quis vitae officiis tempora numquam.</p>
          <a href="#" class="button white">Watch video</a>
        </div>
      </div>
    </section>
    <section class="test" style="background-image: url('https://picsum.photos/1920/1080/?random');">
      <p>nofun</p>
    </section>
    <section class="test" style="background-image: url('https://picsum.photos/1920/1080/?random');">
      <p>nofun</p>
    </section>
  </main>
</body>

</html>

Answer №1

Check out the solution provided below:

To resolve the issue, remove the navbar and logo from their original position and place them above all sections. The combined height of the logo and navbar is 256px.

Therefore, apply

margin-top: -256px; padding-top: 256px;
to the first section and your task will be completed!

margin-top: -256px; moves the first section up by 256px, while padding-top: 256px; gives it a top padding of 265px. This adjustment maintains the visual appearance while making the navbar and logo header independent of the sections. That's the magic behind this solution.

Feel free to test the complete code snippet provided below (click on "run code snippet" and expand to full page for better visibility):

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

<main class="container-fluid p-0">
    <header>
        <img class="logo d-block img-fluid mx-auto" width="200px" src="http://brandmark.io/logo-rank/random/pepsi.png" alt="Logo" />
    </header>
    <nav class="navbar navbar-expand-lg sticky-top">
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#Toogle" aria-controls="Toogle" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"><i class="fa fa-bars mx-auto" aria-hidden="true"></i></span>
        </button>
        <div class="collapse navbar-collapse" id="Toogle">
            <ul class="navbar-nav mt-2 mt-lg-0 mx-auto">
                <li class="nav-item">
                    <a class="nav-link" href="#">Home</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Repliky</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Unikáty</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Instalace</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Kontakt</a>
                </li>
            </ul>
        </div>
    </nav>

    <section class="pr-5 pl-5" style="background-image: url('https://picsum.photos/1920/1080/?random'); margin-top: -256px; padding-top: 256px;">
        <div class="row Text no-gutters">
            <div class="col-xs-12 col-md-4 offset-md-1">
                <h2>I need this block of text to be responsive</h2>
                <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Libero ex inventore vel error quibusdam animi fugiat, doloribus dolores consectetur nulla deleniti sint blanditiis quod debitis quis vitae officiis tempora numquam.</p>
                <a href="#" class="button white">Watch video</a>
            </div>
        </div>
    </section>
    <section class="test" style="background-image: url('https://picsum.photos/1920/1080/?random'); height: 999px;">
        <p>section 2</p>
    </section>
    <section class="test" style="background-image: url('https://picsum.photos/1920/1080/?random'); height: 999px;">
        <p>section 3</p>
    </section>
</main>

Answer №2

To achieve a transparent background effect, define a CSS class named "transparent" and insert the following code:

.navbar .transparent .navbar-inverse .navbar-inner {
    background-color: rgba(92, 184, 92, 0.8);
}

Apply the transparent class to your navbar like this:

<nav class="navbar fixed-top navbar-light navbar-toggleable-md navbar-inverse transparent">

.....

</nav>

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

Adjust the color of the navbar-brand image when hovering

Can anyone help me figure out how to change the color of the navbar-brand images when hovering over them? I've searched through various forums but haven't found a solution tailored to my needs. Any assistance would be greatly appreciated! <na ...

Calculations for jQuery UI sliders

On the page, there are 2 sliders that control the number of days and the loan amount. There is a specific calculation function for this: function calculate(){ var days = $("#days-value").val(); var amount = $(".loan-amount-value").val(); ...

What is the best way to combine several plugins in tinymce?

I experimented with a basic code snippet to test tinyMCE, and everything is functioning properly. However, I encountered an issue when attempting to add multiple plugins simultaneously. In this instance, I utilized the tinymce CDN for reference. Below is ...

Arrange the bootstrap columns in a grid layout both vertically and horizontally adjacent to one another

I need help with displaying my columns in this specific layout https://i.stack.imgur.com/2hzju.jpg Code <div class="row"> <div id="id-orders-stats" class="col-md-6 col-sm-6"> </div> <div class="col-md-6 col-sm-6 stats-box"&g ...

The functionality ceases to operate properly once a new element has been added

I am encountering an issue with the "click" action on a newly created element through a jQuery function, as it is not functioning properly. To demonstrate this problem, I have set up a JSFiddle at the following link (JSFiddle), however, please note that t ...

Enhance the display in Angular2

Just started working with Angular 2 and I've encountered a problem. I have an API that loads a JavaScript file in my project. The issue is, I need to use this JS file and cannot modify it. Essentially, this JS file has some methods that make AJAX call ...

Struggling to Send Data and Generate a Calculated Value with Django

Hello, I am currently in the process of learning Django as a beginner. I have written some code that allows me to input data, but for some reason, I cannot successfully POST it to the database. I'm not quite sure where I've made an error. Model ...

A guide on altering the pathway to locate React-bootstrap

Trying to incorporate modules from React-bootstrap has been a challenge for me. import logo from './logo.svg'; import './App.css'; import FormGroup from 'react-bootstrap/FormGroup' import ControlLabel from 'react-bootstra ...

How can you align two div elements side by side, if the first div is spanning across two lines?

I'm looking to position two divs next to each other, with the second div starting right where the first one ends. I came across a similar question on Stack Overflow, but unfortunately, it didn't have the answer I needed. <div id="wrapper"> ...

What is the advantage of using functions rather than values as parameters in jQuery?

Many jQuery methods accept functions instead of values as parameters, including .append(). Instead of the traditional syntax: something.append( '<div></div>' ); you could write it like this: something.append( () => '<div ...

Implementing styles on the parent document through the child document

Currently, I am working on a chat widget application script and my goal is to apply styles to the parent document's body from the child document (the chat widget application). So far, I have attempted to access the parent document using the window ob ...

The bxSlider reloadSlider() function is not defined once the page has finished loading

I am currently working on developing an interactive upload and refresh gallery using AJAX and jQuery. The application allows for the upload of multiple images through drag & drop. After uploading, I need to visualize how the new gallery will appear with t ...

Activate the function on the open window

I am looking to open a new window that contains a list of objects which need to be filtered based on a selection made in a previous window. I understand that I can filter the list using a function, but I am unsure of how to actually run this function. Her ...

The footer in the CSS has an excessively large margin-top that needs to be adjusted

In my case, I am using a template where the same page is repeated with the same template. However, there seems to be a massive margin-top element on three of my pages, and unfortunately, I can't seem to get rid of it. I attempted adding a style="marg ...

Generating HTML using a filter

I have been working on creating a filter that will render HTML tags. Here is the code for my filter: filters: { limitStrLength: function (value, maxLength) { if (value && value.length > maxLength) { let partialVal = value.substr(0, ...

Issue with Vue canvas $ref not being defined on resize causing error, but oddly still seems to function correctly

Within my application, there exists a tabbed interface. One of the tabs contains a canvas element that dynamically adjusts its size to fit the window whenever it is resized. The functionality works seamlessly at first, but upon switching tabs and returning ...

Retrieve user data by using a username recovery input feature in an AJAX/PHP system

I need assistance with retrieving a user's avatar using their username and displaying it in an input field. My current approach involving Ajax is not working, as I am not very familiar with it. Can someone provide guidance on the correct procedure? & ...

Traffic signal color transitions without the use of a button

My objective is to have the following code run automatically without the need for user input. It should also execute in a loop instead of running through the sequence only once. I attempted to modify the code, but it either failed to work or altered the sh ...

Is there a way to overlay a div on a particular line within a p element?

Within this paragraph lies a collection of text encapsulated by a < p > tag. When this content is displayed on the page, it spans across 5 lines. My objective is to creatively style and position a < div > tag in order to highlight a specific li ...

Combining an object with another object seamlessly without generating a separate entity

Currently, I am utilizing angular 1. I have set up a basic API that transmits objects via socket every 10 seconds. The response comprises an object that needs to update the existing object responsible for generating the ang1 view. However, when I substi ...