Attempting to emulate the grid showcase using flexbox styling

Creating this layout using CSS Grid was a breeze. However, I wonder if it can be achieved with Flexbox. What do you think?

.Message {
  display: inline-grid;
  grid-template-areas: ". name""date text";
}

.Date {
  align-items: center;
  display: flex;
  grid-area: date;
}

.Name {
  grid-area: name;
}

.Text {
  grid-area: text;
}

.Date,
.Name,
.Text {
  border: 1px solid #f00;
  padding: 5px 10px;
}
<div class="Message">
  <div class="Name">name</div>
  <div class="Date">date (vertically centered)</div>
  <div class="Text">three<br />line<br />text</div>
</div>

Answer №1

To achieve a similar result, you need to utilize properties like width:max-content, justify-content:flex-end, margin, wrap, and min-width:

For example:

.Message {
  margin: 1em;
  width: max-content;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end
}

.Name {
  margin-left: 50%;
}

.Date {
  align-items: center;
  display: flex;
}

.Date,
.Name,
.Text {
  border: 1px solid #f00;
  padding: 5px 10px;
  min-width: 3em; /* adjust as needed */
}
<div class="Message">
  <div class="Name">name</div>
  <div class="Date">date (vertically centered)</div>
  <div class="Text">three<br />line<br />text</div>
</div>

Even though it may appear visually appealing, remember that grid and flex serve different purposes and in this case, using grid layout is recommended ;)

Answer №2

Unfortunately, achieving this specific layout with only flexbox is not possible unless you reorganize the .Date and .Text elements into another container.

.Message {
  display: flex;
  flex-flow: row wrap;
  justify-content: end
}

.Break {
  flex: 1 1 100%;
  display: flex;
}

.Date {
  flex: 1 1 fit-content;
}

.Date,
.Name,
.Text {
  border: 1px solid maroon;
  padding: 0.25rem 0.5rem;
}
<div class="Message">
  <div class="Name>name</div>
  <div class="Break">
    <div class="Date">date (vertically centered)</div>
    <div class="Text">three<br />line<br />text</div>
  </div>
</div>

However, while close, it's still not an exact match to your current layout. Therefore, utilizing grid would be necessary for that particular design.

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

Loads a PHP file automatically using the URL from a jQuery Ajax method

Using the jquery ajax method, I am trying to populate a dropdown menu with a set of option values from my title.php file. However, upon loading the page, in the Chrome Android browser, it redirects to the title.php. Does anyone have any insights into what ...

Adjust the width of the button to best fit the content or label

Here we have a screenshot of HTML source code showing a button that is wider than the content it contains. The highlighted area in yellow indicates there is extra space at the right side of the button due to it being displayed on multiple lines. Is this be ...

"Clicking on the 'View More' button within a foreach loop is only functional for the

I am trying to iterate through a list of items using a foreach loop, and each item has a "view more" option. The intention is that when I click on this option, it should expand to show more details about the respective item. However, I am encountering an i ...

Styling input groups with box shadows in Bootstrap 4

One issue I am encountering is the focus shadow that appears when the input text is focused. My goal is to have both the text input and the right button display a focus border. To illustrate this problem, I have created a JSfiddle: http://jsfiddle.net/a5u ...

The contents of a Javascript array are not appearing within a div element

I have developed a program that reads JSON data related to a concert event. The JSON file consists of an object named global, which includes details about the band name and venue. Additionally, there is a tickets object that contains information on all ava ...

Is it possible to include the contents of an .ics file and provide a link to it in HTML, all without relying on JavaScript?

The content of an .ics file is quite simple: BEGIN:VCALENDAR VERSION:2.0 PRODID:-//appsheet.com//appsheet 1.0//EN CALSCALE:GREGORIAN METHOD:PUBLISH BEGIN:VEVENT SUMMARY:Invitation from <<USEREMAIL()>> to talk about <<[MeetingTopic]>> ...

Can anyone provide guidance on how to simulate a click on a JavaScript action for an iPhone?

I am attempting to trigger a click on a "javascript:void(0)" link so that I can retrieve HTML data within the script. Can someone advise me on how to achieve this without using illegal APIs like UITouchEvent, as I only work with NSUrl? Thank you in advan ...

Utilize JavaScript and PHP to dynamically modify the contents of an HTML file

After not receiving a satisfactory answer to my question yesterday, I decided to find a solution. However, I am now facing an issue with the new program and unsure of the mistake. The program involves retrieving the contents of announcement.html and displ ...

Adding an existing element to the DOM using Javascript/jQuery

I am facing an issue in my DOM where I have an element with two children, a div block and a button. My goal is to add a new copy of the same div block to the parentNode whenever the button is clicked. Currently, I am using the following code in the button ...

Utilizing em units within CSS media queries is producing erratic outcomes on various browsers

My CSS media queries are set up in a progressive manner like the following: * { font-size: 14pt; } @media screen and (min-width:85em) { : : } @media screen and (min-width:110em) { : : } When I have two browsers open on the same screen, with identical siz ...

Navigating through website links while working locally on a localhost server can

After exclusively working on live domains or subdomains in the past, I recently experienced the benefits of working on localhost. Utilizing a Wamp server on my Windows machine, I store my project in C:/wamp64/www/[project_name]. I have always used relativ ...

Designing Progress Bars with CSS3

I'm currently working on enhancing the appearance of the progress bars across my website, all of which are built using jQuery UI. My goal is to achieve a design similar to the one shown below (featuring a stylish bevel effect and a visually appealing ...

The resizing of images is limited to when the browser is refreshed for responsive

Hey there, I'm currently facing an issue with a responsive image gallery using jQuery cycle. If you want to check out my fiddle, here's the link - https://jsfiddle.net/qxyodctm/5/ <html>See jsfiddle</html> The problem occurs when t ...

Can CSS be used to create curved dashed lines?

Is it possible to achieve dashed lines similar to the ones highlighted in the images below using only CSS? I have a responsive web page built with Bootstrap, and I need the dashed lines to adjust accordingly when the window width changes. ...

When submitting the form, a new browser tab opens displaying a blank PHP script

Currently revamping my website using a template and editing the content with notepad++. Struggling to display a success message on the contact me page after form submission. The issue arises when I submit information in the text boxes and click submit, it ...

Tips for moving a title sideways and adjusting the bottom section by x pixels

I am seeking to accomplish a design similar to this using CSS in order to create a title of <h1>DISCOVER <span>WEB 3</span> DIMENSIONS</h1>. How do you recommend achieving this? Thank you, I have searched on Google and asked frie ...

Implementing JavaScript Code in TypeScript

Every JavaScript code should also be valid in TypeScript, but when attempting to run the following code snippet below, an error is triggered. Could someone convert this JavaScript code into TypeScript? Error: 20:9 - TS2531 Error: Object is possibly 'z ...

Expanding CSS transition for child elements as they increase in size

I am currently working with Vuetify and have encountered an issue with a v-list-item that contains a title and a subtitle. The problem is that the title is restricted to displaying only one line. If the title exceeds this limit, it gets cut off and shows " ...

"How can I adjust the height of a Bootstrap column to match the height of its neighboring column

In my Bootstrap 4 layout, I have set up two columns... The left column contains three cards in columns The right column has a list group The content in the list group is longer than that of the cards on the left side. Is there a way to make the height ...

Button Menu in HTML

When you click the menu button, I want the text inside the class="greetings" div to change from "Welcome Jon deo" to just "G" So basically, whenever the menu button is clicked, display the letter G and hide or replace "Welcome Jon deo" Addition ...