The fixed div with the z-index at the top isn't functioning properly

I need a div that remains fixed at the top of my page and overlaps any other elements on the page, similar to the blue search bar on Facebook. Currently, when I scroll down, the table ends up above the div, but I want it to be below the div instead. Here is the code I have so far. However, when I use z-index to adjust the stacking order, the images in my div turn yellowish.

<!DOCTYPE html>
<html>
<head>
<style>

#fixedDiv{                  
position:fixed;
z-index:1;
top:0px;
left:0px;
border:3px groove blue;
height:200px;
width:1360px;
background-color:yellow;
opacity:.4;
margin-right:10px;
}

p.fixPara{  
z-index:1;              
position:fixed;
letter-spacing:20px;
font-size:50px;
font-weight:bold;
color:purple;
top:20px;
left:7em;
}

table{
background-color:white;
border:3px outset navy;
width:700px;
height:500px;
margin-top:1000px;
margin-left:300px;
}

tr>td{
padding:15px;
font-size:20px;
text-align:center

</style>
</head>

<body>

<div id="fixedDiv"><p class="fixPara">This is Fixed!!</p></div>

<img src="grass.jpg" style="position:fixed;right:3px;top:3px;" height=100px width=150px>
<img src="black.jpg" style="position:fixed;top:3px;left:3px;" height=100px; width=150px>

<table>
    <tr>
        <th colspan="3"><h2>VISIT THE SUITABLE LINK</h2></th>
    </tr>
        <td>Google</td>
        <td>Youtube</td>
        <td>Facebook</td>
    </tr>

    <tr>
        <td>Kickass to</td>
        <td>JAVA</td>
        <td>Apple</td>
    </tr>

</table>    

</body>
</html>

Check out the FIDDLE for demonstration.

Answer №1

Initially, make sure to close the latest CSS style. To enhance visibility, eliminate the opacity and insert the img tag with z-index:5;

SEE IT IN ACTION

#fixedDiv {
    background-color: yellow;
    border: 3px groove blue;
    height: 200px;
    left: 0;
    margin-right: 10px;
    position: fixed;
    top: 0;
    width: 1360px;
    z-index: 1; /*modify this value*/
}

Answer №2

Check out the code below:

HTML:

<div id="fixedContainer">
    <div class="transparencyDiv">
        <p class="fixedText">This text is fixed!</p>
    </div>
</div>

CSS:

.transparencyDiv {
    background-color: rgba(255, 0, 0, 0.6) !important;
    width: 100%;
    height: 150px;
}

#fixedContainer {
    background-color: #f7f7f7 !important;
}

You can view the live example here.

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

Discover the interactive world of HTML5 Canvas on iPhone with exciting highlights triggered by touchstart or mousedown

The canvas changes to a darker color when touched and held, reverting back to normal when the touch is released. This effect is similar to how hyperlinks are highlighted on an iPhone, not like text selection. To implement this feature, I am using jQuery t ...

Achieving Equal Spacing Between Containers without Using Grid or Flexbox

I'm struggling to evenly space four child containers within a single parent container without using Flex/Grid, as I haven't covered those topics yet. I tried setting each child container to 25% width of the parent and centering them with text-ali ...

Guidelines for accessing the value of the parent function upon clicking the button within the child function?

I have a pair of buttons labeled as ok and cancel. <div class="buttons-div"> <button class='cancel'>Cancel</button> <button class='ok'>Ok</button> </div> The functions I am working wi ...

What is the best way to include the border-radius CSS property to a dropdown element in Ant Design?

Adding the border-radius CSS property to my dropdown component from ant design has been a bit challenging for me. I attempted to modify the antd-css file and include a style object directly into the component, but unfortunately, I did not achieve the des ...

Utilize PHP to import an HTML file with JavaScript code into MySQL database

I've been attempting to use JavaScript to retrieve my location, but I'm facing an issue where when I click submit, the data is not getting entered into the page action.php. geolocation.php <form action="action.php" method="post"> < ...

