What is the best way to seamlessly transition from responsive design to mobile design?

While developing a single-page app, I encountered an issue with the layout when the screen width reaches a specific point. On narrow screens, I prefer to utilize the full width, but for wider screens, I want to limit the width for better readability. The layout mostly functions as intended, except when the screen is slightly larger than the defined limit, resulting in poor formatting.

You can view a representation of this issue on jsfiddle. Please note that the menu placement may differ due to jsfiddle settings (it should be in the top right corner).

The structure of the HTML code is:

<!DOCTYPE html>
<meta charset="utf-8" />

<head>
  <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
  <link rel="stylesheet" type="text/css" media="all" href="blah.css">
</head>

<body>
  <div id="page">
    <div id="menu">
      <a class="burger" href="#" onclick="document.body.classList.toggle('menu')">Menu</a>
      <table id="menu-table" class="open">
        <tr>
          <th>Menu</th>
        </tr>
        <tr>
          <td>Foo</td>
        </tr>
        <tr>
          <td>Bar</td>
        </tr>
      </table>
    </div>
    <div class="page" id="blah">
      <h1>Blah</h1>
      blah blah blah...
    </div>
  </div>
</body>

The corresponding CSS styling is:

#page {
  background: #fff;
  color: #000;
  width: 100%;
  padding: 1em;
  min-height: 200px;
  max-width: 700px;
  overflow: hidden;
}

body {
  padding: 0px;
  margin: 0px;
}

...

@media only screen and (max-width: 700px) {
  #page {
    margin: 0px;
  }
}

If you resize the window just slightly larger than the text area, the display on the right side becomes incorrect. Similarly, when you copy/paste the code into a local file, the menu does not display correctly at that particular width.

In addition, Safari displays the entire menu shifted off to the right instead of being hidden. This results in major visual glitches where part of the menu can even be selected and highlighted mistakenly. Clicking on it doesn't remove the highlighted selection from the ghost version either.

Answer №1

The issue I encountered with the overall formatting stemmed from the padding: 1em, as the max-width: 700px did not account for the padding. By adjusting it to padding: 0px, the problem was solved, and I introduced a margin: 1em to the enclosed div. I made sure to update the jsfiddle accordingly.

Unfortunately, the Safari bug persisted. I discovered a workaround by positioning the "hidden" version at -20000px - although it's quite a messy solution! This approach also interfered with my transitions.

Utilizing , I managed to achieve satisfactory transitions. While they may not be as visually appealing as before, they suffice.

Ideally, the position should be set at -200px; however, Chrome and Brave necessitate -201px, while Safari oddly requires -20000px!

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

Unique text: "Personalized button design without using SVG

I've been experimenting with creating a button using SVG, but unfortunately, it seems that SVG is not supported on Next.js & Material UI. Below you'll find the code snippet and screenshot I have been working with. Any help or guidance would be g ...

Customizing the appearance of jQuery accordion components

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js" language="javascript"></script> <script type="text/javascript" src="http://www.compactcourse.com/js/accordionNew.js" language="javascript"></script> < ...

Finding an element that lacks both a class and an id, and is not consistently present - what's the trick?

Currently, I am faced with a predicament in my code where a <li> element only appears under specific conditions, making it difficult to apply positioning. This element lacks an id and class attribute, which prevents me from targeting it accurately us ...

CSS styling not rendering consistently across various web browsers

Hey everyone! I've encountered an issue with my webpage. Feel free to check out the code on my CodePen here. When I view this page on Safari, everything looks perfect. However, when I switch over to Chrome or Firefox, the layout is all messed up. Ele ...

Shifting the MUI DataGrid Pagination table to the left with CustomPagination: A step-by-step guide

Hey everyone, I am currently diving into the MUI data grid to gain a better understanding. In order to meet my design requirements for a table view, I have incorporated the DataGrid component from MUI. For pagination, I am utilizing their custom implementa ...

Incorporating a delete button onto an image using JavaScript

I am currently developing a BlogApp and facing difficulty in attempting to include a button on an image. The image is being retrieved from the Django database in JavaScript (HTML). My goal is to have a clickable button overlaid on the image. views.py def ...

Display words on screen and then alter hue using HTML and CSS

Is there a way to dynamically change the color of text inside <a> tags from black to red after a specific time interval and keep it permanently red? do { document.getElementById("code").innerHTML +="<a>Hello World</a><br>"; awa ...

Navigation bar links not leading to the correct corresponding pages

Whenever I try to access index.php, it loads perfectly the first time, but I encounter an issue when trying to navigate to another page from the index page. Error: Object not found! The requested URL was not located on this server. The link on the ref ...

JavaScript button is not functioning properly to increase or decrease the value in the input field

I'm facing an issue with the javascript increase/decrease buttons on my website. When I assign my JS variable as the class name of the input field, pressing the button results in all input fields being affected simultaneously: https://i.stack.imgur.c ...

Is it possible to invoke a Python local function from an HTML document?

After creating a Python file with multiple functions, I am now working on designing a web page where I aim to trigger one of the functions mentioned earlier by clicking a button. However, I am unsure about how to go about this process. Is there anyone who ...

Ways to adjust the dimensions of a division element using Bootstrap

I have a CSS class called "brands" and I am looking to change the size of the thumbnail div within this brand class. How can I go about doing this? <div class="brands"> <div class="row"> <?php foreach ($item['brands'] ...

`Finding the appropriate place to define a variable within a React Component`

When attempting to declare the variable images within the component, I encountered an error. See the screenshot for more information: here. ...

How can I adjust the size and alignment of each line within a single cell in an HTML table?

<!DOCTYPE html> <html> <head> <title></title> <meta charset="UTF-8"> <style> .chess-board { border-spacing: 0; border-collapse: collapse; } .chess-board ...

The min-height property does not seem to be compatible with -webkit-calc

I've been experimenting with this code: .main{ min-height: -moz-calc(100% -50px); min-height: -webkit-calc(100% -50px); min-height: calc(100% -50px); background-color:#000; color:white; } html{ height:100%; } <html ...

Issues with LESS rendering on the Django production server

After deploying my Django website to the production server, I noticed that the LESS file is being loaded but not rendered. Strangely, everything works perfectly on the local server. Any insights on why this might be happening? ...

Tips for removing red borders on required elements or disabling HTML validation

I am on a mission to completely eliminate HTML validation from my project. Although this question suggests that having all inputs inside forms can help, I am using angularjs and do not require a form unless I need to validate all fields in a set. Therefore ...

Preventing box shadows from blending together

I'm struggling with a design issue on my site where I have four divs in the center, each represented by a box with a box-shadow. Unfortunately, the colors of the shadows are getting mixed up and creating an unwanted effect. https://i.sstatic.net/NdAUB ...

Implement a Selection Feature in Angular

Currently, I am working on an application where users can add new rows with the same fields. One of the requirements is to allow users to add an option to a select element. While I have successfully implemented this in jQuery, I am facing challenges integr ...

What could be the reason for the container div's height not being properly refreshed?

When adding elements to a container div with an initial height of 'auto', I assumed that the height would adjust based on the children elements added. However, this is not happening. Can anyone assist me in ensuring that the container div's ...

Retrieving extra data from JSON

Instead of just returning a success status in the JSON response from the controller, I would like to also include the person's name. Currently, the JSON response indicates whether the operation was successful and uses JsonRequestBehavior.AllowGet. T ...