-1

Issue

I am trying to build a portfolio website using bootstrap 5, and have been having trouble with the navbar displaying the Title so that it overlaps the hamburger menu and goes off the side of the screen. This issue is only happening on firefox & safari on my iPhone 11. I have tested my site on a Samsung Note, and an iPad pro, and both are working perfectly. It also works properly in the fiddle I linked below. I can't figure out why only the browsers on my iPhone are not rendering this correctly.

The navbar used to appear correctly, but I noticed that my website's font looked way too small on mobile and searched for a solution. I found this question on stack overflow which recommended adding the below meta tag to the head section:

<meta name="viewport" content="width=device-width, initial-scale=1">

This fixed my issue with font size on mobile, but the navbar started behaving incorrectly specifically on firefox & safari on my iPhone 11. The body of the website looks fine, but the navbar looks like this:

Mobile Browser (iPhone 11 - firefox/safari)

firefox-mobile screenshot

For comparison, here is the same code being displayed on a desktop browser at the smallest browser size. This is how it is supposed to look:

Desktop Browser

firefox-desktop screenshot

So I am trying to figure out why the iPhone 11 is rendering it wrong while other devices and browsers are rendering it correctly.

Code

Fiddle

https://jsfiddle.net/GeorgeCiesinski/6c579nt4/8/

HTML

<nav class="py-3 navbar navbar-custom navbar-expand-lg autohide navbar-dark">
  <div class="container">
    <a class="navbar-brand" href="#">
      <img src="./assets/logo.svg" class="logo" alt="logo"/>
      George Ciesinski
    </a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ms-auto">
        <li class="nav-item">
          <a class="nav-link" href="#hero">Software Development</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#about">About</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#projects">Projects</a>
        </li>
        <li class="nav-item">
          <a class="nav-link"
          href="https://georgeciesinski.github.io/blog/">Blog</a>
        </li>
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
            Resume
          </a>
          <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
            <li><a class="dropdown-item" href="assets/PDF/GeorgeCiesinskiResume.pdf" target="_self">PDF</a></li>
            <li><a class="dropdown-item" href="https://georgeciesinski.github.io/resume/">Website</a></li>
          </ul>
        </li>
      </ul>
    </div>
  </div>
</nav>

CSS


@media only screen and (max-width: 850px) {
  .container > .navbar-brand .logo {
    font-size: 1rem;
    display: inline-block;
  }

  .navbar-toggler {
    position: absolute;
    top: 0px;
    right: 0px;
    border-color: none;
  }
  .navbar-brand > img {
    margin-right: 0rem;
  }
}

nav {
  background-color: var(--navbar_color);
}

.navbar-brand img {
  max-height: 50px;
}

.navbar-brand {
  font-size: 24px;
  text-transform: uppercase;
  font-weight: 900;
}

/* Navbar Site Title */

.navbar-custom .navbar-brand,
.navbar-custom .navbar-text {
  color: var(--navbar_logo_text);
}

.navbar-custom .navbar-brand:hover {
  color: var(--navbar_logo_text_highlight);
}

/* Navbar Links */

.navbar-dark .navbar-toggler-icon {
  color: var(--navbar_logo_text);
}

.navbar-nav .nav-item .nav-link {
  color: var(--navbar_text);
}

.navbar-nav .nav-item.active .nav-link,
.navbar-nav .nav-item:hover .nav-link {
  color: var(--navbar_text_highlight);
}

/* Navbar Dropdown Menu */

.navbar-nav > li > .dropdown-menu {
  background-color: var(--navbar_dropdown);
}

.navbar-nav > li > .dropdown-menu a{
  color: var(--navbar_dropdown_text);
  margin: auto 0px !important;
}

.navbar-nav > li > .dropdown-menu a:hover {
  background-color: var(--navbar_dropdown_hover);
  margin: auto 0px !important;
}

nav ul li a {
  color: #a9a9a9;
  font-size: 22px;
  margin: auto 10px;
}

Attempted Solutions

I have searched for a solution and found this question on stack overflow but the solution didn't work for me.

I also searched through the bootstrap 5 documentation about navbars and tried using different navbar classes. I searched for a way to make the font size for the website title smaller on browsers, or dynamically resize to fit. None of the questions or examples I tried resolved the issue for me.

Ideal solution

I would like my navbar to have the same layout and look as my screenshot of the navbar on a desktop browser. The font size looks the same in the screenshots, but the positioning is wrong. If there is a solution to make them behave the same way on both, this would be ideal.

GeorgeCiesinski
  • 191
  • 1
  • 3
  • 11
  • I just went to your front-end and everything seems to be running the way you want it. The only time I saw the title not formatted properly was on an iPad Pro screen. – Kameron Nov 06 '21 at 00:07
  • I just did more tests on an Ipad Pro and an Android phone. Those are behaving normally, so this issue seems to only be present on iPhone browsers. I confirmed it is happening on firefox and safari on my iphone 11. I'll update the quesiton. – GeorgeCiesinski Nov 06 '21 at 00:27

1 Answers1

2

I only saw your issue when I actually went to the link on my phone instead of the dev tools on my chrome browser. However, what I would do in this instance is use media queries in your navbar elements. Your media queries should look something like this for a standard mobile browser.

@media only screen and (max-width: 850px) {
  .container > .navbar-brand .logo {
    font-size: 1rem;
    display: inline-block;
  }

  .navbar-toggler {
    position: absolute;
    top: 0px;
    right: 0px;
    border-color: none;
  }
  .navbar-brand > img {
    margin-right: 0rem;
  }
}

Obviously, feel free to change this as needed, as I can't see how the direct front end looks in either a fiddle or on my phone, but this will get you on the right track.

Kameron
  • 10,240
  • 4
  • 13
  • 26
  • I added a fiddle: https://jsfiddle.net/GeorgeCiesinski/6c579nt4/18/ I tried this solution, but it doesn't make a difference on my iPhone. This issue only seems to be happening on my firefox/safari browser on iPhone 11. Works properly on iPad Pro and Samsung Note. – GeorgeCiesinski Nov 06 '21 at 01:29
  • @GeorgeCiesinski please see the adjusted code. Works for me on the fiddle. – Kameron Nov 06 '21 at 02:04
  • I agree with Kameron and specifically with `margin-right: 1rem;` when you're lower than 850px. In all honesty with Bootstrap I would stay away from margins and padding in your CSS and use the regular Bootstrap spacing. Here are the docs.... https://getbootstrap.com/docs/5.0/utilities/spacing/ – Cutey from Cute Code Nov 06 '21 at 09:26
  • It seems to work in the fiddle but the iPhone 11 browsers render it differently and move the logo & title over to the right so it looks like the screenshot in my question. I can't make sense of why this is happening on this specific platform but works on every other platform I've tried. – GeorgeCiesinski Nov 07 '21 at 23:57
  • @GeorgeCiesinski It's hard to give you **exact** CSS code to format your navbar correctly since I can't inspect it on my phone. However, I do think it's odd that still in the `iPhone-X` view of my `dev-tools` on my browser I still can't see the correct view. With this being said I am 100% sure if you play around with those `media queries` you will get it figured out. Just keep trying to change stuff around and see what the front-end looks like and make changes based on that. – Kameron Nov 08 '21 at 20:55
  • 1
    Thanks for putting me in the right direction! I will keep trying with the media queries and will post my solution once I have it. – GeorgeCiesinski Nov 09 '21 at 01:08