Using the `position:fixed` property is ineffective on android devices

Creating a responsive website with a customized 960 grid system:

@media only screen and 
(min-width: 720px) and (max-width: 959px){

.container_12{
  margin-left: auto;
  margin-right: auto;
  width: 720px;
}
}

In addition, the site includes a navigation bar that utilizes position:fixed to stay at the top of the page.

.nav-band{
    width: 100%;
    font-weight: bold;
    position: fixed;
    z-index: 3;
    overflow: hidden;
    background-image:url('../img/trans_black.png');
    padding: 2px;
}

However, an issue arises when viewing the site on my android tablet. Upon rotating the tablet, causing all .container_12 tags to shrink from 720px to 480px, the nav bar either vanishes or becomes misaligned halfway down the page. How do I go about solving this problem? The website also features an image that displays behind the nav bar in the .header-band section:

.header-band{
    background-image:url('../img/header_band3.png');
    background-repeat:repeat-x;
    background-position:top;
    height: 400px;
    background-color: #050505;
    position: fixed;
    z-index: 1;
}

<div class='pageband nav-band'>
<ul class='horizontal-list'>
<li class='nav-item active'>
<a href="http://...">Home</a>
</li>
...
</ul>
</div>
<div class='pageband header-band'>&nbsp;</div>
<div class='pageband core-band'>
<div class='pageband logo-band '>
<div class='container_12'>
...

Answer №1

Adding top: 0px and left: 0px to your navigation bar's CSS will ensure that it is positioned at the top of the screen, even though you have already set position: fixed. This will properly position the element.

.nav-band{
    width: 100%;
    font-weight: bold;
    position: fixed;
    top: 0px;
    left: 0px;
    z-index: 3;
    overflow: hidden;
    background-image:url('../img/trans_black.png');
    padding: 2px;
}

Answer №2

Give these codes a shot:

@media screen and (orientation: landscape){
   .nav-band {
      // additional code here
   }
}

@media screen and (orientation: portrait){
   .nav-band {
      // more code here
   }
}

By using these, you can specifically target the orientation of your device and effectively "reset" your code.

Answer №3

Thank you for assisting me with this frustrating issue.

position: fixed; initially didn't work on both my android and desktop devices. After removing position: relative from the container of the fixed element, the problem was resolved on the desktop but not on the android (Galaxy Note 5). Adding

-webkit-backface-visibility: hidden;
didn't solve the issue on android either; instead, it caused some flickering and position changes. However, adding display: block; to the container of the element fixed the positioning on android while still working on the desktop.

Here is how the CSS code looks:

body {
  background-image: url("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png");
  background-repeat: repeat-y;
  display: block;
  height: 200vh;
  overflow-y: scroll;  
  width: 100vh;  
} 

#fixed-red-box {
  position: fixed; 
  top: 6%; 
  right: 4%; 
  -webkit-backface-visibility: hidden; 
  height: 5vh; 
  width: 10vw; 
  border: 1vw solid red; 
  z-index: 300;
}  

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-
       scale=1"/>version=5.1"/>
  </head>
  <body>
    <div id="fixed-red-box"></div>
  </body>
</html>

It took me a month to discover this solution. I'm not a professional coder, but I dabble in coding. Hopefully, this information can assist someone else facing a similar problem.

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

Wrapping a series of grids within a parent container to manage height effectively with grid960

Testing on the following browsers: Internet Explorer, Chrome, Firefox; Check out this example of an ideal layout in a PDF: Here is the link to the direct page: While Grid systems work well for width layout, I struggle with setting height constants. In ...

A step-by-step guide on incorporating click and drag events into an HTML Canvas

