What is the best way to allocate a larger size to one part of a flex div?

A div is used to insert information

<div class="inputs">
    <div class="content">@Html.TextBoxFor(model => invoices.ProductDesc, new { disabled = "disabled", @readonly = "readonly" })</div>
    <div class="content">@Html.TextBoxFor(model => invoices.ProductSKU, new { disabled = "disabled", @readonly = "readonly" })</div>
    <div class="content">@Html.TextBoxFor(model => invoices.ProductQuantity, new { disabled = "disabled", @readonly = "readonly" })</div>
    <div class="content">@Html.TextBoxFor(model => invoices.ProductUnit, new { disabled = "disabled", @readonly = "readonly" })</div>
    <div class="content">@Html.TextBoxFor(model => invoices.IsMilled, new { disabled = "disabled", @readonly = "readonly" })</div>
    <div class="content">@Html.TextBoxFor(model => invoices.ProductUnitPrice, new { disabled = "disabled", @readonly = "readonly" })</div>
</div>

The use of display: flex is intended to format the content nicely, however it distributes the width evenly across all columns. More space is needed for the first div (ProductDesc).

How can I either increase the width of the first div or allow the text in that div to wrap to a second line when it exceeds the width?

I have attempted using overflow-wrap with break-word:

.content {
flex: 1 1 10%;
overflow-wrap: break-word;
}

I have also tried other overflow settings without success.

Additionally, converting these into a table layout is not an option due to data retrieval and mobile compatibility concerns.

Full code snippet:

// Code snippet goes here

Answer №1

For the first child elements, it's best to keep the width as auto without adding any flex values. The rest of the elements can be set to flex:1.

.inputs {
  display: flex;
  flex-wrap: wrap;
  margin-bottom: 1em;
}

.content {
  border: 1px solid grey;
  padding: .25em;
}

.content:not(:first-child) {
  flex: 1;
}
<div class="inputs">
  <div class="content">Lorem ipsum dolor sit amet consectetur, adipisicing elit. Asperiores, aliquid. Lorem ipsum dolor sit emet</div>
  <div class="content">Lorem ipsum dolor sit amet.</div>
  <div class="content">Lorem ipsum dolor sit amet.</div>
  <div class="content">Lorem ipsum dolor sit amet.</div>
  <div class="content">Lorem ipsum </div>
  <div class="content">Lorem </div>
</div>

Answer №2

I trust this meets your expectations:

Utilize the flex-wrap property to wrap the content and specify the desired width in the flex property.

Syntax:

flex: flex-grow | flex-shrink | flex-basis ;

flex-basis - specifies the width value.

If you want to break all words, you can use word-break:break-all;

.inputs {
  display: flex;
}

.content:first-child {
  background:lightblue;
  flex: 0 0 250px;  /* Specify the width as required */
  flex-wrap:wrap;
}

.content {
  background: red;
  flex-grow: 1;
}
<div class="inputs">
  <div class="content">1 content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content     </div>
  <div class="content">2</div>
  <div class="content">3</div>
  <div class="content">4</div>
  <div class="content">5</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

Is it possible to set the radius of a d3.js circle using a style attribute?

Learn more about styling in d3.js with this detailed guide that explains how style attributes can be leveraged to customize the look of a circle, including fill color, stroke color, and stroke width. Is it possible to adjust the radius of a d3.js circle u ...

Instructions for removing a class using the onclick event in JavaScript

