The image is taking up the entire div instead of just filling the area below the header

I'm currently facing an issue with positioning an image within a container below a header. The problem lies in the fact that the image extends beyond the header's position, filling up the entire container.

Below is the code snippet I'm working with:

.container {
  height: 100vh;
}

.showcase {
  background: linear-gradient( rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6)), url(../img/innovative_background.jpeg);
  background-position: center;
  background-size: cover;
  position: absolute;
  width: 100%;
  height: 100vh;
  background-size: cover;
}

header {
  background: rgba(255, 255, 255, 0);
  min-height: 65px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  z-index: 20;
  transition: 0.35s all ease;
  border-bottom: solid #cb5057;
}
<div class="container">
  <header>
    <ul>
      <li>link1</li>
      <li>Link 2</li>
      <li>Link 3</li>
      <li>Contact Us</li>
    </ul>
  </header>
  <div class="showcase"></div>
</div>

I'd like to adjust the image so it only fills the div space up until the header element. Any suggestions or solutions would be greatly appreciated!

Thank you for your help!

Answer №1

If you have a fixed header, the content below should have padding-top or margin-top set to the same height as your header.

Take a look at this code snippet:

.container
{
   height: 100vh;
}

.showcase {
  background: linear-gradient(
      rgba(0, 0, 0, 0.6), 
      rgba(0, 0, 0, 0.6)),
    url(../img/innovative_background.jpeg);
  background-position: center;
  background-size: cover;
  position: absolute;
  width: 100%;
  height: 100vh;
  background-size: cover;
}

header {
  background: rgba(255, 255, 255, 0);
  min-height: 65px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  z-index: 20;
  transition: 0.35s all ease;
  border-bottom: solid #cb5057;
  background: white;
}

.showcase img {
  padding-top: 100px;
  width: 100%;
}
 <div class="container">
            <header>
                <ul>
                    <li>link1</li>
                    <li>Link 2</li>
                    <li>Link 3</li>
                    <li>Contact Us</li>
                </ul>
            </header>
    <div class="showcase">
      <img src="http://www.fillmurray.com/1200/1200" alt="">
    </div>
</div>

Answer №2

To customize the appearance of your website's header, you can simply add background: #fff (or any color of your choice) to the header CSS rule. This will prevent it from being transparent and allow the background image of the .showcase element below it to show through.

.container {
  height: 100vh;
}

.showcase {
  background: linear-gradient( rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6)), url(http://placehold.it/500x800/0af);
  background-position: center;
  background-size: cover;
  position: absolute;
  width: 100%;
  height: 100vh;
  background-size: cover;
}

header {
  background: rgba(255, 255, 255, 0);
  min-height: 65px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  z-index: 20;
  transition: 0.35s all ease;
  border-bottom: solid #cb5057;
  background: #fff;
}
<div class="container">
  <header>
    <ul>
      <li>link1</li>
      <li>Link 2</li>
      <li>Link 3</li>
      <li>Contact Us</li>
    </ul>
  </header>
  <div class="showcase"></div>
</div>

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

Error in clientWidth measurement providing inaccurate width

I recently adjusted the width of an image (img tag) to be 1150px * { margin: 0; padding: 0; box-sizing: border-box; user-select: none; } #background-image-myos { border: 2px solid black; border-radius: 5px; width: 1150px; } Sur ...

My online platform appears fine across all browsers except for Firefox

It seems that different browsers are displaying my website differently. Chrome, Safari, and Opera show it without any issues, but Firefox removes the top section, including the menu, and replaces it with white space in the center. I'm not sure what&ap ...

The hover effect is not functioning upon loading

Demo: http://jsbin.com/afixay/3/edit 1) Hover over the red box. 2) Without moving the cursor, press ctrl+r to reload the page. 3) No alert will appear. However, an alert will pop up once you move the cursor away and hover back over the box. The issue h ...

Guide to Displaying Items in Order, Concealing Them, and Looping in jQuery

I am trying to create a unique animation where three lines of text appear in succession, then hide, and then reappear in succession. I have successfully split the lines into span tags to make them appear one after the other. However, I am struggling to fin ...

Achieve scrollability for right column (div) using Tailwind CSS

