Preventing div contents from shrinking with changing screen sizes

I am currently working on creating a portfolio website similar to this one.

Check out the Website Here

Typically, when the screen size is reduced to less than half of the full width, the content of a website tends to be hidden rather than shrinking. However, my website continues to shrink. How can I achieve this with CSS?

This is what I have accomplished so far using sass and React.js:

App.scss

$main-container-height: 87vh;
$navbar-height: 13vh;

/* Styles for Navbar */
.navbar {
  height: $navbar-height;
  text-transform: uppercase;

  .name {
    text-align: left;
    margin-left: 1.5rem;

    a {
      color: black;
      font-size: 25px;
      margin: 0 0 0 0.5rem;
      text-decoration: none;
    }

    .box {
      height: 15px;
      width: 15px;
      background-color: blue;
      display: inline-block;
    }
  }

  .nav-list {
    a {
      color: black;
      margin: 0 1.5rem;
    }

    a:hover {
      color: #519df9;
      text-decoration: none;
    }
  }
}

/* Homepage Styling */

.main-box {
  height: $main-container-height;
  min-width: 50%;

  .left-main-box {
    height: $main-container-height;
    width: 40vw;
    display: inline-block;
    background-color: #e8c9c9;
  }

  .right-main-box {
    display: inline-block;
    height: $main-container-height;
    width: 60vw;
    background-color: white;
  }
}

HomeMain.js

import React, { Component } from "react";
import CenterBox from "./CenterBox";
import Footer from "./Footer";

export class HomeMain extends Component {
  render() {
    return (
      <div className="main-box">
        <div className="left-main-box">left</div>

        <div className="right-main-box">right</div>
      </div>
    );
  }
}

Answer №1

I'm a bit unsure about what you're looking for as I can't seem to replicate the issue: when I decrease the screen width on the provided link, there is no shrinking effect for me in Firefox.

With that being said: My suggestion would be to start by designing your layout for smaller screens first, as it tends to be easier this way. To achieve this, you can utilize grid in combination with media queries.

For instance, you could use the grid-template-areas property and modify the layout using a media query. Once your template is set up correctly, you can use flex to align elements within containers.

Remember to incorporate min-width and max-width when utilizing responsive units.

Here's an example to illustrate (to give you a general idea)

/* mobile */
.main-box{
  display: grid;
  grid-template-areas:
    "header"
    "nav"
    "content"
    "footer";
}

