# Sticky NavBar works on lapTop but not on iPhone.

**URL:** https://forum.kirupa.com/t/sticky-navbar-works-on-laptop-but-not-on-iphone/639532
**Category:** web dev
**Created:** [March 21, 2019, 5:24pm UTC](https://forum.kirupa.com/t/sticky-navbar-works-on-laptop-but-not-on-iphone/639532 "2019-03-21T17:24:00Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![snowmandsp](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/snowmandsp/32/9548_2.png) [@snowmandsp](https://forum.kirupa.com/u/snowmandsp)
#### Post date: [March 21, 2019, 5:24pm UTC](https://forum.kirupa.com/t/sticky-navbar-works-on-laptop-but-not-on-iphone/639532/1 "2019-03-21T17:24:00Z")

</div>

I want the page to be responsive so I stopped using position: fixed. I like the flex ability move the browser page right to left (shrink)  
and the spacing stays the same right to left.  
Any thoughts?

**HTML**

 ![]()

**CSS**  
body{  
display: flex;  
justify-content: center;  
margin: 0;  
}  
#container{  
width: 80%;  
height: 500px;  
margin: auto;  
}  
.nav{  
display: flex;  
justify-content: space-around;  
border: 4px #0ff solid;  
height: 40px;  
min-width: 200px;  
padding: 0px 0px 0px 0px;  
margin: 0px 0px 0px 0px;  
z-index: 5;  
top: 0;  
position: sticky;   
}

Thank you for any advice.  
Snow

---

<div class="post-metadata">

### Author: ![snowmandsp](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/snowmandsp/32/9548_2.png) [@snowmandsp](https://forum.kirupa.com/u/snowmandsp)
#### Post date: [March 21, 2019, 5:29pm UTC](https://forum.kirupa.com/t/sticky-navbar-works-on-laptop-but-not-on-iphone/639532/2 "2019-03-21T17:29:19Z")

</div>

Sorry  
**HTML**

 ![]()

---

<div class="post-metadata">

### Author: ![snowmandsp](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/snowmandsp/32/9548_2.png) [@snowmandsp](https://forum.kirupa.com/u/snowmandsp)
#### Post date: [March 21, 2019, 5:30pm UTC](https://forum.kirupa.com/t/sticky-navbar-works-on-laptop-but-not-on-iphone/639532/3 "2019-03-21T17:30:14Z")

</div>

\<div id=“container”\>

\<div class=“nav”\>

\<img src=“images/pics/x.jpg” width=“100%” alt=""/\> \</div\>

\</div\>

---

<div class="post-metadata">

### Author: ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)
#### Post date: [March 22, 2019, 4:11am UTC](https://forum.kirupa.com/t/sticky-navbar-works-on-laptop-but-not-on-iphone/639532/4 "2019-03-22T04:11:11Z")

</div>

Do you have a live example we can look at? That would help!

---

<div class="post-metadata">

### Author: ![snowmandsp](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/snowmandsp/32/9548_2.png) [@snowmandsp](https://forum.kirupa.com/u/snowmandsp)
#### Post date: [March 22, 2019, 2:52pm UTC](https://forum.kirupa.com/t/sticky-navbar-works-on-laptop-but-not-on-iphone/639532/5 "2019-03-22T14:52:09Z")

</div>

