webkit's flex-pack

There is a wealth of information on the web regarding CSS3 properties like box, flexbox, and flex. As far as I know, flex is the current method under development. Therefore, on Webkit browsers we would use properties like display: -webkit-flex, -webkit-flex: 1 auto...

However, my question is: how can I achieve something similar to box-pack: start using flex?

Please refer to this specific example (compatible with Webkit only). I am trying to align elements at the top, but they are spreading out. It should resemble something like this workaround example (although not ideal for my scenario due to maintenance issues). How can I resolve this issue?

NEED TO FIX

HTML

<div class="body">
    <h1>Test</h1>
    <div class="box" style="width: 80%"></div>
    <div class="box" style="width: 20%"></div>
    <div class="box" style="width: 20%"></div>
    <div class="box" style="width: 20%"></div>
    <!-- (NEED TO FIX) EMPTY SPACE -->
</div>

CSS

h1 {
    -webkit-flex: 1 100%;
}

.body {
    display: -webkit-flex;
    -webkit-flex-direction: row;
    -webkit-flex-wrap: wrap;
    height: 400px;
}

Note that the h1 should occupy all space in line 1, 2nd and 3rd .box elements will move to line 2, while the 4th and 5th .box elements will be on line 3. Additionally, I need the .body element (which is taller than its content) to have empty space at the bottom.

HACKISH SOLUTION :-(

HTML

<div class="body">
    <h1 style="height: 40px;">Test</h1>
    <div class="box" style="width: 80%; height: 20px;"></div>
    <div class="box" style="width: 20%; height: 20px;"></div>
    <div class="box" style="width: 20%; height: 20px;"></div>
    <div class="box" style="width: 20%; height: 20px;"></div>
    <div class="hackish"></div>
    <!-- NOTE THIS .hackish :-( -->
</div>

CSS

.hackish {
    width: 100%;
    height: 100%;
}

Are there any suggestions for a solution?

Answer №1

After putting it all together and providing examples, I finally stumbled upon the solution just 5 seconds later. Grrr...

The answer lies in using

-webkit-align-content: flex-start
on the .body element (W3 Flexbox - Align Content). Here is the revised code snippet:

.body {
    display: -webkit-flex;
    -webkit-flex-direction: row;
    -webkit-flex-wrap: wrap;
    height: 400px;

    -webkit-align-content: flex-start;
}

See this in action.

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

Position the angular material dialog at the center of the mat-drawer-content

My goal is to center the Angular material dialog component within the mat-drawer-content component instead of it taking up the full screen as it normally does. I currently have a mat-drawer that is always open on the left side, with the main content of th ...

Improving loading time for pages requiring jQuery to render

Currently, I am utilizing the Google PageSpeed service to enhance the loading time of my website. It is hosted on GAE/P, but that detail may not be crucial in this context. There are several resources my page relies on: Bootstrap (css and js) jQuery (js ...

When using Bootstrap with fullcalendar, the tooltips may not display properly

Currently, I am immersed in a confidential Codeigniter project where my goal is to showcase various events in the view utilizing fullcalendar. While progress has been made, I aspire to exhibit more than just the event's name and time; additional deta ...

Unable to Scroll HTML Division

At the moment, I am working on a new website. I have a div where I place images and overlay text on them to describe the images. The issue I am facing is that the text does not scroll even though the scroll bar is visible. This is my HTML: <!DOCTY ...

Adjust the dimensions of the HTML button to match that of its background

Typically, buttons are created with specific dimensions like this: <button style="width: 120px; height: 40px;"> Mememe <button> Afterwards, a background is added that matches the size of the button: button { background-size: 100% 100%; } ...

When I hover over one menu item, it interferes with my CSS transitions because the other menu items are hidden

I've been attempting to create a menu with very specific behavior: 1) Submenu transitions in when its corresponding menu item is hovered over 2) Submenu remains visible for a moment after moving the mouse away before transitioning out 3) If another me ...

Is it possible to link to a modal and execute a function simultaneously within the Bootstrap framework?

I have created an HTML form that looks like this: <form class="well span9 offset1" action="/summary/" method="post"> {% csrf_token %} <fieldset> <label class="control-label" for ="inputIcon">Type or paste your text in ...

Unable to see Primereact styles reflected on components

After some investigation, I've pinpointed the issue to be related to preflight from tailwind. Upon reviewing the documentation, I came across this helpful information: CSS Layer It seems that using Tailwind CSS with styled or unstyled modes of PrimeR ...

I'm having trouble centering the links in my navigation bar using flexbox, and I'm not sure how to fix it

Struggling with creating a navigation bar for my portfolio-building project. The "Who needs a quote" element is correctly displaying on the left, but I can't figure out how to center align the links "Sports, business, politics". Tried using flexbox op ...

"Creating a 2-column layout for an unordered list using CSS Flex

After spending far too much time at work today pondering this issue, I've decided to turn to the collective wisdom of the internet. My dilemma involves a standard <ul> containing multiple <li> elements (currently 12, but this number could ...

Tips for adjusting the padding percentage of a div with jquery

In my video player application, I have implemented a responsive window for playing videos. .player-window { position: relative; padding-bottom: 42%; height: 0; overflow: hidden; max-width: 100%; } My goal is to dynamically change the ...

Borders in my CSS/HTML table design

Hey, I'm currently facing an issue with my class project. I've created a table with a series of images to form a background image. However, there are borders on the table that I need to adjust. Here is the current look: I am trying to have a sq ...

Incorrect Configuration of Tailwind v3 in React and Webpack

Can anyone help me figure out why styles are not being applied when integrating Tailwind v3 into my React v17 / Webpack v5 app? I am not receiving any errors, so it's unclear what may be missing. Here is the relevant file structure: /client/index.js ...

What is the significance of mobile browsers rendering pages within a virtual "window"?

While browsing a specific webpage, I came across the following statement: Mobile browsers display web pages in a virtual "window" known as the viewport, which is typically wider than the actual screen size. This allows websites to maintain their layout ...

Transferring Text from Word to Expression using Copy and Paste

Whenever I try to copy and paste content from a Word document into Expressions Web, I encounter some strange behavior. Often, the top line gets placed in one <span> tag while the rest ends up in another <span> tag, causing a slight gap between ...

Replace the default MailChimp stylesheet with a different stylesheet

Objective: I want to modify the background color of the "Subscribe" button on a MailChimp embedded sign-up form found on our company's website page. Query: MailChimp provides the CSS hook "input.button" for styling the Subscribe button. How can I uti ...

Incapable of stacking one canvas on top of another

I'm new to javascript and looking for help with positioning a canvas element behind another. The code I have may be a bit messy, so any assistance is greatly appreciated. My goal is to have the canvas named "myCanvas" appear behind "coinAnimation". Th ...

Displaying PHP error location

Here is the PHP code snippet I am using: if($_SESSION['msg']['login-err']) { echo '<p class="error">'.$_SESSION['msg']['login-err'].'</p>'; ...

Begin the ul element from the left-hand side

Check out my latest JSFiddle creation: http://jsfiddle.net/alonshmiel/Ht6Ym/2409/ I'm attempting to align the ul element on the left side of the page: I've experimented with the following CSS rules: margin-left:0px; float: left; Unfortunatel ...

Step-by-step tutorial on designing an input slider to dynamically adjust the CSS :before linear-gradient values

Is there a way to achieve a gradient effect using pseudo-element :before on an image that can be customized by adjusting a slider input? I've been trying to implement this feature with the following code, but have not been successful so far. var ...