Maintaining the size and proportions of an object as it

I'm currently learning the ins and outs of HTML/CSS while working on a navigation bar. However, I've run into an issue with scaling. Here is the website in full-screen mode.https://i.sstatic.net/kCFqn.png

Here is the website when it's slightly minimized. https://i.sstatic.net/b1H9w.jpg

This is the website when it's completely minimized. https://i.sstatic.net/UtuxY.jpg

As you can see, when I scale the website to different sizes, the proportions go haywire, causing overlap. Despite my efforts to make the children absolute and keep the containers relative, and using em's for measurements instead of pixels, I still face this issue. Is there a way to maintain proportionality while scaling?

Here's the js fiddle: https://jsfiddle.net/2w1r136j/2/

HTML

<div class="container">
  <header>
    <nav>
      <img class="logo" src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/8a/Westworld_Logo.svg/2000px-Westworld_Logo.svg.png" alt="logo">
      <div class="leftNavContainer">
        <a href="#">Home</a>
        <a href="#">Story</a>
      </div>
      <div class="rightNavContainer">
        <a href="#">Characters</a>
        <a href="#">Create</a>
      </div>
    </nav>
  </header>
</div>

CSS

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #222;
  font-size: 1em;
}

.container {
  width: 100%;
  height: 100%;
  position: absolute;
}

header {
  background: white;
  height: 3.5em;
}

.logo {
  height: 4.5em;
  width: 4.5em;
  position: absolute;
  left: 50%;
  margin-left: -50px !important; 
  display: block;
  margin-top: 0;
}

.leftNavContainer {
  position: absolute;
  float: left;
}

.leftNavContainer a {
  position: relative;
  display: inline;
  margin-right: 2em;
  margin-left: 2em;
}

.rightNavContainer {
  float: right;
}

.rightNavContainer a {
  position: relative;
  display: inline;
  margin-right: 2em;
  margin-left: 2em;
}

Answer №1

If you're considering Media queries, it could work, but a more efficient approach would be to utilize Flexbox or the advanced CSS Grid system. I've made enhancements in the fiddle by incorporating a flexbox layout.

Check out the updated fiddle here

HTML

<head>
  <title>
    Westworld
  </title>
  <link rel="stylesheet" href="css/style.css">
</head>
<div class="container">
  <header>
    <nav>
      <div class="leftNavContainer">
        <a href="#">Home</a>
        <a href="#">Story</a>
      </div>
       <img class="logo" src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/8a/Westworld_Logo.svg/2000px-Westworld_Logo.svg.png" alt="logo">
      <div class="rightNavContainer">
        <a href="#">Characters</a>
        <a href="#">Create</a>
      </div>
    </nav>
  </header>
</div>

CSS

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #222;
  font-size: 1em;
}

nav{
  display: flex;
  justify-content: space-between;
}

.container {
  width: 100%;
  height: 100%;
}

header {
  background: white;
  height: 3.5em;
}

.logo {
  height: 4.5em;
  width: 4.5em;
  position: absolute;
  left: 50%;
  margin-left: -50px !important;
  /* 50% of your logo width */
  display: block;
  margin-top: 0;
}

.leftNavContainer {

}

.leftNavContainer a {
  position: relative;
  display: inline;
  margin: 4px;
}

.rightNavContainer {

}

.rightNavContainer a {
  position: relative;
  display: inline;
  margin: 4px;
}

For more on Flexbox, check out MDN's resource:

Learn about Flexbox basics

Hoping this information proves helpful! 😇

Answer №2

If you want to adjust sizes at specific breakpoints, you can utilize media queries. For example:

@media only screen and (max-width: 600px) {
    body {
        font-size: .7em;
    }
}

Explore this live code snippet for a better understanding: https://jsfiddle.net/2w1r136j/7/

A great use of media queries is to create responsive designs that cater to mobile users. A common practice involves collapsing menu items into full width elements while increasing the font size.

Check out this example for reference: https://jsfiddle.net/2w1r136j/40/

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

Is there a way to send the element as an argument within the inner function?

I need to pass the selector as a parameter through the Slider to an Object nested function. I anticipated that istouchEnd would receive the .storage1 as a parameter from the Slider, but unfortunately, this.storage never gets the parameter from the Slider ...

Organize the HTML table upon importing

