The navigation bar and text subtly shift when displayed on various devices or when the window size is adjusted

Hello, I am brand new to web development and have encountered an issue on my website. Whenever the window is resized or viewed on a different screen, the navigation bar (which consists of rectangles and triangles) and text elements start moving around and some parts disappear entirely. I am wondering if setting the sizes in percentages would solve this problem. If so, I'm unsure which specific parts I need to adjust.

If you'd like to take a look at the issue yourself, please visit my website on Codecademy by clicking on this link and then click the full-screen button.

body {
    background-image:  url('http://www.rgbstock.com/cache1u7YbL/users/x/xy/xymonau/300/nXWyMYC.jpg')
}

#background {
    background-color: white;
    height: 100%;
    width: 75%;
    position: relative;
    top: 100px;
    margin-left: auto;
    margin-right: auto;
}

#header {
    word-wrap: break-word;
    border: 1px solid black;
    height: 30%;
    width: 60%;
    position: relative; 
    bottom: 90px;
    margin-left: auto;
    margin-right: auto;
}

.photocontainer {
    border: transparent;
    height: 55%;
    width: 65%;
    position: relative;
    bottom: 60px;
    margin-left: auto;
    margin-right: auto;
}

.photocontainer img {
    width:100%;
    height:100%;
}

.navcontainer {
    border: 1px solid black;
    height: 10%;
    width: 99%;
    position: relative;
    bottom: 70px;
    margin-left: auto;
    margin-right: auto;
    overflow: hidden;
}


.navcontainer .navbar .navigation li {
    list-style: none;
    display: block;
    float: left;
    margin: 1em;
    text-align: center;
    position: relative;
    left: 15%;
}

.navcontainer .navbar .navigation li a {
    font-family: quicksand;
    text-decoration: none;
    text-transform: uppercase;
    display: block;
    width: 110%;
    color: #000000;
    font-size: 20px;
    vertical-align: middle;
    line-height: 31px;      
}

.navigation li a:hover {
    margin-top: 2px;
}

.navbar {
    margin: 0 auto;
    width: 90%;
    position: relative;
    bottom: 42px;
}

.navcontainer .navbar .rectangle {
    background: #f1e5cd;
    height: 62px;
    position: relative;
    -moz-box-shadow: 0px 0px 4px rgba(0,0,0,0.55);
    box-shadow: 0px 0px 4px rgba(0,0,0,0.55);
    -webkit-border-radius: 3px;
    -moz-border-radius: 3px;
    border-radius: 3px;
    z-index: 500; /* the stack order: foreground */
    margin: 3em 0;
}

.navcontainer .navbar .l-triangle-top {
    border-color: #e7dbc3 transparent transparent;
    border-style:solid;
    border-width:50px;
    height:0px;
    width:0px;
    position: relative;
    float: left;
    top: 1px;
    left: -50px;
}
 
.navcontainer .navbar .l-triangle-bottom {
    border-color: transparent transparent #e7dbc3;
    border-style:solid;
    border-width:50px;
    height:0px;
    width:0px;
    position: relative;
    float: left;
    top: -40px;
    left: -150px;
    }

.navcontainer .navbar .r-triangle-top {
    border-color: #e7dbc3 transparent transparent;
    border-style:solid;
    border-width:50px;
    height:0px;
    width:0px;
    position: relative;
    float: right;
    right: -45px;
    top: -107px;
}
 
.navcontainer .navbar .r-triangle-bottom {
    border-color: transparent transparent #e7dbc3;
    border-style:solid;
    border-width:50px;
    height:0px;
    width:0px;
    position: relative;
    float: right;
    top: -149px;
    right: -145px;
}
   <div id="background">
  <div id="header"></div>
  <div class="navcontainer">
     <div class="navbar">
     <!-- the left side of the fork effect -->
       <div class="l-triangle-top"></div>
       <div class="l-triangle-bottom"></div>
     <!-- the ribbon body -->
       <div class="rectangle">
         <!-- the navigation links -->
         <ul class="navigation">
           <li><a href="#">Home</a></li>
           <li><a href="#">About</a></li>
           <li><a href="#">Menu</a></li>
           <li><a href="#">Order</a></li>
           <li><a href="#">Contact</a></li>
         </ul>
    <!-- end the ribbon body -->
    </div>
 
    <!-- the right side of the fork effect -->
         <div class="r-triangle-top"></div>
         <div class="r-triangle-bottom"></div>
 
    <!-- end container -->
    </div>
 </div;

    <div class="photocontainer"></div>

Answer №1

