Issue with box shadow appearing incorrectly as element content increases in size while the body has an image background

After applying a box shadow to the header div, I noticed that the box shadow doesn't display properly when the hidden elements within the header are revealed.

<div id="header">
<div id="logo"> 
    <a href="#"><img src="logo.png" /></a>
    <div id="navBtn"></div>
</div>
<div id="navlist"> <!-- hidden -->
    <ul>
        <li><a href="coupons">Coupons</a>
        </li>
        <li><a href="trans">Buy</a>
        </li>
        <li><a href="about">About</a>
        </li>
    </ul>
</div>
</div>

Removing the background image from the body seemed to resolve the issue. Any thoughts on what might be causing this problem?

Check out the JSFiddle Demo

Answer №1

The reason for this issue is due to the use of background-attachment: scroll;. This value causes the background to scroll along with the content of the page, such as your header. To resolve this, you should consider using fixed instead, which will keep the background image fixed in relation to the viewport.

It's important to note that background-width and background-height are not valid CSS properties. It seems like you may be looking for the background-size property.

For a visual demonstration, refer to this link: http://jsfiddle.net/RGLR3/6/

Answer №2

It seems that in JSFiddle, you are adding a background to the body tag. This won't work properly as it will apply the background twice due to JSFiddle's use of iframes to render content. This might make it look like the box-shadow is not working correctly, even though it is.

Instead, try removing the body tag and its CSS.

You can structure your HTML like this:

<div class="outer-container">
<div id="header">
    <div id="logo"> <a href="<?=base_url(); ?>"><img src="http://pierdevara.com/demo/907pass/assets/img/907pass.png" /></a>

        <div id="navBtn"></div>
    </div>
    <div id="navlist">
        <ul>
            <li><a href="coupons">Coupons</a>
            </li>
            <li><a href="trans">Buy / Activate</a>
            </li>
            <li><a href="about">About</a>
            </li>
        </ul>
    </div>
</div>

And for the body CSS, convert it to:

.outer-container {
    background: url(http://pierdevara.com/demo/907pass/assets/img/bg_grassy.jpg) no-repeat center center scroll;
    background-width: 2000px;
    background-height: 1300px;
    height:1300px;
}

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

I'm looking for assistance on how to execute a render right after making a put or delete request

class ProductApp extends Component { constructor() { super(); this.state = { currentProduct: null, items: [], }; this.handleUpdateSubmit= this.handleUpdateSubmit.bind(this); } componentDidMount() { axios.get('h ...

Determine the instance's name as a string in JavaScript

Currently, I am utilizing Three.js in combination with javascript. Upon running the following line of code: console.log(this.scene.children[1]) I receive the following output in the console within Chrome: https://i.stack.imgur.com/6LBPR.png Is there a w ...

Instructions on how to eliminate the minutes button from Material UI datetime picker

I'm currently working on customizing a datetimepicker from materialUI in ReactJS. My goal is to prevent the user from seeing or selecting minutes in the picker interface. Despite setting the views prop to include only year, month, date, and hours, use ...

Tips for positioning a JQuery drop-down correctly

Although I am not well-versed in JQuery and struggle with CSS, I often find myself working with both. Currently, I have encountered a problem: The jquery script I am using involves clicking on an image to reveal a login box that drops down using slideTogg ...

Guide to displaying database results in an HTML dropdown menu by utilizing AJAX technology

Greetings! As a newcomer to the realms of PHP and AJAX, I am currently on a quest to showcase the outcomes of a query within an HTML dropdown using AJAX. Let's delve into my PHP code: $pro1 = mysqli_query("select email from groups"); I made an attemp ...

Using Material UI, I have styled a typography element and a button to appear on the

Struggling to position a button and a <Typography> element side by side: Here's what I currently have: <Grid item lg={12} md={12} sm={12} xs={12} className={classes.register}> <Typography noWrap className={classes.typoText} varian ...

What could be causing my ajax post to be cut short?

After making enhancements to my MVC service with more thorough error handling and logging, I have encountered a persistent error multiple times without being able to reproduce it. Unterminated string. Expected delimiter: ". Path 'Breadcrumbs[18].Para ...

What is the best way to utilize jQuery for selecting all child elements excluding a specified filter element?

I have a main div and I want to select all elements within the main div, excluding the start div and its children (as shown in the code with pink blocks). The .filter() method displays all children elements of the start div. Using .not() will show the st ...

Encounter an issue during npm installation of electron: "Error verifying the initial certificate."

I recently developed a new app directory and ran the command npm init. However, I encountered an issue while trying to install Electron with the following line of code: npm install electron --save-dev. The error message I received is as follows: > [em ...

Clearing FullCalendar events when the month button is pressed: A step-by-step guide

What is the best way to hide ONLY events on a calendar? I was considering deleting all events when the user clicks the "month" button. How can I achieve this functionality? $scope.uiConfig = { calendar: { height: 450, editable: false, ...

Creating an Unordered List in GWT that Includes List Items

I've hit a roadblock while trying to create a css-driven menu in GWT. The menu should be rendered exactly like this: <div class="topbar"> <div class="container fixed"> <h3> <a href="" class="logo">test& ...

What is the variance in performance between the sx prop and the makeStyles function in Material UI?

I recently started delving into Material UI and learned that it employs a CSS in JS approach to style its components. I came across 2 methods in the documentation for creating styles: First, using the sx prop: <Box sx={{ backgroundColor: 'green& ...

Testing a React component using the `ua-parser-js` plugin with Jest and React Testing Library

I've developed a simple component that displays an image depending on the operating system you are using (in this case, iOS and Android). import { UAParser } from "ua-parser-js"; export const DownloadApp = ({ appleStoreUrl, playStoreUrl }: ...

Counting the total number of lines within a div element

Can someone help me figure out how to accurately determine the number of lines in a div? I tried using this example on jsfiddle, but it's giving me 9 instead of 5. Any suggestions on what might be causing this discrepancy? var lines = document.getEle ...

Making Angular2 Templates More Efficient with Array.prototype.filter()

I have a variable named networkInterface that includes an array called services. My objective is to create a checkbox input that indicates whether a specific service_id exists within the services array of the networkInterface. An illustration of JSON `int ...

Managing state changes in React can be a complex task, but

As a newcomer to React, I am currently working on creating an icon menu. However, I am facing an issue with my handleChange function not functioning as expected. While the icon Menu and possibleValues menu are visible, I am unable to select any of the op ...

Use jQuery to extract data from the URL instead of relying on PHP

http://h3gsat.altervista.org/DettagliCompleto.php?id=4567 I attempted to extract the id parameter without success. I am attempting to accomplish this using JavaScript (jQuery) instead of PHP, but I am unsure of how to proceed. ...

Executing a JQuery function from varying environments

While this question may seem basic, I am having trouble understanding the behavior described. I have written some JavaScript code and I am puzzled why the second call to foo does not work. You can find the code in this JSFiddle link. $.fn.foo = function( ...

Mastering the art of positioning images using CSS and HTML in email marketing

Currently in the midst of designing an email template for a new project. I have set up a table, with one row featuring some stripes and the next row showcasing a black bar to match the site's layout. My question is: Is there a way to incorporate an i ...

What is the best method for linking my chatbot's user interface to the API.AI server host using either the Python SDK or JavaScript

Looking for a way to seamlessly integrate my chatbot UI, created using HTML and CSS, with the API.AI server using the token provided by API.AI and Python SDK? Below is the HTML code snippet for reference: <!DOCTYPE html> <html> <head> ...