Expanding Width and Height Using CSS3 Flexbox

Looking to create a fullscreen calendar app using the CSS3 Flex model. While I've managed to fit the calendar nicely horizontally, I'm struggling to find a way for the weeks to stretch equally in height too.

Check out this jsFiddle for a visual representation of my issue: http://jsfiddle.net/CgXLa/

The weeks are evenly distributed until I switch them to display: flex;. Even when enclosing all days within a div and setting that to display: flex;, the problem persists.

Is there a way to utilize the Flex model to expand the calendar both horizontally and vertically?

Answer №1

Below is the solution I came up with.

The unnecessary wrapper around weeks has been removed. Now both the weeks and the th elements are direct children of the calendar.

<main id="calendar">
    <section class="th">
        <span>Sunday</span>
        <span>Monday</span>
        <span>Tuesday</span>
        <span>Wednesday</span>
        <span>Thursday</span>
        <span>Friday</span>
        <span>Saturday</span>
    </section>
    <div class="week">
        <div></div>
        <div></div>
        <div></div>
        <div data-date="1"></div>
        <div data-date="2"></div>
        <div data-date="3"></div>
        <div data-date="4"></div>
    </div>
    ....

Here is the updated CSS:

/* Calendar 100% height */
#calendar { 
    height: 100%; 
    display: flex;
    flex-flow: column nowrap;
    align-items: stretch;
}

.th {
    flex: 30px 0 0;
} 
.week {
    flex: 30px 1 0;
    border-bottom: 1px solid #ccc;    
}

The key point here is to assign a fixed height (flex-basis: 30px) to the th element without allowing it to grow, and then give some initial height to the week element while allowing it to expand (flex-grow: 1).

This setup ensures that the weeks occupy all remaining space within the calendar after accommodating the th element, distributing the space equally between them.

Check out the updated fiddle here

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

Minimum and Maximum Price Input Field

Hello everyone, I'm currently facing an issue with a code that is supposed to filter with minimum and maximum price values, but it's not working as expected. Below is the HTML form snippet: <form> <select class="custom-select my ...

Are there various types of HTML5 document declarations available?

Back in the days when I used to create web pages in XHTML, there were three types of doctype available - strict, transitional, and frameset. Are these different types of doctypes still present in HTML5? ...

Demonstrating the transformation of child elements into parent elements through angular 6 ngFor

I have a JSON array dataset where each object may contain nested arrays. In order to display the inner nested array elements as part of the parent array using Angular's NgFor, I need to format the input like this: [{ 'id': 1, 'tit ...

Circular gradient backdrop

Looking to create a sleek and professional body background for my website that is as attractive as Twitter's. Can you help me achieve the same blue shaded background effect? I'm new to web development and would appreciate any guidance on how to m ...

Retrieve the content of a different page and store it as a variable using ajax

Is it possible to assign the content of another HTML page to a JavaScript variable? I attempted: var X = $(http://www.website.com/home).html() Unfortunately, this did not work, even though it seemed like a good idea. Can anyone provide guidance on how t ...

Is it possible for jQuery UI Dialog to function similar to an iFrame?

Is there a way to set up my dialog box with a form so that when the form is submitted, only the dialog box changes instead of the browser location? ...

Avoiding interference with adjacent elements caused by long content in a div

Hey there, I could really use some help with my CSS layout, I'm pretty new to CSS and Flexbox and I'm trying to create a simple layout. The issue I'm running into is how to stop long content inside a pre tag from pushing other divs. Here& ...

"Unable to get the overflow-x: auto property to function properly

Below is the CSS and HTML code that I am working with: #container { display: table; margin: 0 auto; } .table-container { width: 100%; overflow-x: auto; _overflow: auto; } <div id='container'> <div class='table-contain ...

Creating files for two HTML pages with Vue: A step-by-step guide

Currently, I am working on creating two HTML files as part of my project structure. This is how it looks: |- node_modules |- public | |- blog | | |- some-page.html | |- index.html |- src (contains all the Vue components) |- Blog.Vue |- Index.Vue ...

Customizing SharePoint Web Part Styles with CSS: Header Alignment Issue with Body_TEXT

I am currently working on branding a SharePoint website and have encountered an issue with aligning background colors for the title area and body of some web parts. Despite applying background colors, the alignment between the title and body areas is off ( ...

Ways to eliminate additional container padding within flexbox

I'm struggling with understanding flexbox and couldn't find any clear explanation on the W3 page about how to remove the extra spacing between containers. For example, in one of their demos, I'm unsure how to achieve a layout similar to lef ...

AngularJS: The dynamic setting for the stylesheet link tag initiates the request prematurely

I'm encountering a problem that is somewhat similar (although not exactly the same, so please be patient) to the one discussed in Conditionally-rendering css in html head I am dynamically loading a stylesheet using a scope variable defined at the sta ...

Flip elements in jQuery that are overlapping other elements following them

Utilizing the jQuery flip plugin to create image flip animations within an ejs file in a Node environment. The issue arises where any element positioned below the flip element ends up overlapping with it, causing visual discrepancies. Here is a simple co ...

The specified SVG marker identifier could not be located

https://i.stack.imgur.com/xQhWg.png I am managing a web block list that consists of different divs, each containing specific code that is displayed based on the sent ID. Below are the codes for each div: Div1 <svg width='200' height=&apos ...

The form will not pass validation

The validation of my form is not working correctly, as all my functions are called when the submit button is clicked. // Main Function function validate_form(form) { var complete = false; // Ensure that only one error message is displayed at a ti ...

Modify the CSS class by utilizing ngClass

Is it achievable to modify only one out of multiple classes assigned to an element without affecting the others? Illustration: <span ng-class="{'result warning' : error, 'result passing' : !error}"></span> In this code sn ...

Having difficulty aligning divs in the center

My nested div is causing alignment issues and I can't seem to solve it. Despite trying various solutions like margin: 0 auto and setting a specific width, the centering problem persists. Can someone please help me identify the issue and provide a fix ...

Using Html to differentiate input based on type

Looking for input on the code snippet below: <table class="details-table" *ngIf="animal && animaldata"> <tr *ngFor="let attribute of animaldata.Attributes"> <td class="details-property">{{ attribute.AttributeLabel }}& ...

What is the best way to ensure that my drop down select menu consistently displays the same data even after performing a query with the menu?

Hey there! I'm facing a little hiccup with a drop-down selection box. Here's what I'm trying to do - get someone to log into a database, and then display all available tables in the selection box. Once they choose a table, they hit select an ...

displaying and activating element using jQuery

I'm currently working on setting up a notification system for my website but seem to be encountering some issues that I can't quite pinpoint. Essentially, I have a link that triggers a JavaScript function upon being clicked. This function is mean ...