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

Disabling the child element from triggering the parent element's onclick function, while still allowing it to respond to its own content

My list elements have onclick-functions that change the display of each element and its child div, moving them to the top of the list. Clicking again reverses this effect. The issue arises because the child div contains search fields, clickable pictures, ...

CSS Animations are effective in CodePen, but unfortunately, they do not function properly once integrated into an ASP.Net project

I created a unique design on codepen with a background animation, which functions properly there. However, when I integrate it into my ASP.Net Core project, the animation doesn't work as expected. The file references seem correct because the backgroun ...

Guide on how to prevent Paste (Ctrl+V) and Copy (Ctrl+C) functionalities in a TextField within MaterialUI

Is there a way to restrict the Paste (Ctrl+V) and Copy (Ctrl+C) functions in a specific TextField within MaterialUI? I am currently working with ReactJs ...

How can I avoid anti-aliasing in browsers when enlarging images?

Back in April 2012, Google's Chart Image API became deprecated but it was possible to generate QR codes using it. Although I know that I can adjust the size of the image produced by the API, I prefer to simply use CSS along with the width and height ...

Struggle with Arranging Elements in CSS using position absolute & relative

Currently tackling a project involving adjusting the positioning of elements within a sidebar. The sidebar holds Font Awesome icons and corresponding text elements, with the goal of moving both the icons and text together as one unit using attribute and cl ...

Spin only the outline with CSS

I have a unique idea for my webpage - three spinning circles surrounding text, while the text itself remains stationary. My challenge is to achieve this effect using only CSS, specifically by utilizing the .spinner-border class from Bootstrap. I cannot ma ...

Arranging the placement of list-group-item buttons

Looking for a way to create a list-group-item with two buttons that are equal in height and aligned to the right? Take a look at this example below: While I have the basic structure in place, I'm having trouble getting the buttons to position correct ...

Unique arrangement of hexagons in a honeycomb layout with precise centering

Currently, I am having trouble creating hexagonal blocks with content in a specific layout. My goal is to have four blocks starting with one at the top, followed by a row of two, and finishing with a row of one as shown in the image below. Unfortunately, a ...

Tips for creating a stylish navbar with a faded effect on the right side and integrating a fresh button into its design

I'm looking to enhance my Navbar by implementing a feature where, if the width of the Navbar exceeds that of its parent div, it will fade on the right side and a new button will be added - similar to what can be seen on Youtube. 1- When the Navbar&ap ...

The images in Bootstrap-Grid at 1920 resolution stay compact

Is there a way to make images grow beyond the 1280 resolution? This is how it appears at 1920 resolution https://i.sstatic.net/JmYc7.png And this is at 1280 resolution https://i.sstatic.net/Sk19K.png <div id="logokutu1" class="d ...

Angular 2.0 in conjunction with D3.js does not style SVG elements using CSS

Currently, I am utilizing Angular 2.0 TypeScript along with the d3.js library to create graphics. My main focus is on applying CSS to the axis (especially shape-rendering: crispEdges;). Do you have any suggestions? Check out the code below: var vis = d3 ...

Is it possible to design and implement Materialize CSS inputs without relying on Materialize CSS?'

Is there a method to implement Materialize CSS input elements that include placeholders and icons without directly using the Materialize CSS framework? I prefer not to mix frameworks in order to avoid potential conflicts, as I am already utilizing anothe ...

Deleting an item from a Vue.js list

I'm currently working on a project to develop a basic webpage that allows users to add or remove textboxes using vue.js. new Vue({ el: "#app", data() { return { list: [] }; }, methods: { deleteFromList(index) { this ...

Guide on creating a square within an element using JavaScript

After conducting thorough research, I find myself unsure of the best course of action. My situation involves a Kendo Grid (table) with 3 rows and 3 columns. Initially, the table displays only the first column, populated upon the page's initial load. S ...

What is causing my Javascript media query for the sidebar to not function properly?

I am working on implementing a sidebar that slides out 250px using JavaScript on the desktop view. However, I want the sidebar to take up 100% width when viewed on mobile devices. Despite my attempts to use Media Queries in JavaScript to achieve this, I am ...

Angular 13: Problems arise with custom theme in Angular Material version 13

I've set up a custom theme palette for my project that works perfectly with version ^12.2.13 of Angular Material, but not with ^13.2.3. Here's the SCSS code for my custom theming: my-custom-theme.scss @import '~@angular/material/theming&apo ...

Functionality Issue: Submit Button Not Working on Designed Form Select

Through dedication and hard work, I managed to create a customized form with images that display correctly in Firefox, Chrome, and Internet Explorer's compatibility mode. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...

The submit button is getting disrupted by the background image being set

Implement the following CSS code to set a background image on a single-page app (Angular). .page::before { content: ''; position: absolute; background-size: cover; width: 100%; height: 100%; background-image: url("../../assets/weird. ...

Having trouble adjusting the appearance of the dropdown menu in Angular Material's Select component

I've been attempting to adjust the style of the overlay panel within an Angular Material's MdSelect component in order to change the default max-width property of 280px. I have tried various methods, such as using '!important' to overr ...

Tips for adjusting the animation position in Off-Canvas Menu Effects

I am currently utilizing the wave menu effect from OffCanvasMenuEffects. You can view this menu in action below: ... // CSS code snippets here <link rel="stylesheet" type="text/css" href="https://tympanus.net/Development/OffCanvasMenuEffects/fonts/f ...