In my code, I am populating a table with data retrieved from a JSON object. Here is the JavaScript snippet: if (jsonObj[0].array !== 'undefined' && jsonObj[0].array.length > 0) { for (var i = 0; i < jsonObj[0].array.length; i++ ...

Animating a CSS overlay

My goal is to design an overlay using the following HTML and CSS code snippets div.relative { position: relative; width: 400px; height: 200px; border: 3px solid #73AD21; } div.absolute { position: absolute; top: 50%; right: 0; width: 20 ...

Link the Sass variable to Vue props

When working on creating reusable components in Vue.js, I often utilize Sass variables for maintaining consistency in colors, sizes, and other styles. However, I recently encountered an issue with passing Sass variables using props in Vue.js. If I directly ...

What causes the odd gaps at the bottom of boxes in a Pure CSS Masonry layout?

Issue with implementing Pure CSS Masonry layout. Using position: relative for the boxes and position: absolute for the content inside each box is causing gaps below each box. Struggling to find a solution, view the code on this codepen: http://codepen.io/k ...

Show a collection of files in a table format

Here is the current code I have: index.html <!DOCTYPE html> <html> ... </form> </div> </body> </html> And here is my code.gs function doGet() { return HtmlService.createHtmlOutputFromFile('index'); } ...

CLS notifies about an Unrecognized CSS Element in Page Insights' Core Web Performance

My experience with Google PageSpeed Insights has been quite frustrating due to the numerous alerts I'm receiving about Unsupported CSS Properties. The importance of avoiding non-composited animations: Animations that are not composited can appear gli ...

Unable to input information into Textbox in real-time

Having trouble entering data from one page to another using ng-model. After filling in some information in a textbox and moving to the next page, I want the same data to be entered when I return to the previous page. I've written the code but it doesn ...

Establishing a class for wp_nav_menu

Is there a way to transform the following code: <ul class="ulStyle"> <li class="liStyle"> <div class="first"> <div class="second"> menu1 </div> </div> </li> </ul> into wp_nav_menu? I'm struggling with ...

Having trouble with a switch statement in Javascript that is unable to find a case for "none."

In my code, I am checking to see if there is a ball in a specific map point and then changing the color of the pixels where the ball is located to match the color of the ball. Here is my code snippet: function UpdateColorInMapPoints(mapPointIndexs) { / ...

Styling in CSS to ensure scrollbar is constantly displayed without narrowing the container's width

Is it possible to have a vertically scrollable div with an always visible scrollbar without the scrollbar affecting the width of the elements inside? I attempted some CSS modifications, but the scrollbar still reduced the available width of the div. Is th ...

PHP: variables malfunctioning post implementation of "if" statement

Recently, I encountered a strange issue while working on a database processor. After processing the login information, the variables containing the data seemed to disappear and any subsequent actions within the "if" statement, which verified the login info ...

Button that vanishes when clicked, using PHP and HTML

I am in the process of creating an online store and I am seeking to implement a button that directs users to a new page, but then disappears permanently from all pages within the store. Here is the code snippet I have developed so far: <input class="b ...

Utilize OpenLayer3 to showcase Markers and Popups on your map

I am currently exploring how to show markers/popups on an osm map using openlayers3. While I have come across some examples on the ol3 webpage, I'm interested in finding more examples for coding markers/popups with javascript or jquery, similar to som ...

problem with the picture and wrapper expanding to fill the entire width of the screen

I'm having an issue with the image I added and its hover effect. The image seems to be leaving space on both sides of the screen, even though I've included background-size: cover and width:100% in my code. Could someone please point out where I ...

Challenging Trigonometry Puzzles in Javascript

In my project, I am creating an interactive application where a group of humans and bacteria engage in a game of chase. However, I encountered a problem where instead of moving directly towards their target, all entities would veer to the left. I attempt ...

What's the best way to place my image inside a Bootstrap Accordion so that it is housed within the accordion-item?

I've been facing an issue with a Bootstrap Accordion. Everything works fine, except when I try to insert an image <img src="https://placehold.co/600x400" class="img-fluid" /> into an accordion-item <div class="accord ...

Retrieving content from a div element

I am using Beautiful Soup to extract a list from HTML attributes. g_info = soup.find_all("div", {"id":"details_readonly"}) print g_info ## this prints out all the contents of the div tag. y = re.compile(r'B00(.{7})',g_info) print y The extrac ...

I am interested in altering the color of table rows using either JQuery or CSS

Looking to update row colors based on grouping. For example: Color the TR accordingly for every 5 rows: First 5 rows in green (0-4 Rows), Next five rows in red (5-9 Rows), Following five rows in yellow (10-14 Rows) and repeat the pattern... ...

Removing gaps around rounded corners in jQuery UI accordions is a common issue that often arises when styling web elements

I am currently using jQuery UI Accordion to create collapsible sections that expand when clicked. In order to enhance the appearance, I have applied a background image to the header of each section like this: Check out my jQuery UI Accordion Demo here Up ...