Flex Gridlayout with flex-direction row and different heights of row - html

I need a flex grid, where each grid cell has equal width, after every second cell it should wrap. But some cells should have full width. So far no problem.
But I want some of these cells have a fixed height.
In my example I want the blue background to be hidden and filled by the cells below the first one. Is this possible without adding more html tags?
The outcome should look like the second box, but without the additional html tag.
.flex-container {
background-color: blue;
-ms-box-orient: horizontal;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -moz-flex;
display: -webkit-flex;
display: flex;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-flex-direction: row;
flex-direction: row;
width: 300px;
height: 300px;
border: red 5px solid;
}
.flex-item {
background: tomato;
width: 50%;
color: white;
font-weight: bold;
font-size: 2em;
text-align: center;
border: green 1px solid;
box-sizing: border-box;
}
.flex-item:first-child {
width: 100%;
height: 50px;
}
.flex-container2 {
background-color: blue;
-ms-box-orient: horizontal;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -moz-flex;
display: -webkit-flex;
display: flex;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-flex-direction: row;
flex-direction: row;
width: 300px;
height: 300px;
border: red 5px solid;
}
.flex-item2 {
background: tomato;
width: 100%;
color: white;
font-weight: bold;
font-size: 2em;
text-align: center;
border: green 1px solid;
box-sizing: border-box;
height: 50px;
}
.additional-flex-container {
-ms-box-orient: horizontal;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -moz-flex;
display: -webkit-flex;
display: flex;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-flex-direction: row;
flex-direction: row;
width: 100%;
height: calc(100% - 50px);
flex-grow: 1;
}
.additional-flex-container .flex-item2 {
background: tomato;
width: 50%;
color: white;
font-weight: bold;
font-size: 2em;
text-align: center;
border: green 1px solid;
box-sizing: border-box;
height: auto;
}
<div class="flex-container">
<div class="flex-item">1</div>
<div class="flex-item">2</div>
<div class="flex-item">3</div>
<div class="flex-item">4</div>
<div class="flex-item">5</div>
</div>
<hr/>
<div class="flex-container2">
<div class="flex-item2">1</div>
<div class="additional-flex-container">
<div class="flex-item2">2</div>
<div class="flex-item2">3</div>
<div class="flex-item2">4</div>
<div class="flex-item2">5</div>
</div>
</div>

The only possibility I found was to calculate the height of all items. It is not as flexible as I want it, but I can play around at least with some additional classes.
.flex-container {
background-color: blue;
-ms-box-orient: horizontal;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -moz-flex;
display: -webkit-flex;
display: flex;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-flex-direction: row;
flex-direction: row;
width: 300px;
height: 300px;
border: red 5px solid;
}
.flex-item {
background: tomato;
width: 50%;
color: white;
font-weight: bold;
font-size: 2em;
text-align: center;
border: green 1px solid;
box-sizing: border-box;
height: calc((100% - 50px) / 2);
}
.flex-item:first-child {
width: 100%;
height: 50px;
}
<div class="flex-container">
<div class="flex-item">1</div>
<div class="flex-item">2</div>
<div class="flex-item">3</div>
<div class="flex-item">4</div>
<div class="flex-item">5</div>
</div>

Related

Why is this hover effect pushing the other elements that are next to it away?