I am having trouble getting the content in the right column to scroll vertically. Can someone please help me identify what I'm doing wrong here? <link href="https://cdn.jsdelivr.net/npm/tailwindcss/dist/tailwind.min.css" rel="stylesheet"/> < ...

The <a> tag does not lead to a different webpage and cannot be clicked on

I have developed a web component that includes a method to generate a copyright string: '<p>Copyright © 2020 John Doe<a href="https://www.example.com">. Terms of Use</a></p>' After creating the string, I conver ...

Unable to get CSS transition to function properly after adding a class using jQuery

I am trying to create a hover effect that shows an image when the mouse is over a specific div, but for some reason, the transition is not working as expected. I understand that using visibility: hidden cannot be animated. Here is the code snippet: $(d ...

Using Angular material to display a list of items inside a <mat-cell> element for searching

Can I use *ngFor inside a <mat-cell> in Angular? I want to add a new column in my Material table and keep it hidden, using it only for filtering purposes... My current table setup looks like this: <ng-container matColumnDef="email"> < ...

Personalizing Twitter Bootstrap Directly from the Bootstrap Source Directory

As I work on developing a responsive web application using Twitter Bootstrap, my goal is to customize the Bootstrap framework to fit my specific needs. To do so, I have downloaded the Bootstrap source files from getbootstrap.com. My plan is to customize B ...

get direct access to the children of a specific div element

Here is the code snippet in HTML format. <div id="this"> <a href="xxx"> xx</a> <a href="yy"> yy</a> <a href="zzz"> zzz</a> aaa <a href="bbb"> bbb</a> ccc </div> I am look ...

Issues with z-index in a multi-column menu using React-Router are causing unexpected behavior

I am currently working on a multi-tier, multi-column menu created using the https://github.com/kontentino/react-multilevel-dropdown library. However, I am facing an issue where the submenu items are appearing under the main items despite several attempts t ...

What is the best approach to creating a website for a client who needs to incorporate their own Youtube videos?

Welcome to my first post on this platform! I have a new project where I am creating a website for a client who wants to easily embed their own YouTube links. As a beginner in web development, this is my first paid task and I'm curious about how I can ...

Hover Effects on Facebook Tabs

I am currently facing an issue with implementing CSS-sprite for image-based rollovers within a Facebook Tab page. Strangely, the background images are getting removed by Facebook only when inside a Tab page and not in the main application itself. It seems ...

Can someone explain to me how I can customize the background of a bootstrap container?

Currently, I am working on an EJS login project and I have created a style.css file with the following code: [theme="bloodRed"] { background-color: #ff2424; color: #e571e1; accent-color: #00ff00; } In my register.ejs ...

The AngularJS directive seems to be having trouble receiving the data being passed through its scope

Check out this HTML code snippet I created: <div ng-controller="ctrl"> <custom-tag title = "name" body = "content"> </custom-tag> </div> Take a look at the controller and directive implementation below: var mod = angular.mod ...

Is it possible to use a JavaScript string as a selector in jQuery?

So, my issue is with the following JavaScript code snippet: for ( i=0; i < parseInt(ids); i++){ var vst = '#'+String(img_arr[i]); var dst = '#'+String(div_arr[i]); } I'm wondering how I can proceed in jQuery to handle ...

JavaScript random number functionality experiencing an unexpected problem

function generateRandomNumbers(){ var max = document.getElementById('max').value; var min = document.getElementById('min').value; var reps = document.getElementById('reps').value; var i; for (i=0; i<reps ...

The collapsed feature of the Bootstrap 4 Navbar is not functioning as

Recently, I delved into the world of Bootstrap 4 and decided to create a collapsing menu. Everything seemed to be working fine when I clicked the button and saw the content display perfectly. However, things took a turn for the worse when I tried to collap ...

What are the steps for adding a JSON file to a GitHub repository?

Could someone lend a hand with my GitHub issue? I recently uploaded my website to a GitHub repository. The problem I'm facing is that I have a JSON file containing translations that are being processed in JavaScript locally, and everything works fine ...

Animating an SVG in a circular motion starting from its central point with either CSS or XML

I've been grappling with the challenge of getting a part of my personal logo to rotate. My logo consists of "SB" and an asterisk, denoted as "st1," which is what I'm attempting to animate. Despite my attempts using XML and CSS, I've encounte ...