When zooming in, the content exceeds the boundaries of the screen, creating a cropped effect. Conversely, when zooming out,

I'm working on a layout that includes a sidebar and a flexbox container with 3 boxes, where the middle one is scrollable.

My issue arises when I zoom in, causing content to go beyond the visible screen. On the other hand, zooming out leaves a white blank space on the right side.

To provide more context and seek assistance, I've included a video link and code snippet:

Watch the video here

* {
  margin: 0;
  padding: 0;
}

html,
body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  color: white;
}

.sidebar {
  width: 12%;
  height: -webkit-fill-available;
  position: fixed;
  top: 0;
  left: 0;
  background-color: black;
  overflow-y: scroll;
}

.container {
  position: fixed;
  left: 12%;
  height: 100%;
  width: 100%;
}

.navbar {
  background-color: grey;
}

...

... (continued)

... 

The provided CSS and HTML markup showcases how the layout is structured with each element's styling. Any suggestions or guidance would be highly appreciated!

Answer №1

Through the implementation of relative values instead of fixed ones, I successfully resolved the issue. The modifications made include:

  1. Adjusted width of .container class from 88% to 100% to allow it to expand freely.
  2. Given that the sidebar occupied 12% of the total space, the remaining space was divided equally between both containers by changing the width of the .box class from 100% to 44% ((100%-12%)/2=44%).
  3. The width of the .item class was set to 32.3%, totaling approximately 97%, with the excess 1% allocated as margin instead of a fixed 15px margin (An additional 1% padding was included for stability).

Note: Utilizing relative values is an effective solution in such scenarios. It's advisable to rely on relative values when developing websites.

Below is the revised code snippet:

* {
  margin: 0;
  padding: 0;
}

html,
body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  color: white;
  width: 100%;
  height: 100%;
}

.sidebar {
  width: 12%;
  height: -webkit-fill-available;
  position: fixed;
  top: 0;
  left: 0;
  background-color: black;
  overflow-y: scroll;
}

.container {
  position: fixed;
  left: 12%;
  height: 100%;
  width: 100%;
}

.navbar {
  background-color: grey;
}

.navbar h2 {
  text-align: center;
}

.fluid-container {
  background-color: rgb(193, 224, 236);
  height: 100%;
  display: flex;
  width: 100%;
}

.box {
  width:44%;
  background-color: black;
  border: 1px solid red;
}

.item {
  width: 32.3%;
  height: 100%;
  padding:1%;
  border: 1px solid green;
  margin:1%;
  background-color: sandybrown;
}

#item1 {
  height: calc(100vh - 100px);
}

#item2 {
  overflow-y: scroll;
  height: calc(100vh - 100px);
}

#item3 {
  height: calc(100vh - 100px);
}

.items-container {
  display: flex;
}
<div class="sidebar">
  <h2>Title 1</h2>
  <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Vitae, porro reprehenderit iure sed voluptates aperiam delectus excepturi inventore non, esse a repellat dolores obcaecati, libero dolor rerum aspernatur ullam? Nam?Lorem, ipsum dolor sit amet
    consectetur adipisicing elit. Error, molestias eveniet! Voluptate vel nam dolorem beatae explicabo neque reprehenderit delectus similique distinctio natus molestias, quae unde ducimus ea dolore illo quis aliquam hic consequatur incidunt quidem animi
    fuga eum mollitia? Veritatis temporibus magnam placeat facere deleniti dolorem consequatur praesentium! Voluptatibus cum, ducimus repudiandae, neque distinctio ad laudantium, vitae minus odit repellat praesentium ipsum laborum atque iste quibusdam
    perspiciatis assumenda corrupti.</p>

... [Remaining HTML code omitted for brevity] ... 

</div>

Answer №2

To ensure your layout works correctly, make sure to include height: 100%; and width: 100%; in the CSS for both the HTML and body elements. Additionally, set width: 88%; on your container class, as your sidebar is occupying 12% of the width, resulting in a total of 100%.

It's crucial to note that setting a fixed width like 220px on each item will prevent them from resizing responsively. Instead, use width: 100%; for better adaptability when zooming in or out.

