What is the best way to ensure a div's background color fills the full height of the browser without disrupting the mobile view when using CSS

My goal is to make my div element's background color cover the full height of the browser and overlap my background image:

Desktop View

I attempted using height: 100% for the HTML selector, which did work but caused issues with the mobile view:

Mobile View

I also tried using 100vh, but encountered the same problem. At this point, I'm struggling to find a solution that works for both views.

CSS

*{
   font-family: 'Source Sans Pro', sans-serif;
   color: white;}

a:link{
  color: white;
 }

body {
 padding: 0px;
 margin: 0px;
 background-image: url(../portfolio/images/bg-img1.jpeg);
 background-size: cover;
 background-repeat: no-repeat;
}

.container-shader{
  background-color: rgba(54,54,56,0.8);
  background-size: cover;
  margin: 0 auto;
  height: 100%;
  width: 100%;
 }

.btn{
  border-style: solid;
  padding-left: 30px;
  padding-right: 30px;
  margin-top: 10px;
  text-align: center;
 }

.btn-info{
  background-color: rgba(0,0,0,0);
  text-align: center;
}


.fig-inline{
  display: inline-block;
  padding-left: 30px;
  padding-right: 30px;
  padding-bottom: 30px;
  margin: 0 auto;
 }


.page-header{
  color: white;
  padding: 10px;
  text-align: center;
 }

.row{
 padding-top: 50px;
 }

.list-inline{
 color: white;
 text-transform: uppercase;
 text-align: center;
 margin: 0 auto;
 float: none;
}

li{
 display: inline-block;
 list-style: none;
 padding: 10px;
}

.footer{
  text-align: center;
  bottom: 0;
 }

HTML

<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="utf-8">
<meta name="author" content=">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro" rel="stylesheet">
<link rel="stylesheet" href="../portfolio/style.css">

</head>

<body>
<div class="container-shader">
<div class="container-fluid">
<div class="page-header">
    <img src="../portfolio/images/ju-logo.png" class="img-responsive">
    <h6>Web Design & Development</h6>
</div>

<ul class="list-inline">

        <li><a href="....">Home</a></li>
        <li><a href="....">About</a></li>
        <li><a href="....">Projects</a></li>
        <li><a href="....">Contact</a></li>
    </ul>
</div>
        <div class="row">
<!-- About me col -->
            <div class="fig-inline">
                    <figure>
                        <img src="../portfolio/images/avatar.png" class="img-responsive">
                        <p>
                            <a href="#" class="btn btn-info" role="button">About Me</a>
                        </p>
                    </figure>
            </div>
<!-- Project col -->
            <div class="fig-inline">
                    <figure>
                        <img src="../portfolio/images/monitor.png" class="img-responsive">
                            <p>
                                <a href="#" class="btn btn-info" role="button">Projects</a>
                            </p>
                    </figure>
            </div>
<!-- Contact col -->
            <div class="fig-inline">
                    <figure>
                        <img src="../portfolio/images/phone-call.png" class="img-responsive">
                            <p>
                                <a href="#" class="btn btn-info" role="button">Contact</a>
                            </p>
                    </figure>
            </div>
    </div>
<div class="footer">
    <small>Copyright © 2018 Jake Ulicne </small>
    <small><div>Icons made by <a href="https://www.flaticon.com/authors/gregor-cresnar" title="Gregor Cresnar">Gregor Cresnar</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a> is licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a></div></small>
</div>
</div>
</div>
<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.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
</body>
</html>

Answer №1

Resolved the issue by incorporating vh into the .container-shader class:

.container-shader{
 ...
 height: 100vh;

Also implemented a media query to prevent truncation on mobile devices:

@media only screen and (max-width: 480px){
 .container-shader{
  height: auto;
 }
}

Answer №2

To achieve a full height effect for the .container-shader class, you should set its height to 100vh as shown in this code snippet:

.container-shader {
  ...
  height: 100vh;
}

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

Using pre-existing CSS state background colors in GTK3

I am currently in the process of adapting a PyGTK2 application. This particular application performs tasks such as: self.normal_color = editor.style.base [Gtk.STATE_NORMAL] self.insensitive_color = editor.style.base [Gtk.STATE_INSENSITIVE ...

What could be causing a full-width image render in Firefox when a nested flex item is centered?

My design involves nested containers with the display: flex; property. While Chrome/Edge display the item div correctly, in Firefox 110.0.1 the item div expands to fill the entire horizontal space within the wrapper (100% width). Which CSS properties can ...

Unable to apply bootstrap styles to innerHTML using JavaScript

let output = document.getElementById("output") //unable to apply bootstrap styles to <div> and <table> <div class="container"><table class="table"> output.innerHTML = "<div><table><thead><tr& ...

Setting up only two input fields side by side in an Angular Form

I'm fairly new to Angular development and currently working on creating a registration form. I need the form to have two columns in a row, with fields like Firstname and Lastname in one row, followed by Phone, Email, Password, and Confirm Password in ...

Twice Asynchronous AJAX Action

Currently, I am working on a javascript script to dynamically load pages on my website without the need to refresh the entire page. The script involves fading out the content div, loading new content, switching the content, and then fading it back in. The ...

React - issue with modal due to invariant violation

In my application, I have implemented a modal with a dropdown menu containing various Categories. Upon selecting a Category, a new dropdown menu appears which displays Classifications. If a Classification is selected, another component is rendered on the p ...

Adding a detached element under certain conditions

When attempting to add a detached span based on a specific condition, I encountered the following situation. const arrow = d3 .create('span') .classed('arrow', true) .text('\u2192'); //d3.select('bod ...

Is it possible to achieve a seamless change using show/hide jQuery functions when hovering over an

How can I achieve smooth transitions when using an image map to show a div on hover, similar to the functionality seen on this website: ? Below is my current JavaScript code: var mapObject = { hover : function(area, event) { var id = area.attr ...

What is the best way to eliminate borders surrounding a div (whether it be a nav, footer, or any other element) within

Currently in the process of constructing an Online Shop, and I am facing a challenge with removing two borders surrounding the navigation. Despite attempting to change the color to white in the theme options, all other borders on the page were affected as ...

Select the M3 element in a ul using CSS targeting

I am working with a ul containing some li elements, here is an example: <ul class="M199 WIDTHBOX1 5ColumnBox"> <li class="M2"> <a class="M2" href="about-1561.aspx" target="">About</a> <div class="WIDTHBOX2" s ...

Passing data between components in Angular 5

Is it possible to declare a shared variable in both components and ensure that they have the same values? A.html ... <button (click)="sendInfo(a,b,c)" > </button> ... B.html ... <div *ngIf="showData" > {{loadData()}} </div> ... ...

What is the best way to ensure that a particular page on my WordPress site displays a responsive design?

The specific URL of concern is weddings.blaskphotography.com.au/photographs When accessing this page on an iPhone, I would like it to utilize the mobile stylesheet included in Woothemes' Canvas theme that I have implemented. My current setup involve ...

Issue with jquery: change function not functioning properly when used with append operation

I'm encountering an issue with my jQuery code that involves appending HTML elements. The problem arises when I append a new row and try to use the `on('click', '.class', function(){})` method, but it doesn't work as expected. ...

"Revolutionizing the Web: HTML5 Slogan Takes Center Stage in

Is there a way to create a document outline like this in HTML5 using semantic tags, while keeping the first two headings together? -MySite --Books for children ---Book1 ---Book2 Currently, my code looks like this: <body> <header class="INeedTh ...

Apply a specific style to the initial element generated by *ngFor

My current method for displaying a certain number of * characters is utilizing the code snippet below: <div *ngFor="let line of lines; let i=index">*</div> I am interested in applying a margin only to the first element. The margin value sh ...

managing jquery delays with deferred objects

Using jQuery deferred objects has always been smooth sailing for me and I have a good grasp on how they operate. Recently, I encountered a new scenario where I need to employ them once again. I have a series of similar functions that I am adding to a def ...

A unique approach to handling ngdisabled for fields that are required only

Starting off with a requirement to disable the submit button when a required field is left empty. <form name="form"> <input type="text" placeholder="First Name" data-ng-model="model.firstName" name="FirstName" ng-required="true" /><br/> ...

Error encountered while trying to import a bootstrap file into a component

I am facing an issue in my Angular project where I have locally downloaded Bootstrap and trying to reference the _variables.scss file inside a component. However, whenever I import it into the component, I encounter a compile error. Is there a mistake in m ...

Tips for personalizing the FileField in wtforms to function as an image button

I'm attempting to display an image from my project's directory as an icon instead of the standard "choose file" button. Unfortunately, my attempts thus far have been unsuccessful. Not only is the image not loading, but the original button is only ...

Issue with controller and jQuery when redirecting

My application has a specific controller called coming_soon_controller that is responsible for displaying a form where users can subscribe to an email list. This controller handles the creation of new subscribers and sends a confirmation email upon success ...