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.

Here is the website when it's slightly minimized.

This is the website when it's completely minimized.

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

Designing a fluid dropdown menu with scroll functionality for my website

I have been trying to implement a scrollable dropdown menu on my website by following various tutorials, but none of them seem to be working. Despite my efforts, the dropdown menu remains non-scrollable. HTML <li> <a href="#">Team ...

I have a flex box with an image and text line inside. How can I adjust the width of the box and text to automatically match the size of the image?

Consider the code snippet below: <style> .img_box { display: flex; } </style> <div class=img_box> <img src=img/> <div>Title text of varying length. It may exceed the image's width or be smaller.</div> & ...

Tips for dynamically adjusting the size of a div container according to the user's

I have been working on a unique landing page design featuring a menu made up of custom hexagons. I aim to make these hexagons dynamically adjust to fill the entire screen based on the user's resolution, eliminating the need for scrolling. For a previ ...

To replace basic SVG icons upon clicking with the use of HTML, CSS, and jQuery - here's how!

I have a simple question about inline SVG icons and how to handle them in HTML, CSS, and jQuery. Despite reading numerous resources, I still struggle with implementing the functionality where clicking on one icon changes it to another. My objective: To to ...

Remove any unnecessary white space and new lines from the HTML code

Is there a way to remove double whitespaces and new lines from my HTML output without altering the ones within textarea and pre tags using PHP? ...

Preventing click events with pointer-events property in CSS while still allowing scrolling

Is there a way to use pointer-events: none to disable click events on a specific container while still allowing scroll functionality and an overlay? You can view my fiddle here: https://jsfiddle.net/1eu6d3sq/1/ Currently, when I apply pointer-events: non ...

Changing base 64 into Mp3 audio format using PHP

I currently have an "audio" tag with a script (which is essentially a plugin) that receives and saves it as base64. This functionality is working properly. My goal now is to modify the script in order to send the base64 data to the server, convert it to m ...

How to make sure a bootstrap row fills the rest of the page without exceeding the height of the screen

In my Angular application, I am using bootstrap to create the following structure (simplified version). <div class="container"> <div class="header> <div class="mat-card> <!-- Header content --> < ...

What could be causing my React components to not display my CSS styling properly?

If you're developing a React application and integrating CSS for components, ensure that you have included the style-loader and css-loader in your webpack configuration as shown below: module.exports = { mode: 'development', entry: &apo ...

Arrange the icons in multiple rows to ensure an equal distribution of icons on each row

There are 12 image icons displayed in a row within div elements using display: inline-block. However, when the browser window is resized, I would like the icons to be arranged on two or more rows so that each row contains an equal number of icons. ...

Fatal error in CodeIgniter occurring while invoking CSS less functions

Whenever I try to execute this function, I encounter the following error message: "Fatal error: Uncaught exception 'Exception' with message 'load error: failed to find test.less' in C:\xampp\htdocs\project\applic ...

The function .val() is not a recognized method

hello everyone here is the section of my HTML code: <div class="radio"> <input type="radio" name="certain" id="oui" value="oui"/> <label for="oui"> oui </label> <br /> <input type="radio" name="certain" id=" ...

Achieving the ideal positioning of content within the flex property

I am facing an issue with my containers, specifically .grid.left and .grid.right. The images within each of these grids are dynamic and enclosed within another div called .gallery. The problem arises when I apply margins to the image boxes, causing gaps w ...

Error Encountered: Bootstrap Dropdown Menu Malfunction in Master Page

I'm struggling to make my Bootstrap drop down menu function properly. Nothing happens when I click on the link, no dropdown appears. I've set up my nav bar in a master page and have spent hours trying to troubleshoot it without success... This i ...

Gain command over the underline style of text without relying on the border property

Ingredients: just a simple text input field. Question: Is there a way to customize the size, color, and position of the underline styling on an input tag? I noticed that the property text-decoration-color is supported in the moz browser engine, but I&apos ...

The {shade} of the code has been modified within brackets

Ever encountered your code's colors abruptly changing to red and green in the middle of an HTML page? My editor is Brackets, and while it doesn't pose any issues, it's really bothersome and makes the code difficult to read: Take a look at t ...

Issue with HTML While Utilizing wp_get_attachment_image

This script : $source = wp_get_attachment_image( get_the_ID(), 'medium' ); $weburl = wp_get_attachment_image_url( get_the_ID(), 'full' ); echo( '<p><a href="%s"><img src="%s"></a></p>', $weburl, ...

Tips for displaying the webpage background above a specific div by utilizing a differently shaped div

I designed a webpage with a background image. At the top, I placed a div element (let's call it div_1) set to 50% width which creates a horizontal black bar with 60% opacity. Directly above that, towards the left at 50%, I want another div element (di ...

Mobile device causing issues with sticky footer functionality

Can anyone help me troubleshoot an issue with my sticky/floating bottom footer on a calorie calculator? It works fine on desktop but not on mobile. Any ideas what might be causing the problem? HTML: <footer class="footer"> <div class="summar ...

Linking Two HTML Components in Angular 4 with Identical Values

Recently, I've started working with Angular and encountered an issue. In a table row, the value item.md_id is bound like this: <tr *ngFor="let item of driverData"> <td class="align-right" id="md_id" [(ngModel)]="item.md_id" name="driverId ...