* {
  margin: 0;
  padding: 0;
}

html,
body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  color: white;
  width: 100%;
  height: 100%;
}

.sidebar {
  width: 12%;
  height: -webkit-fill-available;
  position: fixed;
  top: 0;
  left: 0;
  background-color: black;
  overflow-y: scroll;
}

.container {
  position: fixed;
  left: 12%;
  height: 100%;
  width: 88%;
}

.navbar {
  background-color: grey;
}

.navbar h2 {
  text-align: center;
}

.fluid-container {
  background-color: rgb(193, 224, 236);
  height: 100%;
  display: flex;
  width: 100%;
}

.box {
  width: 100%;
  background-color: black;
  border: 1px solid red;
}

.item {
  width: 100%;
  height: 100%;
  border: 1px solid green;
  margin: 15px;
  background-color: sandybrown;
}

#item1 {
  height: calc(100vh - 100px);
}

#item2 {
  overflow-y: scroll;
  height: calc(100vh - 100px);
}

#item3 {
  height: calc(100vh - 100px);
}

.items-container {
  display: flex;
}
<div class="sidebar">
  <h2>Title 1</h2>
  <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Vitae, porro reprehenderit iure sed voluptates aperiam delectus excepturi inventore non, esse a repellat dolores obcaecati, libero dolor rerum aspernatur ullam? Nam?Lorem, ipsum dolor sit amet
    consectetur adipisicing elit. Error, molestias eveniet! Voluptate vel nam dolorem beatae explicabo neque reprehenderit delectus similique distinctio natus molestias, quae unde ducimus ea dolore illo quis aliquam hic consequatur incidunt quidem animi
    fuga eum mollitia? Veritatis temporibus magnam placeat facere deleniti dolorem consequatur praesentium! Voluptatibus cum, ducimus repudiandae, neque distinctio ad laudantium, vitae minus odit repellat praesentium ipsum laborum atque iste quibusdam
    perspiciatis assumenda corrupti.</p>
</div>
<div class="container">
  <div class="navbar">
    <h2>Header Section</h2>
  </div>
  <div class="fluid-container">
    <div id="box1" class="box">
      <h2 style="text-align: center; font-size: 2rem; margin-top: 5px;">Tri Column Title</h2>
      <div class="items-container">
        <div id="item1" class="item">
          <h2>Title 1</h2>
        </div>
        <div id="item2" class="item">
          <h2>Title 2</h2>
          <p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Rem deleniti, consequuntur officiis harum, fugiat debitis dolorem reiciendis odit qui illum deserunt veniam quaerat pariatur voluptatem et earum, numquam quidem in corporis incidunt aliquam
            quo sunt nulla culpa. Non architecto, assumenda libero error qui nulla dicta aut sunt et, corporis nam facere nobis...
        </div>
        <div id="item3" class="item">
          <h2>Title 3</h2>
        </div>
      </div>
    </div>
    <div id="box2" class="box">
      <div class="items-container">
        <div id="item1" class="item">
          <h2>Title 1</h2>
        </div>
        <div id="item2" class="item">
          <h2>Title 2</h2>
­          <p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Rem deleniti, consequuntur officiis harum, fugiat debitis dolorem reiciendis odit...dge

Answer №3

Include the following snippet at the beginning of your HTML file, inside the head section

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

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

Problem with modals not triggering within the iDangero.us swiper

I am encountering an issue with the iDangerous.us Swiper where I cannot activate any events within the swiper-wrapper. I am attempting to trigger a modal on each slide but nothing is happening. Any Modal placed inside the swiper-wrapper does not work. I a ...

Creating a Parent Container to Maintain the Height of the Tallest Offspring

I've been searching online for solutions, but so far I haven't found one that meets all the requirements. <div class="parent"> <div class="child1">I am 60px tall and always visible; my parent is 100px tall</div> <div ...

Creating HTML elements using JavaScript