This is my index page mock-up.  
http://davidsimonperry.com/ZZZ.html  
The content below the navBar scrolls behind nicely on the lapTop, but on my iPhone.  
On my existing index page  
[http://davidsimonperry.com/index.html](http://davidsimonperry.com/index.html)  
it works fine on all platforms, but it is not responsive using position: fixed.  
You should take a look at my email sent page.  
[http://www.davidsimonperry.com/A-sent.html](http://www.davidsimonperry.com/A-sent.html)  
You helped me with the red balls falling.  
Thank you for that one.  
WOW.  
Snow

---

<div class="post-metadata">

### Author: ![snowmandsp](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/snowmandsp/32/9548_2.png) [@snowmandsp](https://forum.kirupa.com/u/snowmandsp)
#### Post date: [March 25, 2019, 1:38am UTC](https://forum.kirupa.com/t/sticky-navbar-works-on-laptop-but-not-on-iphone/639532/6 "2019-03-25T01:38:16Z")

</div>

I guess it is a hard thing to do.

---

<div class="post-metadata">

### Author: ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)
#### Post date: [March 25, 2019, 2:39am UTC](https://forum.kirupa.com/t/sticky-navbar-works-on-laptop-but-not-on-iphone/639532/7 "2019-03-25T02:39:40Z")

</div>

What you are trying to do is difficult, but I’m also having difficulty understanding your question.

On [this page](http://davidsimonperry.com/ZZZ.html), what is it that I’m supposed to be focusing on. Is the content scrolling properly on your desktop but not working on the iPhone? In other words, do you want the same behavior you see on desktop on the iPhone with the appropriate adjustments to account for a smaller screen size?

On this page ([http://davidsimonperry.com/index.html](http://davidsimonperry.com/index.html)), when you are saying _ **works fine on all platforms** _, does it mean it works on desktop and mobile as well? If so, if we can get the behavior to work when `position: fixed` is set, would that solve it for you?

---

<div class="post-metadata">

### Author: ![snowmandsp](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/snowmandsp/32/9548_2.png) [@snowmandsp](https://forum.kirupa.com/u/snowmandsp)
#### Post date: [March 27, 2019, 4:07pm UTC](https://forum.kirupa.com/t/sticky-navbar-works-on-laptop-but-not-on-iphone/639532/8 "2019-03-27T16:07:22Z")

</div>

I thank you for you time Mr. Kirupa.  
[http://davidsimonperry.com/Kirupa.html](http://davidsimonperry.com/Kirupa.html)  
This linked page I created shows all the example of what is going on.  
I would like this page to be responsive.  
Using display: flex is a more user friendly on small devices displaying a larger overall image than using position: fixed.  
I would like to have the NavBar at the top of the page at all times.  
The NavBar rolls out if I scroll down on the phone captured in example 8.  
I does not stick at the top of the page.  
If you have any thought it would be greatly appreciated.  
Thank you again.  
Snow

---

<div class="post-metadata">

### Author: ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)
#### Post date: [March 28, 2019, 2:44am UTC](https://forum.kirupa.com/t/sticky-navbar-works-on-laptop-but-not-on-iphone/639532/9 "2019-03-28T02:44:01Z")

</div>

Thanks for the detailed explanation! I found out what the issue is. The **sticky** value needs to be prefixed with -webkit to work on iOS. When prefixed the value, the header was properly sticking to the top of the page as expected on both Safari desktop (where it also didn’t work) as well as on my iPhone.

The last line contains the change:

```
.nav {
	display: flex;
	justify-content: space-around;
	background-color: #fff;
	border: 4px #0ff solid; 
	height: 40px;
	box-shadow: 2px 4px 8px 2px rgba(0, 5, 10, 0.2),
				 0px 6px 20px 0px rgba(0, 0, 0, 0.19);
	min-width: 200px;
	padding: 0px 0px 0px 0px;
	margin: 0px 0px 0px 0px;
	z-index: 5;
	top: 0;
	position: sticky;
    position: -webkit-sticky;	
}

```

Let me know if this works 🙂

---

<div class="post-metadata">

### Author: ![snowmandsp](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/snowmandsp/32/9548_2.png) [@snowmandsp](https://forum.kirupa.com/u/snowmandsp)
#### Post date: [March 28, 2019, 11:42pm UTC](https://forum.kirupa.com/t/sticky-navbar-works-on-laptop-but-not-on-iphone/639532/10 "2019-03-28T23:42:29Z")

</div>

Indeed it worked.  
I do not Know much about the webkit business,  
but I will have to study up on it.  
I recall some bits used for Mozilla as well.  
I reallyDo appreciate your time and efforts.  
Right again you were.  
Thank you.  
Snow

---

<div class="post-metadata">

### Author: ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)
#### Post date: [March 29, 2019, 2:47am UTC](https://forum.kirupa.com/t/sticky-navbar-works-on-laptop-but-not-on-iphone/639532/11 "2019-03-29T02:47:36Z")

</div>

Glad it worked 🙂

One of the first places I often look when things work on the desktop (and in Chrome) but not on mobile is this site: [https://caniuse.com/#feat=css-sticky](https://caniuse.com/#feat=css-sticky) It does a great job highlighting the various degrees of support other implementations have, and it also calls out when you may need to prefix something!