Implementing a dynamic navigation bar that expands and collapses on mouse hover in a React application

I have a side navigation bar on my webpage that I obtained from a React Bootstrap website, so the class names are already pre-loaded. Instead of using a toggle hamburger icon to expand or collapse the navigation, I want to achieve this functionality based ...

Change the width of the webpage inside the iframe

I am working with an iframe that has a fixed width and height of 400px. I want to load a web page in the iframe, but I need to adjust the width of the source to fit my iframe perfectly. The height is not an issue as I can add a scrollbar if needed. Here ...

JavaScript generating HTML code causing malfunctions

I have been attempting to implement the IN Place Editing feature using JQuery. Below is the code snippet editinplace.js $(document).ready(function() { //When div.edit me is clicked, run this function $("div.editme").click(function() { // ...

Issues with Loading Bootstrap JavaScript on Basic "Hello World" Project

I am experiencing an issue where the JavaScript code is not displaying on my website. I have checked the inspect element sources and it seems to load correctly, but for some reason, it is not being applied. Any insights on why this might be happening? Than ...

Nested navigation in Bootstrap

I am currently working on creating a multilevel menu using Twitter Bootstrap. Check out the code here Below is the snippet of HTML code: <!DOCTYPE html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> ...

Responsive design challenge

I'm currently working on a WordPress theme with a fixed header and footer on the homepage, and a vertical slider in between that includes content and images. I've made the website responsive, but I'm facing an issue where the content in the ...

The Bootstrap Input-Group with Spinner displays an unusual spinning shape that resembles the letter D

I am encountering an issue with a unique form that sends each line of input as a separate request upon submission. I am looking to add a spinner at the end of each line, but I am facing a problem where instead of a circular spinner, I am getting a spinning ...

Utilizing PHP to send emails via an HTML form

I spent all day attempting to send an email from my HTML contact form using PHP, but I'm struggling as a beginner. When I uploaded the form to free web hosting, I received a "success!" message upon submission, yet no actual email was sent. Any assist ...

Can flexbox elements be animated as they scroll?

Wondering if it's feasible to animate flex elements upwards when scrolled? Attempting to replicate this effect: https://codepen.io/Sergiop79/pen/bxjGEe I want to apply this to the elements below (styled in flexbox), either the entire "row" or each i ...

Retrieve user choices from dropdown menu with Flask and HTML

I'm currently working on developing a dropdown list in HTML that, upon selection submission, will pass the chosen option to a Python script to dynamically update the content of the HTML page. While I have successfully implemented the dropdown list, I ...

Vue 3 has a known issue where scoped styles do not get applied correctly within the content of a <slot> element

Utilizing the Oruga and Storybook libraries for creating Vue 3 components. The code in the Vue file looks like this: <template> <o-radio v-bind="$props" v-model="model"> <slot /> </o-radio> </template ...

What is the method to establish the table format in HTML using several for each loops?

I need to arrange the table structure for product plans as follows: +------------------+---------------+---------------+ | product1 | product2 | product3 | +------------------+---------------+---------------+ | product1plan1 | product ...

What is the proper way to add process.env.PORT to the script declarations string within my package.json file?

I am facing an issue while trying to upload my file on Heroku that requires including the PORT specification. Unlike my previous projects, this project consists of only html, js, and css files instead of an index.js file. To run it, I am using "live-server ...

I'm new to this, but can someone explain why I'm being redirected to the register_db.php page when I click on the register button?

Why when I click the register button, it redirects me to the register_db.php page instead of sending the data to the database and keeping me on the same register.php page? I want the data to be sent to the database without changing the webpage. register.p ...

What is the procedure for injecting CSS with user origin in a browser extension?

I need assistance with a basic browser extension that involves injecting CSS: { "manifest_version": 2, "name": "User Style Sheet Workaround", "version": "1", "content_scripts": [ { ...