Below is the code snippet in question: function getAllRecipes(){ $.ajax({ type: "GET", url: "https://api.npoint.io/7493fda05b8038212eed", beforeSend: function() { $("#AllRecipe").html('Fetching...') }, success: func ...

What methods does webpack use to minify CSS links within HTML code?

As a newcomer to webpack, I am looking to compress and reference linked CSS files in HTML. Below is the code snippet I am working with: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8> <meta name="viewport" ...

Is the <ul> tag aligning to the left?

I recently encountered an issue while designing my website. I created a div with a width of 200px on the right side of the webpage, and added a list of links within it. However, I noticed that elements inside the div are aligning slightly to the left, givi ...

Outline of a transparent right trapezoid shape

I'm attempting to create a slanted path line that resembles this particular image. The method I am currently using involves two trapezoid shapes, positioning one on top of the other to blend in with the background, as demonstrated in this jsFiddle ex ...

How can I make a clickable <div> easily navigable with tab functionality?

I am currently tackling a project that involves implementing an onclick event within a <div>. While I've successfully set up the primary functionality, there is one issue at hand. Specifically, I need the onclick event to trigger when a user nav ...

How to dynamically style NavLink using a variable in react-router-dom with Emotion?

Is there a way to extract styles to a variable when using react-router-dom's NavLink activeStyle prop? I want to avoid repeating the same styles without using a css file. Ideally, I would prefer to achieve this using Emotion, but if that's not f ...

Storing a database row value into a PHP variable using an SQL query

I am encountering a number of questions related to my issue, but as a beginner in programming, I am struggling to understand most of the solutions. The code snippet below is the only one that works for extracting data from my table, although it is carrying ...

Email sent upon form submission

Users have the option to provide feedback through a simple form below. Upon submission, the feedback will be sent directly to my email address. The subject line of the email will automatically read "Feedback from [name input]" and the email will show it&ap ...

How can I determine the specific font used in an image through Google Fonts?

I remember seeing how to do this once on a website, possibly html5rocks, but now I can't seem to figure it out. Maybe there is someone out there who can help me with this. I want to know what font was used in this picture and if it is hosted on Googl ...

What is the process for capturing a screenshot of a specific DOM element using Intern JS?

I'm currently utilizing intern.js for testing a web application. It allows me to run tests and generate screenshots in case of failures. My goal is to capture a screenshot of a specific element for conducting CSS regression testing with tools like res ...

Height of Nav-Links in Bootstrap 4

Is there a way to modify the height of the navigation links in Bootstrap? To set a specific height, such as for the navbar, you may encounter issues where it doesn't occupy the entire space. CSS CODE: .navLogo { width: 15%; height: 100%; } ...

Tips for linking to a page and dynamically adding a class to the body after it has been fully loaded

I've been working on a template that includes a blog.html file featuring various layouts: full-width layout 2 column layout 3 column layout 4 column layout I've customized the blog.html so that when specific classes are added to the body tag, ...

Ways to trigger the audio tags with keypress and click events

My current drum machine setup activates on keypress, but I would like to make it so that the audio tags can also be activated on click. Below is the HTML structure: <body> <div class="container"> <div class="row"> ...

Convert a list into nested JSON items by utilizing the getJSON function

Below is an example of a JSON object: {"sessions":[ { "totalusers":"2", "Users": [ { "id": 1, "name": "abc" }, { "id": 2, "name": "def" } ] } ]} Here is the corresponding HTML structure: <div> ...

Unusual images emerge following certain elements in this unique gallery

Looking for some advice on my image gallery created using an ordered list. The issue I'm facing is that the images are not all the same size, causing the 4th and 7th images to disrupt the layout. I have come up with a solution by using: ...

I am curious to see the number of people who have made their selection

I am currently using JavaScript to alter the text value from "select" to "selected". My next step is to include the selected text in a cart. Can you please provide some guidance? Thank you in advance. PHP CODE : <a class='btn slct' href=&ap ...

No defined parent for 'appendChild' operation

Seeking guidance on implementing a Solar System using THREE.js and encountering an issue: Error message: Cannot read property 'appendChild' of undefined Below is the current code snippet: <html> <head> <meta charse ...

How can we begin to create this dynamic animation?

Can someone help me figure out how to create an animation effect similar to the one seen in this link? I have some basic knowledge of css and html5, but I'm not sure where to start. Is this done with css, html5, plugins, or something else? I am looki ...