Is there a way to make it so that pressing a button will display a specific class, and if another button is pressed, the previous class is removed and a new one is shown? Thank you for your assistance. function myFunction() { document.getElementById ...

Unable to manipulate JQuery lightSlider slides using element index

I've been working on a new page design at this link: The code is still a work in progress, so bear with me as I test out some functions and scripts. At the end of the first section, there are 4 logos that, when clicked, will trigger a modal to pop u ...

The Material UI button shifts to a different row

I need help adjusting the spacing between text and a button on my webpage. Currently, they are too close to each other with no space in between. How can I add some space without causing the button to move to the next line? const useStyles = makeStyles((the ...

When implementing CSS, the background image in the header section of my webpage is not visible to me

I'm currently working on a basic webpage and encountering an issue with setting an image as the background for my header section. Despite using what I believe to be the correct code in the CSS section, specifying the right path and file name for the i ...

Trouble encountered while trying to animate an SVG path

My attempt to animate an SVG is not working for some reason. https://i.stack.imgur.com/atTg3.png This is the component where I'm trying to load the SVG: import { JapanMap } from "../illustrations/japanMap"; export default function Home() ...

The overflow of CSS text selection color spills beyond the boundaries of the box

I'm just starting to learn CSS and was wondering if there is a way to prevent the text selection color from extending into the 'gutter' (I believe that's the correct term) like shown here: It may seem trivial, but I've observed th ...

What is the best way to create a button with a background image that is also transparent?

Is it possible to set a background image for a button in HTML with a transparent background using CSS? Here is the HTML code I currently have: <button style="background-image: url('../images/example.png');"></button> ...

Exploring the wonders of Bootstrap 3 panels and stylish floating images

Is it possible to create a responsive design using Bootstrap 3 panel along with a floating image positioned next to it? I want the panel to seamlessly fit into the available space, without overlapping the image. Can anyone provide guidance on achieving thi ...

Decrease the gap between rows in CSS Grid

I'm struggling to minimize the space between the rows. I've attempted adjusting margins and paddings to 0, but nothing seems to be working effectively. Displaying desktop view on the left and mobile view on the right side. .content{ margi ...

When adjusting the window size with the <ion-split-pane>, both the menu and router outlet disappear

When I have two ion menus and one main content (router outlet) and resize the page or switch to mobile view, the page appears blank as if the content is missing. Here is the code: <ion-app> <ion-split-pane> <ion-menu side="start" me ...

The <img> tag is displaying with dimensions of 0 x 0 pixels even though its size was specified

Is there a way to control the image size within an <img> tag placed inside an html5 video element? Currently, it keeps defaulting back to 0 x 0 pixels. The reason behind using this img is to serve as a fallback for outdated browsers where the video ...

Increase the border at the bottom while hovering with React.js and the Material UI library

Can someone help me achieve a hover effect similar to the one in this question on Stack Overflow: Hover effect : expand bottom border I am attempting to create the same effect in React using makeStyles of Material UI. Here is my current code: const useSty ...

What is the best way to align a value within CardActions in Material UI?

I'm currently facing an issue with my website design. Here's a snapshot of how it looks: Additionally, here is the code snippet related to the problem: <CardActions> <Typography style={{ fontWeight: 'bold', c ...

When the ::after pseudo element is utilized for creating a bottom border, it will display following each individual list item contained within the specified div

I have been using a pseudo-element to create a division line between sections, and it was working perfectly until I added a list of items. Now, the division line is appearing after every <strong> and <li> tag. I have tried various approaches, s ...

The HTML component fails to acknowledge width settings

I seem to be having trouble identifying an issue or perhaps I am misunderstanding something (I am using daisyui + nx + tailwind css + angular). To simplify my problem, let's consider the following scenarios: In the first scenario, I have: <div cl ...

Unable to eliminate top margin in Bootstrap 3 affix feature

Struggling to locate the source of the margin-top when utilizing the affix plugin on my Navbar. You can view [my website here] for better understanding. Should I be implementing Javascript to solve this issue? My current skills in that area are not very ...

Automatically adjust the image size in CSS to fit the screen when the iPhone is rotated from portrait to landscape

I am trying to create a responsive design where an image will fit the screen without being cropped in both portrait and landscape mode. I have attempted the following code: <!doctype html> <html> <head> <style> img { max-height ...

Why does text display differently in HTML (Firefox) on Ubuntu compared to Windows 7?

When viewing the HTML and CSS code in Firefox on Windows, everything appears fine. However, when I view it in Firefox on Ubuntu, it looks out of place. How can this be corrected? Any suggestions? Additional information: The CSS code used for the text show ...

What is preventing my image from moving upwards?

I've been struggling to move this image up, despite trying several methods. I really want it to be aligned horizontally with the PV picture. I need the HP image to be moved directly upwards so that it aligns horizontally with the PV image. This is t ...