CSS allows for the creation of fixed bars that remain at the top of the

I am looking to create a fixed bar that is off-center with a scrolling background. The code I have so far either places the bar on the surface but fixes it to the background, or it positions the bar beneath the image and fixes it to the window - neither of which is what I want. I can't seem to keep the "contentBox" on the surface of the window. Any help would be appreciated (and apologies for the messy code, as this is my first attempt at CSS).

<html>
<head>
<style type="text/css">
body{ height:100%}
#bg {
    position:absolute;
    background-color:grey;
    top:0;
left:0;
width:100%;
height:100%;
}
#bg img {
position:absolute;
top:0;
bottom:0;
margin-left:10%;
min-width:80%;
height:100%;
}
#contentBox
 {
   position:top;
   left:0;
   margin-top:25%;
   height:30%;
   max-width:90%;
   background-color:#ffffff;
   opacity:0.6;
   filter:alpha(opacity=60);
 }
#contentBox:hover
 {
   position:top;
   left:0;
   margin-top:25%;
   height:30%;
   max-width:90%;
   background-color:#ffffff;
   opacity:0.9;
   filter:alpha(opacity=90);
 }
#linkCloud
 {
   float:left;
   min-width:11%;
   min-height:100%;
   background-color:blue;
   opacity:0.9;
   filter:alpha(opacity=90);
 }
#feed
 {
   float:right;
   top:0;
   right:0;
   min-height:100%;
   min-width:10%;
   background-color:red;
   opacity:0.9;
   filter:alpha(opacity=90);
 }
</style>
</head>

<body>

  <div id="bg">
      <img src="/home/samzors/Desktop/Gimp/skull.jpg" alt="">

      <div id="feed">
         <p>hello world</p>
      </div>

      <div id="contentBox">

         <div id="linkCloud">
           <p>hello world</p>
         </div>

     </div>
 </div>

</body>

</html>

Answer №1

If my understanding is correct, it seems like you are looking to create a navigation bar that stays fixed at the top of the screen. This can be achieved by using the CSS property position: fixed. Here's an example:

<style>
    #navBar {
        position: fixed;
        left: ; /* distance from the left side of the screen */
        top: ; /* distance from the top of the screen */
    }
    ...
</style>

...

<body>
    <div id="navBar">navigation content</div>
    <div id="mainContent"> rest of your content </div>
</body>

You may also want to add a margin-top property for #mainContent to ensure that it doesn't overlap with #navBar.

One more thing to keep in mind -- when using pseudo-classes like :hover, you only need to specify the properties that are changing. For example, in #navBar:hover, you would only include:

#navBar:hover {
    opacity: 0.9;
    filter = alpha(opacity = 90);
}

Answer №2

After much experimentation, I have discovered a rather unconventional solution to the problem at hand.

By splitting the bg (background) class from the contentBox class in the HTML code, following cmw's advice, I managed to resolve the issue of the content box being hidden from view. To achieve this, I created a secondary div class called "content" within the contentBox class. This allowed me to display the fixed box on the screen while keeping the bg class scrollable.

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

How can I alter the color of the menu text when scrolling to the top of a webpage?

As I navigate my website, I encounter a menu with a transparent background at the top that changes to black as I scroll down. On a specific page where the background is white, this presents an issue: when the menu reaches the top, the white background clas ...

Guide on utilizing jQuery to read and insert a local HTML file directly into a textarea

What is the best way to load a local HTML file in raw format and insert it into a textarea using jQuery version 1.3? ...

Revolutionize iPad user experience with seamless HTML5 video integration

What is the most effective method for dynamically embedding HTML5 video to ensure compatibility with the iPad? (using pure Javascript) I'm having difficulty getting this approach to work: <div id="placeholder"><script type="text/javascript" ...

JavaScript's innerHTML property is failing to update

Hello there, I am currently attempting to update the innerHTML content of the script below: <div id="global-alert-queue" class="layout-wrapper"> <div class="alert success animate-in" role="alert"> Your submission was successful. <button i ...

Parallax scrolling and Swiper slider, a match made in digital design