I have divs that contain each individual arrow (one for the greater than text and another for the less than text). However, when I hover over the less than arrow, it pushes all the other elements to the right a bit. How can I have the hover effect not push any other elements away?
This is my HTML:
<div className="datepicker-wrapper">
<div className="dates">
<div className="arrows prev-month"><</div>
<div className="months">
<div className="start-month">February</div>
<div className="end-month">March</div>
</div>
<div className="days"></div>
<div className="arrows next-month">></div>
</div>
<div className="selected-dates">
<div className="check-in-date">02/13/2020</div>
</div>
</div>
And this is my CSS:
#import 'variables.css';
.datepicker-wrapper {
position: relative;
display: flex;
flex-direction: row;
justify-content: space-around;
align-items: flex-start;
width: 100%;
height: 50px;
background: transparent;
}
.datepicker-wrapper .dates {
display: flex;
flex-direction: row;
justify-content: space-around;
align-items: center;
width: 60%;
height: 100%;
}
.datepicker-wrapper .selected-dates {
display: flex;
flex-direction: column;
cursor: default;
width: 40%;
height: 100%;
}
.datepicker-wrapper .dates .arrows .previous-month {
}
.datepicker-wrapper .dates .arrows:hover {
width: 15px;
height: 15px;
background: var(--light-gray);
border-radius: 50%;
cursor: pointer;
}
.datepicker-wrapper .dates .months {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
NOTE
I've tried giving the arrows prev-month div a set width, but that doesn't seem to have any effect.
You give the width and height only on hover.. try to give the styles to the arrows anyway, and on hover only change the background-color
.datepicker-wrapper {
position: relative;
display: flex;
flex-direction: row;
justify-content: space-around;
align-items: flex-start;
width: 100%;
height: 50px;
background: transparent;
}
.datepicker-wrapper .dates {
display: flex;
flex-direction: row;
justify-content: space-around;
align-items: center;
width: 60%;
height: 100%;
}
.datepicker-wrapper .selected-dates {
display: flex;
flex-direction: column;
cursor: default;
width: 40%;
height: 100%;
}
.datepicker-wrapper .dates .arrows {
width: 15px;
height: 15px;
border-radius: 50%;
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
}
.datepicker-wrapper .dates .arrows:hover {
background: #c1c1c1;
}
.datepicker-wrapper .dates .months {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
<div class="datepicker-wrapper">
<div class="dates">
<div class="arrows prev-month"><</div>
<div class="months">
<div class="start-month">February</div>
<div class="end-month">March</div>
</div>
<div class="days"></div>
<div class="arrows next-month">></div>
</div>
<div class="selected-dates">
<div class="check-in-date">02/13/2020</div>
</div>
</div>
Setting the styles on :hover impacts the CSS box model for the .arrows element:
All four of those impact the overall space an element takes.

CSS transform scale with flex-direction column

I'm trying to use CSS transform: scale(1.5); within a flex container. I need the hidden content to be displayed above and centered to the original text, so to do this I am using flex-direction: column; which works.
The issue is when the transform executes, the sibling html element grows too. (You can see the behavior within the code snippet)
I'm sure I'm missing something simple but I've tried several solutions can't figure out why this is happening. Any help is greatly appreciated.
$(document).ready(function() {
$('[data-action="clickable"]').mousedown(function(item) {
$(item.currentTarget).addClass('flex-item-blowout');
$(item.currentTarget).find('.hidden').addClass('displayed');
$(item.currentTarget).find('.hidden').removeClass('hidden');
});
$('[data-action="clickable"]').mouseup(function(item) {
$(item.currentTarget).removeClass('flex-item-blowout');
$(item.currentTarget).find('.displayed').addClass('hidden');
$(item.currentTarget).find('.displayed').removeClass('displayed');
});
$('[data-action="clickable"]').mouseleave(function(item) {
$(item.currentTarget).removeClass('flex-item-blowout');
$(item.currentTarget).find('.displayed').addClass('hidden');
$(item.currentTarget).find('.displayed').removeClass('displayed');
});
});
.flex-container {
padding: 0;
margin: 0;
list-style: none;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-flow: row;
line-height: 30px;
}
.flex-item {
background: burlywood;
color: white;
margin: 3px;
font-weight: bold;
font-size: 1.5em;
min-width: 20%;
max-width: 20%;
display: flex;
justify-content: center;
flex-direction: column;
text-align: center;
min-height: 50px;
user-select: none;
}
.flex-item-blowout {
transform: scale(1.5);
background-color: coral;
}
.hidden {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="flex-container">
<div class="flex-item" data-action="clickable">
<span class="hidden">2</span><span>1 + 1</span>
</div>
<div class="flex-item" data-action="clickable">
<span class="hidden">3</span><span>1 + 2</span>
</div>
</div>
Just add align-items: flex-start to the .flex-container, which will prevent the default behavior of the value stretch.
$(document).ready(function() {
$('[data-action="clickable"]').mousedown(function(item) {
$(item.currentTarget).addClass('flex-item-blowout');
$(item.currentTarget).find('.hidden').addClass('displayed');
$(item.currentTarget).find('.hidden').removeClass('hidden');
});
$('[data-action="clickable"]').mouseup(function(item) {
$(item.currentTarget).removeClass('flex-item-blowout');
$(item.currentTarget).find('.displayed').addClass('hidden');
$(item.currentTarget).find('.displayed').removeClass('displayed');
});
$('[data-action="clickable"]').mouseleave(function(item) {
$(item.currentTarget).removeClass('flex-item-blowout');
$(item.currentTarget).find('.displayed').addClass('hidden');
$(item.currentTarget).find('.displayed').removeClass('displayed');
});
});
.flex-container {
padding: 0;
margin: 0;
list-style: none;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-flow: row;
line-height: 30px;
align-items: flex-start;
}
.flex-item {
background: burlywood;
color: white;
margin: 3px;
font-weight: bold;
font-size: 1.5em;
min-width: 20%;
max-width: 20%;
display: flex;
justify-content: center;
flex-direction: column;
text-align: center;
min-height: 50px;
user-select: none;
}
.flex-item-blowout {
transform: scale(1.5);
background-color: coral;
}
.hidden {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="flex-container">
<div class="flex-item" data-action="clickable">
<span class="hidden">2</span><span>1 + 1</span>
</div>
<div class="flex-item" data-action="clickable">
<span class="hidden">3</span><span>1 + 2</span>
</div>
</div>

flex properties not working on safari

I am using flex for making a searchbar/input element stay centered and change width as the screen size changes.
This is my html:
<div class="flex-container">
<div class="flex-row">
<h1 class="brandname">Hello</h1>
</div>
<div class="flex-row">
<form>
<!-- <div class="search centered"> -->
<div class="search">
<div class="input-container">
<input type="text" name="query" class="searchbar" />
<button type="submit" class="search-button">Search</button>
</div>
</div>
</form>
</div>
</div>
and this is my css:
#import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');
.flex-container{
display: flex;
display: -webkit-flex;
align-items: center;
-webkit-align-items: center;
justify-content: center;
-webkit-justify-content: center;
-webkit-flex-direction: row;
flex-direction: row;
flex-wrap: wrap;
-webkit-flex-wrap: wrap;
}
.flex-row {
display: flex;
display: -webkit-flex;
justify-content: center;
-webkit-justify-content: center;
flex: 1;
-webkit-flex: 1;
}
form{
display: flex;
display: -webkit-flex;
justify-content: center;
-webkit-justify-content: center;
flex: 1;
-webkit-flex: 1;
}
.search{
display: flex;
display: -webkit-flex;
flex: 0 1 455px;
-webkit-flex: 0 1 455px;
}
.input-container{
display: flex;
display: -webkit-flex;
flex: 1;
-webkit-flex: 1;
min-width: 0;
}
.searchbar{
flex: 1;
-webkit-flex: 1;
min-width: 0;
}
.flex-container > .flex-row:first-child{
flex: 0 1 100%;
-webkit-flex: 0 1 100%;
}
.brandname {
position: relative;
font-size: 500%;
font-family: 'Lato', sans-serif;
color: #1f0e3e;
text-align: center;
margin-bottom: 30px;
margin-top: 5%;
}
body {
margin: 10px;
}
.input-container{
/*float: left;*/
/*display: block;*/
flex: 1;
-webkit-flex: 1;
outline-style: solid;
outline-color: #e3e3e3;
outline-width: 1px;
}
.searchbar{
margin-left: 5px;
}
.search button {
background-color: rgba(152,111,165,0.38);
background-repeat:no-repeat;
border: none;
cursor:pointer;
border-radius: 0px;
/*overflow: hidden;*/
outline-width: 1px;
outline-style: solid;
outline-color: #e3e3e3;
color: white;
}
.search input{
outline-width: 0px;
outline-style: none;
border-width: 0px;
}
and it works in chrome, ie edge and in this fiddle, but not in safari.
In Safari the searchbar goes above the .brandname element and to the right of it and takes a width of 150px.
any ideas on how to make this work in safari?
One thing that is not working is the the first flex row width of 100% is not working. In safari it is making the two felx-row elements be right next to each other and both of them together are taking 100% of the width.
I changed .flex-row css rules to:
.flex-row {
display: flex;
display: -webkit-flex;
justify-content: center;
-webkit-justify-content: center;
flex: 1;
-webkit-flex: 0 1 100%;
}
and changed the flex-row first child css rules to:
.flex-container > .flex-row:first-child{
flex: 0 1 100%;
-webkit-flex: 0 1 auto;
}
and then it works.
I thought about doing this after reading that flex-wrap is buggy in safari from this SO question which suggests that setting flex-wrap in safari is buggy
Always use the non-prefixed setting last in your CSS rules. In your first rule that would be:
.flex-container{
display: -webkit-flex;
display: flex;
-webkit-align-items: center;
align-items: center;
-webkit-justify-content: center;
justify-content: center;
-webkit-flex-direction: row;
flex-direction: row;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
}
similar for all other rules.

How to break words with IE 11 running on WP 8.1?

I'm struggling to get word-wrap: break-word; to work on Nokia Lumia 930 (and probably other Windows phones). Any ideas? The text just floats over to the next tab.
It seems to be working ok in iOS and Android.
body {
background: lightblue;
}
.container {
width: 320px;
margin: 20px auto;
border: 1px solid #ebebeb;
background: white;
}
.tabs {
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
.tab {
width: 25%;
-webkit-flex: 1 1 auto;
-ms-flex: 1 1 auto;
flex: 1 1 auto;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
border-right: 1px solid #ebebeb;
}
.tab:last-child {
border-right: none;
}
.label {
display: block;
margin: auto 0;
text-align: center;
word-wrap: break-word;
}
<div class="container">
<div class="tabs">
<div class="tab">
<span class="label">xxxxxx xxx xxxxxxxxxx</span>
</div>
<div class="tab">
<span class="label">xxxxxx xx xxxxx</span>
</div>
<div class="tab">
<span class="label">xxxx xxxxxx</span>
</div>
<div class="tab">
<span class="label">xxxxxx xx</span>
</div>
</div>
</div>
Adding align-self: stretch to .label solves it.
.label{
align-self: stretch
}

Creating divs displaying inside each other and inline using CSS

I have started on this fiddle using CSS:
.cont {
border:1px solid #F36F25;
}
.ticketnumber {
display:inline-block;
}
.status {
display:inline-block;
}
.summary {
display:inline-block;
float:left;
}
.last_updated {
display:inline-block;
float:right;
}
.box {
}
http://jsfiddle.net/3qbn222u/
i want to create something that looks like this image:
how can i achieve this in the easiest way?
//HTML BLOCK
<div class="cont">
<div class="header_box">
<div class="ticket_box">
<div class="ticketnumber">ID#0000001234</div>
<div class="summary">Subject: Grumpy Cat</div>
<div class="summary">Summary: blaahh</div>
</div>
<div class="summary_box">
<div class="last_updated">10 minutes ago</div>
<div class="status"></div>
</div>
</div>
<div class="wrapper_box">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
</div>
//CSS BLOCK
.cont {
display: flex;
display: -webkit-flex;
height: 200px;
border-radius: 5px;
flex-direction: column;
-webkit-flex-direction: column;
border: 1px solid #dddddd;
box-shadow: 0 1px 5px rgba(0,0,0,.6);
-webkit-box-shadow: 0 1px 5px rgba(0,0,0,.6);
}
.header_box{
display: flex;
display: -webkit-flex;
flex: 1;
-webkit-flex: 1;
font-size: 12px;
}
.wrapper_box{
display: flex;
display: -webkit-flex;
flex: 2;
-webkit-flex: 2;
}
.ticket_box{
display: flex;
display: -webkit-flex;
flex: 6;
-webkit-flex: 6;
flex-direction: column;
-webkit-flex-direction: column;
justify-content: center;
-webkit-justify-content: center;
align-items: flex-start;
-webkit-align-items: flex-start;
margin: 10px 10px;
}
.summary_box{
display: flex;
display: -webkit-flex;
flex: 4;
-webkit-flex: 4;
flex-direction: column;
-webkit-flex-direction: column;
justify-content: center;
-webkit-justify-content: center;
align-items: flex-end;
-webkit-align-items: flex-end;
margin: 10px 10px;
}
.ticketnumber {
display: flex;
display: -webkit-flex;
}
.summary {
display: flex;
display: -webkit-flex;
}
.last_updated {
display: flex;
display: -webkit-flex;
}
.status {
display: flex;
display: -webkit-flex;
height: 15px;
width: 15px;
margin: 10px 0px;
border-radius: 50%;
background: red;
}
.box {
display: flex;
display: -webkit-flex;
flex: 1;
-webkit-flex: 1;
justify-content: center;
-webkit-justify-content: center;
align-items: center;
-webkit-align-items: center;
border: 10px solid #f3f3f3;
margin: 5px 5px;
background: #ccc;
background: url(http://www.freeallimages.com/wp-content/uploads/2014/09/grumpy-cat-no-1.jpg) no-repeat;
background-size: cover;
-webkit-background-size: cover;
background-position: center;
-webkit-background-position: center;
color: #fff;
}
Agreed using FlexBox would be the easiest way.
Here is a good reference guide to FlexBox:
https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Flexible_boxes