I have developed a unique business tool using html canvas. It is equipped with a variety of draggable and droppable elements. I personally created the functionality with the following pseudocode: if(mouseIsDown && mouseInBoundsOfIcon){ icon.g ...

Creating an HTML div that fills the remaining height available

Currently, I'm developing a web application and aiming to have the content span the full height of the screen. Is there a way to make the div element (other-child) automatically fill its parent without having to manually set its height? html { heig ...

problem with concealed picture when hovering cursor

While I know this issue has been discussed before, I am facing a slight confusion regarding displaying an image on MouseOver. Currently, I have a div container with a colored background that shows when hovered over. You can see an example of this here - sc ...

Equal size images displayed within cards in Material UI

Is there a way to create a list of Material UI components with images that have uniform height, even if the original images vary in size? I want to make all image heights responsive and consistent across all cards. Any suggestions on how to achieve this? ...

"Encountering a 405 error when transmitting information from an HTML file to a Python Flask server using 'GET / HTTP/1.1'

As someone who is brand new to the world of python and AJAX, I have been piecing everything together from various sources online including examples and Flask documentation. So far, I have managed to make some progress. My goal is to send latitude and longi ...

Leveraging perl's CGI.pm within various subroutines

I am currently working on a school project that requires me to write a Perl CGI script to build a social networking site. While I have successfully created multiple subroutines for different pages, I am encountering an issue. When I try to execute each su ...

Capture screenshots of the web page URLs within the Chrome browser by utilizing PhantomJS

Looking for a way to capture screenshots of various URLs and display them in the Chrome browser using PhantomJS. How can I achieve this? Any assistance would be greatly appreciated, as nothing is currently showing up on the webpage. This is how my code a ...

The jQuery .accordion() feature is not functioning properly due to the failure to load jQuery into the HTML document

I have exhaustively researched online and visited numerous resources, including Stack Overflow. Despite making countless adjustments to my code, it still refuses to function properly. The frustration is mounting as I struggle with jQuery - a technology tha ...

I'm currently reviewing a CSS stylesheet for a React webpage, and I've noticed that several classes are utilizing content to dynamically create images. However, the display of content in VSCode appears as a bullet point

Exploring an existing ReactJS website, I've noticed that many images are rendered using the CSS content property. While examining the CSS file in VSCode, I've come across classes where the content is displayed as "". I'm uncertain whether ...

A CSS sticky footer solution with a top margin tweak

I've encountered numerous solutions for creating a sticky footer on Stack Overflow, and they have all been effective for me. However, I am facing an issue where I need to maintain a 60px space between my "content div" and my "footer div." Unfortunatel ...

Floating with Flex in Bootstrap 4: A seamless way to achieve

Is there a way to achieve this floating layout using Bootstrap 4 flex Grid? I've attempted to use the flex order function but encountered some issues. Have a look at my result: <div class="row align-items-start"> <div class="col-sm- ...

By utilizing the body element as the container instead of a div, the content shifts to the left by eight pixels

When the body is used as the wrapper instead of a div, the content shifts eight pixels to the left (on a 1920×1080 display) when it extends below the fold. The examples below illustrate this difference in code snippets. Please note that the variance is on ...

Adjusting jQuery tab content heights to maintain consistent height across tabs and prevent varying heights

I am currently working on a tabbed view that is very similar to the demo found at the following link: http://jsfiddle.net/syahrasi/us8uc/ $(document).ready(function() { $(".tabs-menu a").click(function(event) { event.preventDefault(); $(this).pare ...

Is it possible to trigger a server-side event using jQuery in SharePoint 2010?

For my Sharepoint 2010 application, I have been utilizing jQuery to handle most events on the client-side. However, when it comes to saving data to the Sharepoint list and generating a PDF file with that data, I need to switch to server-side processing usi ...

Creating a dynamic calendar text box with JavaScript: a step-by-step guide

I am trying to dynamically add a calendar text box on each click of a link. While I have tested some codes, it seems that the functionality only works for the first declaration and not for subsequent ones. Here's the code snippet I have been working ...

Move the grid items to their new positions with animation

I have a group of floating elements, all the same size and arranged within a grid layout. I am now adding a new element using jQuery's .after() method, which is larger in size and spans the entire width of the container, necessitating its own row. T ...

Passing Parameters to Razor Pages Controller

Within my controller, there exists a function as follows: public ActionResult AddSubSub(int? idOfSubsub) { return RedirectToAction("Index", new { searchword = "" }); } I am able to invoke this function without providing any parameter. I attempted the ...

Craft unique looks for both even and odd Tumblr posts

I recently came up with a unique idea for a Tumblr theme where the design of posts changes based on whether they are even or odd in the sequence. While I have experience with basic HTML coding, delving into Tumblr customization is new to me. Here's wh ...

jquery is in motion while svg paths are at a standstill, waiting to

i have been attempting to incorporate a css-animated svg into my project. initially, the animation would start automatically, which was undesirable. after some research, i discovered that by declaring it as paused and then triggering it using jQuery with $ ...