Currently facing an issue with Swiper Slider and Simple Parallax Scrolling. Whenever I switch slides, the same image is displayed repeatedly. I suspect the problem lies in the fixed position of the image within the parallax effect. Attempted to resolve b ...

Trouble arises when trying to link IE7 with jQuery

I am currently testing a website with jQuery. There is a plugin that, when hovered over, slides down to reveal another banner, subsequently sliding the banner below it down as well. I have added a link on the bottom banner using z-index, and although it wo ...

Using HTML to get the minimum date specified by a different date

Can someone assist me? I am trying to retrieve the minimum parameter for the second date field based on the value entered in the first date field: Check-In: <input type="date" name="checkin" min="<?php echo date('Y-m-d');?>" required& ...

Can you specify the doctype used for XHTML5, which is the XML representation of HTML5?

Which doctype is recommended for XML serialization of HTML5? If I keep the file extension as .html, can I still indicate to the browser that the content is XHTML5? ...

Mobile version shows white spaces when using particles.js and bootstrap 4.6

This is how I implement particles.js: <div id="particles-js"></div> @RenderSection("Header", required: false) <main role="main" class="container"> @RenderBody() </main> <script> ...

Discovering the reason behind a DOM element's visual alteration upon hovering: Where to start?

Visit this page, then click on the next button to navigate to the time slots section. As you hover over any time slot, you will notice a change in appearance. Despite inspecting Chrome's developer tools, I was unable to locate a style with a hover dec ...

Experimenting with the routerLink directive in Angular 2

Currently, I am in the process of testing routing functionality. As part of this, I have moved my navbar to a separate component called MdNavbar, which primarily consists of HTML and CSS. The RouteConfig is located in another component where MdNavbar is in ...

How to link an external CSS file to a Vue.js project

I created a new project using @vue/cli and now I want to add an external CSS file to my App.vue Here's what I attempted: <template> <div id="app"> <div id="nav"> <router-link to="/">Home</router-link> | ...

Tips for getting free jqgrid to display frozen column borders in the search toolbar

If the actions column has a caption of "Activity" or custom settings and is frozen, the free jqgrid will not display column borders for this column in the search toolbar. Vertical lines do not appear in the search toolbar: Is there a way to resolve this ...

Executing Cross-Component Communication in Angular 7: A Quick Guide

I've encountered a challenge with a checkbox in the header component. If the checkbox is checked, I need to display an alert message when the application loads. The tricky part is that the checkbox is linked to the home component. Therefore, if I am o ...

Update the header background color of an AG-Grid when the grid is ready using TypeScript

Currently working with Angular 6. I have integrated ag-grid into a component and I am looking to modify the background color of the grid header using component CSS or through gridready columnapi/rowapi. I want to avoid inheriting and creating a custom He ...

Develop a responsive component on the right side

I am encountering an issue with creating a responsive div that matches the height of the image on the left side. I want to include text in this div, however, when I do so, the paragraph expands in height along with the div element when I attempt to change ...

What is the best way to horizontally align my div content while ensuring it is responsive, alongside a sidebar and top menu on the same

I am facing an issue trying to center my div content responsively with a sidebar menu and a top menu using Bootstrap. However, when I require the side-menu file, my div content gets placed at the bottom of the page unexpectedly. I am only using Bootstrap 5 ...

Stop the link height from changing when hovered over

Incorporating Angular, Angular Material, and Angular Flex-Layout, I have designed a collection of links that resemble cards or tiles. The links initially display an icon and title but transition to show informational text upon hovering. However, for links ...

Can you explain the differences between offsetHeight, clientHeight, and scrollHeight for me?

Have you ever wondered about the distinction between offsetHeight, clientHeight, and scrollHeight? What about offsetWidth, clientWidth, and scrollWidth? Understanding these differences is crucial for working effectively on the client side. Without this kn ...

Error in THREE.js: Failed to retrieve object at http://192.168.8.104:8080/[object%20Object] (Error code: 404) - Module: three.module.js

During my attempt to create a text loader in THREE.js, I encountered an error instead of getting the expected text output. three.module.js:38595 GET http://192.168.8.104:8080/[object%20Object] 404 (Not Found) I made various efforts to resolve this error ...