Check out the following article: "http://www.w3schools.com/css/css_navbar.asp" Your current code seems a bit muddled. I hope this explanation clears things up for you.

Below is a simple example:

ul {
    list-style-type: none;
    margin: 0;
    overflow: hidden;
    padding: 0;
}

li {
    float: left;
}

a {
    background-color: #dddddd;
    display: block;
    width: 60px;
}

Answer №2

To see the solution with creatively positioned triangles, check out my fiddle. I've taken out your header for simplicity.

http://jsfiddle.net/L74gdm7j/2/

body {
    background-image: url('http://www.rgbstock.com/cache1u7YbL/users/x/xy/xymonau/300/nXWyMYC.jpg')
}
#background {
    background-color: white;
    height: 100%;
    width: 75%;
    position: relative;
    top: 100px;
    margin-left: auto;
    margin-right: auto;
}
.photocontainer {
    border: transparent;
    height: 55%;
    width: 65%;
    position: relative;
    bottom: 60px;
    margin-left: auto;
    margin-right: auto;
}
.photocontainer img {
    width:100%;
    height:100%;
}
.navcontainer {
    height: 10%;
    width: 99%;
    margin-left: auto;
    margin-right: auto;
    overflow: hidden;
}
.navcontainer .navbar .navigation {
    text-align: center;
    margin: 0;
    padding: 0;
}
.navcontainer .navbar .navigation li {
    list-style: none;
    display: inline-block;
    margin: 1em;
    text-align: center;
}
.navcontainer .navbar .navigation li a {
    font-family: quicksand;
    text-decoration: none;
    text-transform: uppercase;
    color: #000;
    font-size: 20px;
    line-height: 31px;
    transition-duration: 0.2s;
    display: inline-block;
    position: relative;
}
.navigation li a:hover {
    transform: translateY(10px);
}
.navbar {
    margin: 0 auto;
    width: 90%;
    position: relative;
    bottom: 42px;
}
.navcontainer .navbar .rectangle {
    background: #f1e5cd;
    height: 62px;
    position: relative;
    -moz-box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.55);
    box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.55);
    -webkit-border-radius: 3px;
    -moz-border-radius: 3px;
    border-radius: 3px;
    z-index: 500;
    /* the stack order: foreground */
    margin: 3em 0;
}
.navcontainer .navbar .l-triangle-top {
    border-color: #e7dbc3 transparent transparent;
    border-style:solid;
    border-width:50px;
    height:0px;
    width:0px;
    position: absolute;
    top: 0;
    left: -38px;
}
.navcontainer .navbar .l-triangle-bottom {
    border-color: transparent transparent #e7dbc3;
    border-style:solid;
    border-width:50px;
    height:0px;
    width:0px;
    position: absolute;
    top: -38px;
    left: -38px;
}
.navcontainer .navbar .r-triangle-top {
    border-color: #e7dbc3 transparent transparent;
    border-style:solid;
    border-width:50px;
    height:0px;
    width:0px;
    position: absolute;
    right: -38px;
    top: 0;
}
.navcontainer .navbar .r-triangle-bottom {
    border-color: transparent transparent #e7dbc3;
    border-style:solid;
    border-width:50px;
    height:0px;
    width:0px;
    position: absolute;
    top: -38px;
    right: -38px;
}
<body>
    <div id="background">
        <div class="navcontainer">
            <div class="navbar">
                <!-- the left side of the fork effect -->
                <div class="l-triangle-top"></div>
                <div class="l-triangle-bottom"></div>
                <!-- the ribbon body -->
                <div class="rectangle">
                    <!-- the navigation links -->
                    <ul class="navigation">
                        <li><a href="#">Home</a>

                        </li>
                        <li><a href="#">About</a>

                        </li>
                        <li><a href="#">Menu</a>

                        </li>
                        <li><a href="#">Order</a>

                        </li>
                        <li><a href="#">Contact</a>

                        </li>
                    </ul>
                    <!-- end the ribbon body -->
                </div>
                <!-- the right side of the fork effect -->
                <div class="r-triangle-top"></div>
                <div class="r-triangle-bottom"></div>
                <!-- end container -->
            </div>
        </div>
        <div class="photocontainer"></div>
    </div>
</body>

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

The CSS @media query is failing to function properly

I'm currently developing a web application similar to Spotify for my personal use, but I'm running into some issues with the @media query as it doesn't seem to be working correctly. Here is the CSS code: /* Screen Adapting */ @media (height ...

Unleashing the Power of Resetting CSS Class Attributes in Twitter Bootstrap

