Divide text to reduce its width within the confines of a specific height on a div element

I've spent the past week scouring various forums, including stackoverflow, but I haven't been able to find a solution.

In my responsive website, I'm using CSS flexbox to display dynamic menu items. Sometimes the text can be quite long, and if there's enough space vertically in my div, I'd like to split the text into multiple rows to minimize the width.

Here's an example:

HTML

<div class="wrapper">
    <div class="text">
        Hello pouc nice to meet you!
    </div>
    <div class="text">
        It would be a great pleasure to help you ;-)
    </div>
    <div class="text">
        Seriously, if ever you had an idea I would be very glad!
    </div>
</div>

CSS

.wrapper {
    display: flex;
    flex-direction: row;
    overflow-x: auto;

    height: 80px;
    width: 400px;
}

.text {
    flex-shrink: 0;

    background: pink;
    margin: 2vh;
}

Here is a link to what I am trying to achieve: http://jsfiddle.net/etL630ew/2/

The current result is shown at the top, and at the bottom, I have added brs to simulate what I am aiming for.

Any solutions using only CSS would be greatly appreciated. If CSS alone won't cut it, then any JavaScript solution would also work!

Thank you for taking the time to read this.

Pouc

Answer №1

Make sure to delete the line flex-shrink: 0 within the .text CSS rule

.wrapper {
  display: flex;
  flex-direction: row;
  overflow-x: auto;
  height: 80px;
  width: 400px;
}
.text {
  background: pink;
  margin: 2vh;
}
<div class="wrapper">
  <div class="text">
    Hello, nice to meet you!
  </div>
  <div class="text">
    Would love to assist you with anything ;-)
  </div>
  <div class="text">
    Feel free to share any ideas you have!
  </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

The error message "Cannot access 'id' property of undefined" is being displayed

I have a file named auth.js along with a middleware called fetchuser. The code provided below is causing an error that I cannot figure out. The error occurs during the process of sending a token to the user and verifying whether the user is logged in or n ...

By-passing Mistakes in Iteration in JavaScript

I have been working on using Google's Feed API to fetch images from a feed within an AngularJS controller. It successfully retrieves three images, but encounters an issue when it reaches a Twitter URL, causing the script to break. I would like it to s ...

Delay the axios get request in the useEffect

Working with React JS, I have implemented a useEffect hook to request data from a database via an Express server when the page renders. However, if the server is down, the app will continue to make thousands of requests until it crashes. Is there a way to ...

Error: Module not located - Unable to resolve 'crypto'

Upon running ng serve, I encountered a list of errors that need to be addressed. Here is my package JSON configuration: { "name": "ProName", "version": "0.0.0", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "tes ...

Learn the process of programmatically concealing subtext information for certain options within a select-picker

Dropdown Menu <select class="dropdown-menu form-control " name="name_id"> <option disabled selected value> -- choose an option -- </option> <option id="classes" value="class&qu ...

What sets npm install apart from manual installation?

I've been exploring requirejs recently. I'm trying to decide between installing it using npm install requirejs or manually downloading it from the website. Are there any differences between the two methods? Are there any advantages or disadvantag ...

Using PHP Hover should apply CSS styles exclusively to the specified element

I have a piece of PHP code that displays cards. What I need: When a user hovers over the entire element, I want to make the title bolder, move the arrow to the left, and zoom in on the image of that particular hovered element. <div class="posti-class ...

Focus on targeting each individual DIV specifically

Is there a way to toggle a specific div when its title is clicked? I have tried the following code snippet: $( '.industrial-product' ).find('.show-features').click(function() { $('.industrial-product').find('.ip-feat ...

What is the best way to organize text within messages?

Hey there! I have a messaging app with arrays of messages. [{"id":4, "user_id":1, "messageable_id":3, "messageable_type":"conversation", "text":"Text 1", "action":null, "target_id":null, "created_at":"2019-06-17 15:47:55", "updated_at":"2019-06-17 15:47:5 ...

Variations in the appearance of scrollbars on the x-axis and y-axis within a single <div> element

Let's say we have a div element like this: <div class="nav-menu"></div> I want to customize the CSS style for scrollbar using the ::scrollbar pseudo-element: .nav-menu::-webkit-scrollbar { width: 8px; background: white; ...

"Discrepancy in Alignment of Bootstrap's Dual Column Layout

Currently, I am in the process of designing a straightforward two-column layout. This layout will consist of one prominent image at the top followed by two columns underneath - one for images and the other for text. https://i.sstatic.net/sYphQ.png Howeve ...

What is preventing me from using JavaScript to generate labels?

My current project involves creating dynamic input fields to filter products by color. I initially attempted static checkbox inputs for this purpose, which worked fine. Now, I want to achieve the same functionality but dynamically through JavaScript. Inste ...

AngularJS feature that enables resizing modal popup dimensions through a modal service

Currently working on an AngularJS application and in need of opening a specific modal popup with larger dimensions. Are there any AngularJS libraries available that cater to customizing modal popups? Explored AngularStrap (http://mgcrea.github.io/angular-s ...

Utilize an array with dynamic referencing

I am attempting to reference a single index out of 30 different indices based on the user's actions, and then utilize ng-repeat to iterate through each item in the index. Controller: $scope.meals = [ { title: 'Abs', url:"#/app/mworkout ...

Fixed Navigation Menu on Top with Specific Width Size

Currently diving into the world of CSS and eagerly following a tutorial on creating a responsive menu for my website. Managed to get it up and running, but hit a few roadblocks along the way: The navigation menu seems to shrink in both desktop and mobile v ...

The radio button allows for the selection of multiple items, rather than just one at a time

https://i.sstatic.net/9MEzS.png I have implemented a radio input as shown below <input type="radio" id={el.name} className="form-check-input" name={el.name} data-count={el.name} value={el.id} onChange={this.select_role.bind(this)} style={{margin: "4px ...

What is the best way to add to a variable in jQuery?

I have the following piece of code: var golden_site = '<div id="golden_site"></div>'; $('.form_content').append(golden_site); var lookup = '<input type="text" name="lookup" value="test">'; Can anyone explai ...

Problem with looping through arrays in JQuery using .each() function

Looking for some help with jQuery and JavaScript, please bear with me if my question seems naive. I am attempting to load images from different folders into corresponding divs to create a gallery. <div id="menu"> <div class="gallery" id="div0"&g ...

Is it possible that Typescript does not use type-guard to check for undefined when verifying the truthiness of a variable?

class Base {} function log(arg: number) { console.log(arg); } function fn<T extends typeof Base>( instance: Partial<InstanceType<T>>, key: keyof InstanceType<T>, ) { const val = instance[key]; if (val) { ...

CSS - Resizing Images

I am experiencing an issue with the width of an image on my website. I want it to span 100% of the browser frame, but it is currently limited to only 1000px wide. Please take a look at: The image in question is located at the top of the page. Is there a ...