/* desktop */
@media screen and (min-width: 1024px){
  .main-box{
    grid-template-areas:
      "header header header"
      "nav nav nav"
      "leftbox content rightbox"
      "footer footer footer";
    }

For further practice, you can explore more about grid and flex.

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

What is the best way to ensure that form inputs and labels stay aligned?

Let's consider a scenario where there is a web page containing a form: <form> <label for="FirstName">First:</label> <input name="FirstName" type="text"> <label for="MiddleName">Middle:</label> <input n ...

A combination of Webpack CSS modules with Angular templates

I am currently trying to integrate webpack CSS modules into my angular/ionic project. I'm wondering if it's possible for the CSS module class definitions to be correctly appended to an external template instead of an inline template. When I embe ...

Mobile navigation bar with Bootstrap transparency

I recently encountered a challenge with my Bootstrap navbar where I needed to remove the background. To achieve this, I applied the class "navbar-fixed-top" to the main wrapper. <nav class="navbar navbar-fixed-top"> After making this change, the na ...

Ways to adjust the background color

Is there a way to change the background color instead of font color in this code snippet? def cloud_height_style_function(vals): return pd.cut(vals,[-np.inf,199,499,999,3000, np.inf], # need to review the bin a bit labels=[f'color: ...

Steps for Adding a class or Id to an Ext.Msg.alert box

Is there a way to customize the style of a specific Ext alert box without affecting all alert boxes? Can someone please explain how to assign a class or ID to an Ext.Msg.alert box? Ext.Msg.alert('Status', 'Changes saved successfully.' ...

Phonegap Application: Page design gets distorted following keyboard input

After a user enters login details and the next page loads, the layout shifts as shown in the image below. The entire app layout breaks and the view moves down to accommodate the size of the onscreen keyboard. This issue persists unless the orientation is ...

Ways to Halt Every Single CSS Animation

Is there a way to stop all CSS animations in a document from the beginning? My idea is to assign a class to elements containing CSS animations at the start, such as '.paused'. Then, using jQuery in my JavaScript, I would remove the '.paused& ...

What steps can I take to ensure a website designed for Firefox will work seamlessly on Safari and Chrome browsers as well?

As someone who is still learning about web development, I find myself struggling with browser compatibility issues. It's frustrating to see my website looking different in Chrome compared to Safari. While I know that browsers interpret code differentl ...

Positioning MDL cards in HTML documents

Seeking guidance on positioning MDL cards alongside existing text. I've attempted various methods without success so far, and the desired outcome has not been achieved. The goal is to have text aligned to the left (which is currently satisfactory) wi ...

What is the term for the visual display of a product through a photo gallery or slideshow?

Can someone help me identify what the item I'm looking for? You can click on the link to see an example of the product: sephora product example What is the technical term for the section that contains product pictures and slides? Are there any librar ...

The drop-down menu seems to have disappeared from sight

I'm having an issue with getting a dropdown to appear in my registration form. Everything else in the form is displaying correctly and functioning properly, but the dropdown remains invisible. After searching extensively, I haven't been able to ...

Display a snippet of each employee's biography along with a "Read More" button that will expand the content using Bootstrap, allowing users to learn more about each team

I have successfully developed a Google App Script that links to a Google Sheet serving as a database. The application iterates through each row, and I showcase each column as part of an employee bio page entry. ex. Picture | Name | Title | Phone | Email ...

Margin and padding have the ability to increase the size of an image

Is there a technique to position the logo.png so that it appears approximately one-third of the way across the page without affecting its size? I've attempted to use padding or margin adjustments, but it seems to distort the image despite having limit ...

CSS-Only tooltip that adjusts size dynamically

Having trouble getting a tooltip to work exactly as desired? I need to implement tooltips for the contents of dynamically built HTML tables. It must be done with CSS only, without relying on JavaScript or events for performance reasons. The challenge is ha ...

Modify top position without affecting bottom alignment using CSS

I am currently working on a website that is designed to mimic a printable document. The layout consists of a header, body, and footer, with each element utilizing CSS for margin and height adjustments. The challenge lies in ensuring that the footer is alw ...

Exploring PHP Queries with Div Classes

I'm in desperate need of assistance. I'm currently working on putting together a website and pulling data from a mysql database. The specific div that I'm trying to populate is provided below. The issue I'm facing is how do I integrate ...

Input field, upon receiving focus, triggers a subtle shift in the position of the submit button

Thank you for the assistance, I believe this issue should be an easy fix. I have added a custom :focus style to my input that removes the default outline and adds a box shadow and border. However, when the input field is focused, the submit button located ...

Issues with the Content Editable Functionality

While working on my website, I encountered a strange issue. For some reason, I can't seem to get the contenteditable="true" attribute to work on the heading with the ID "hl". It would be awesome if someone could help me figure out how to mak ...

Is there a way to place two input fields from different forms side by side on the same line?

Here are two forms extracted from an html page: <form method="get" action="search/s" id="number"> <div style="text-align: center;"> <input type="text" id="regNo" name="regNo" size="30" maxLength="50" > or ...

SignalR enables the display of identical dashboard data pulled from queries on various browsers. By utilizing SignalR/hub, MVC, and C#.NET, the data can

Encountering an issue with my signalr/hub while fetching dashboard data. I'm using 2 browsers to access data based on dates. However, when searching for July on browser 1 and then switching to another month on browser 2, the data in browser 1 gets upd ...