"Exploring the versatility of the width property in flexbox

If I change the flex-wrap to nowrap in the given code snippet with a width of 33.3333333333%, what would be the new calculation for the width?

.box{
  color: white;
  font-size: 100px;
  text-align: center;
  text-shadow: 4px 4px 0 rgba(0, 0, 0, 0, 1);
}

.box1{ background: #1abc9c; }
.box2{ background: #3498db; }
.box3{ background: #9b59b6; }
.box4{ background: #34495e; }
.box5{ background: #f1c40f; }
.box6{ background: #e67e22; }
.box7{ background: #e74c3c; }
.box8{ background: #bdc3c7; }
.box9{ background: #2ecc71; }
.box10{ background: #16ae85; }


/* flex property for parent(container) - start */
/* Wrapping flex items */
.container{
  display: flex;
  border: 1px solid goldenrod;
  height:100vh;
  flex-wrap:nowrap; /* changed value */
}
/* flex property for parent(container) - end */

.box{
  width: 33.3333333333%; /* New calculation here */
}
<!doctype html>
<html>
  <head>
  <meta charset="UTF-8">
  <title>Sample document</title>
  <link rel="stylesheet" href="style.css">
  </head>
  <body>
     <div class = "container">
      <div class = "box box1">1</div>
      <div class = "box box2">2</div>
      <div class = "box box3">3</div>
      <div class = "box box4">4</div>
      <div class = "box box5">5</div>
      <div class = "box box6">6</div>
      <div class = "box box7">7</div>
      <div class = "box box8">8</div>
      <div class = "box box9">9</div>
      <div class = "box box10">10</div>
     </div>
  </body>
</html>

Answer №1

When it comes to this scenario, all flex items will shrink equally until their content prevents them from shrinking further.

They shrink equally because the default value of flex-shrink is 1.

The items stop shrinking at the width of their content because the default value of min-width is auto, ensuring that an item cannot be smaller than its content.

This behavior can be changed by setting min-width to 0, or using overflow: hidden on the flex items.

Check out the stack snippet below:

.box{
    color: white;
    font-size: 100px;
    text-align: center;
    text-shadow: 4px 4px 0 rgba(0, 0, 0, 0, 1);
}

.box1{ background: #1abc9c; }
.box2{ background: #3498db; }
.box3{ background: #9b59b6; }
.box4{ background: #34495e; }
.box5{ background: #f1c40f; }
.box6{ background: #e67e22; }
.box7{ background: #e74c3c; }
.box8{ background: #bdc3c7; }
.box9{ background: #2ecc71; }
.box10{ background: #16ae85; }


/* flex property for parent(container) - start */
/* Wrapping flex items */
.container{
    display: flex;
    border: 1px solid goldenrod;
    height:100vh;
    flex-wrap:wrap; /* default value. */
    flex-wrap: nowrap;

}
/* flex property for parent(container) - end */

.box{
    width: 33.3333333333%;
    overflow: hidden;
}
<div class="container">
  <div class="box box1">1</div>
  <div class="box box2">2</div>
  <div class="box box3">3</div>
  <div class="box box4">4</div>
  <div class="box box5">5</div>
  <div class="box box6">6</div>
  <div class="box box7">7</div>
  <div class="box box8">8</div>
  <div class="box box9">9</div>
  <div class="box box10">10</div>
</div>

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

Leveraging jQuery to automatically fill in a time field while excluding other buttons

I've been working on using jQuery to automatically fill in a time input field. The functionality is working properly, but the time is also being applied to my other button. How can I make sure it only gets assigned to the time input field? I would re ...

Adjust the class of the iframe element when clicked

I am attempting to change the class of an iframe (soundcloud embedded track) when it is clicked, in order to apply different properties. However, my code doesn't seem to be working as expected. Here is what I have: Here is a snippet from my index.htm ...

Finding a specific element within a table using xpath in selenium proved to be a challenge

I am trying to click on a specific button inside a table where each row has an update button. Here is what my table looks like: <table _ngcontent-vhp-c82="" datatable="" id="dtOptionsComments" class="display table tabl ...

Safari-exclusive bug: jQuery offset() function malfunctioning and producing highly inaccurate results

My goal is to retrieve the top offset values of a series of elements on my webpage. I am cycling through each element and recording its top offset value like this: $(elements).each(function() { var element = $(this); var offset = Math.floor($(elem ...

How can I ensure my game or website fits perfectly on the screen without any need

I have recently developed a fun Erase-A-Man game that is optimized for mobile devices. However, I am facing an issue where users need to scroll to view all the letters on their screens. My goal is to make the game fit perfectly on all phone screen sizes so ...

"Exploring the technique of extracting substrings in JavaScript while excluding any symbols

I am working on a JavaScript web network project and I need to use the substring method. However, I want to exclude the colon symbol from the substring because it represents a hexadecimal IP address. I do not want to include colons as part of the result. H ...

Switch the angular attribute by clicking on ng-click

I have a Google Map set up with markers that I need to switch on and off. <marker id='{{marker.id}} 'visible="{{ condition ? 'true' : 'false'}}"> </marker> Additionally, I have created a button to control the v ...

The red error text below the input becomes less visible when the input is focused on Windows, creating

My issue involves a basic input field and error validation message, both set against a dark background. The problem arises when the error text is displayed and I click on the input field - the error text suddenly loses contrast and appears "thinner." What& ...

My website gets all wonky when I try to resize the browser

Here is a visualization of my website's ideal appearance: However, the actual display varies on different computers. After testing with browsershots.org, I noticed that my website looks messy on most browsers and even when resizing the browser window ...

Struggling to update a scope variable when utilizing Firebase's Facebook authentication with AngularJS

Hey there... I'm currently exploring AngularJS and attempting to implement Facebook's connect feature using Firebird. Almost everything is running smoothly - the connection to my Facebook account is successful, and the information is retrieved w ...

Centering PayPal buttons horizontally with a width specified as a percentage

Take a look at this interactive coding playground showcasing the following React code: import React from "react"; import ReactDOM from "react-dom"; import { PayPalScriptProvider, PayPalButtons, usePayPalScriptReducer } from " ...

Creating a thumbnail with a close button using an image

My code is available at the following link: https://codepen.io/manuchadha/pen/PBKYBJ In this form I have created, I am trying to implement an image upload feature using a file input. The goal is to display a thumbnail of the selected image below the file ...

MUI: Issue with pseudo element appearing cropped outside of Paper container

I am facing an issue where a red arrow pseudo element '::before' is partially cut off outside its container '.MuiPaper-root'. I need the arrow to remain visible, any suggestions on how to fix this? Here is the relevant code snippet and ...

Organize JSON array information into HTML elements

Here is an example of JSON data: {"_id":"56af2ca2eb91bd4721443037","username":"xxxxxx","userGroup":[{"groupName":"nodeJs","groupAssigned":"No","_id":"56b086ccd1bc72eb21d99c62"},{"0":{"groupName":"php","groupAssigned":"No","_id":"56b0880d13c9fc4c22a1d291"} ...

Utilizing React Classes Based on Conditions

I'm attempting to add the class active if commentBadgeActive is true. The Scholar image should transition from grayscale to colored. <Paper className={classes.paper}> <div className={classes.profile}> < ...

Request to api.upcitemdb.com endpoint encountering CORS issue

This code may seem simple, but for some reason, it's not working as expected. What I'm trying to achieve is to call the GET API at: I want to make this API call using either JavaScript or jQuery. I've attempted various approaches, but none ...

unitary incline division assemblage

I noticed a particular element in the design that is currently displayed with an image (png). However, I am facing limitations due to needing to make it adaptive. Can a gradient be used as a sub-element instead? background-image: linear-gradient(to left, ...

Tally the number of items using the jQuery AJAX method and the

Extracting information from an XML DB looks something like this: <record> <eventname></eventname> <company></company> <city></city> <state></state> </record> The data is then parsed usi ...

Troubleshooting Problem with Card Layout in Basic Bootstrap Template

While using a basic Bootstrap template from Mobirise for my website, I ran into an issue. I am trying to create 5 Bootstrap cards with buttons in a row, instead of the maximum of 4 that is currently available. You can view an example of these cards here: ...

Looking to bookmark Java links or a similar task?

Apologies for the lackluster title, as I am not well-versed in programming language and struggle to articulate my specific request... Allow me to explain: I frequently need to visit a particular website to conduct research (details below). I attempted usi ...