Last year, @Andres Ilich shared a remarkably elegant solution for centering the navigation bar in Bootstrap. Here is an excerpt from the answer he posted: Visit here for more details. <div class="navbar navbar-fixed-top center"> <div class=" ...

Customizing the size of dateBox icons in JQuery Mobile

Is there a way to increase the button size within the input box of a dateBox? Currently, it appears small and difficult to click accurately. Additionally, it would be beneficial if clicking anywhere in the input field could open the calendar, instead of ju ...

Attempting to replicate the action of pressing a button using Greasemonkey

I am currently working on a greasemonkey script to automate inventory updates for a group of items directly in the browser. I have successfully implemented autofill for the necessary forms, but I am facing challenges with simulating a click on the submissi ...

Issue with PHP/MySQL registration page failing to save user information to database

As I work on developing my website that includes user registration and login functionality, I encountered an issue where the registration page was not loading properly. Initially, the registration process worked perfectly, but the next day, upon trying to ...

Discovering the meeting point where two dives converge

Is there a method to change the color of the overlapped common part of two animated circles? ...

What is the reason for needing a page reload in Javascript or JQuery?

I'm curious why Javascript or jQuery require a page reload before applying certain effects. CSS updates in real-time, as demonstrated by the following example: This changes dynamically without needing to refresh the page @media all and (max-width:7 ...

Form featuring a mandatory checkbox that must be selected in order to proceed; failure to do so will result in an

So here’s the situation: I have a form with a checkbox for agreeing to the terms of service, and I want to make sure it is checked before proceeding with the donation process. I only have the HTML code and no idea how to implement this functionality. Ide ...

Stellar.js is malfunctioning

I've been attempting to implement a parallax effect using Stellar.js with two image tag elements, but I'm encountering issues. Despite trying various configurations, including following the Stellar.js creator's tutorial scripts closely, noth ...

Transform the text color of a table generated by a v-for loop

I have a Vue.js setup to exhibit a collection of JSON data which consists mainly of numbers. These numbers are displayed in a table format, with one minor issue - if the number happens to be negative, the text color of its cell needs to be red. <table& ...

Three dots implemented in the heading of a card

In my Bootstrap 4 project, I am aiming to design a card header with three distinct parts. The left part will showcase the author. The middle section will present a preview of the content. The right part will display the date. Specifically, I want the mid ...

What's the best way to incorporate necessary styles into text using particular fonts?

Is there a way to set letter spacing and word spacing for text on my website with the font 'classylight'? Adding classes to each post in the site map seems like a lengthy process. To save time, I attempted to use the attribute*=style property to ...

Unable to reach the dropdown menu in CSS

Having trouble with creating a dropdown navigation bar? I've encountered an issue where the dropdown menu disappears as soon as I move my cursor off the buttons that reveal it. The menu itself displays properly, but accessing the drop down menu is pro ...

Unexpected Error with Background Position Variable

Hello, I am attempting to create an animated background effect that moves up and down using the .animate() and .hover() methods in jQuery. Within my DOM, there is a div with id="#menu" containing a UL list where each item has a background positioned at dif ...

Ways to apply autofocus to one element once another element already has it?

I have encountered an issue while attempting to give a textarea autofocus using the autofocus attribute. Upon doing so, I receive an error message in the console that says: Autofocus processing was blocked because a document already has a focused element. ...

What is the best way to showcase an ajax response on an HTML webpage?

Apologies for the length of the code, but I'm looking to condense it while maintaining the same functionality. Is there an alternative approach or method that could achieve the same results? I receive data from PHP, which is then passed to JavaScript ...

The navigation bar and column layout is not functioning properly in Firefox

Hey there! I'm having a little issue with my website. When I view it in Chrome, everything looks perfect - the logo is left aligned at the top right and the testimonials section at the bottom has a nice 3 column layout. But when I try to open it in Fi ...

tips for aligning bootstrap flex items horizontally in multiple div containers

Is there a more efficient method to align flex items in different div flex containers so that the flex items have the same width, as shown below? <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" ...

Learn how to incorporate a vertical divider pipe into your website using Bootstrap

Hello, I'm having trouble adding a separator between nav-links that actually works. I tried adding the following code snippet: nav-link:after { content:"|"; } But unfortunately, it's either not working at all or appearing on the left side of th ...

Distinguishing Features of HTML, Canvas, and WebGL

Is there a way to draw images in WebGL with the same quality as HTML, even when downscaled? I've noticed that scaling down images in WebGL results in poor quality compared to HTML. After reading about 'Handling High DPI (Retina) displays in WebGL ...