css, how to combine shape-outside and flex-wrap? - html

I'm trying to combine flex-wrap and shape-outside to get something like this :
What i want to do is : the blue zone to flex-wrap it's content, and to be on the right and bottom of the grey zone :
adding display: flex; break the shape-outside
Any tips ? thanks
A JSfiddle :
https://jsfiddle.net/81b3cLxf/
HTML
<div class="main">
<div class="left"></div>
<div class="flex-container wrap">
<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 class="flex-item">6</div>
<div class="flex-item">7</div>
<div class="flex-item">8</div>
</div>
</div>
CSS
.main {
width: 600px;
height: 500px;
box-sizing: border-box;
overflow: hidden;
background-color: black;
padding: 10px;
}
.left {
width: 50%;
height: 200px;
background-color: lightgray;
shape-outside:"none";
float: left;
}
.flex-container {
height: 100%;
background-color: blue;
-ms-box-orient: horizontal;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -moz-flex;
display: -webkit-flex;
display: flex;
}
.wrap {
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
}
.flex-item {
background: tomato;
padding: 5px;
width: 75px;
height: 75px;
margin: 10px;
line-height: 75px;
color: white;
font-weight: bold;
font-size: 2em;
text-align: center;
}

Please check my example with grid:
.main {
width: 600px;
height: 500px;
box-sizing: border-box;
overflow: hidden;
background-color: black;
padding: 10px;
}
.left {
grid-column: span 3;
grid-row: span 2;
background-color: lightgray;
}
.flex-container {
height: 100%;
background-color: blue;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(75px, 1fr));
grid-gap: 10px;
grid-auto-rows: 85px;
}
.flex-item {
background: tomato;
padding: 5px;
width: 75px;
height: 75px;
margin: 0;
color: white;
font-weight: bold;
font-size: 2em;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
}
<div class="main">
<div class="flex-container wrap">
<div class="left"></div>
<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 class="flex-item">6</div>
<div class="flex-item">7</div>
<div class="flex-item">8</div>
<div class="flex-item">9</div>
<div class="flex-item">10</div>
</div>
</div>

Related

Why does the divs starts from between in case of overflow hidden?

Styles
body{
margin:unset;
}
.carousel{
height: 200px;
width: 100%;
padding: 10px;
box-sizing: border-box;
display: grid;
grid-template-columns: 50px 1fr 50px;
grid-gap: 10px;
}
.carousel-controls{
color: navy;
}
.carousel > div{
display: grid;
align-items: center;
justify-content: center;
}
.carousel-holder{
background: purple;
display: grid;
grid-gap: 10px;
grid-auto-flow: column;
overflow: hidden;
padding: 10px;
box-sizing: border-box;
}
.carousel-cards{
background: white;
height: 100%;
width: 125px;
display: grid;
place-items:center;
font-weight: bolder;
color: navy;
}
Markup with bit of php for card generation
<div class="carousel">
<div class="carousel-controls carousel-controls-prev ">
<i class="fas fa-arrow-left"></i>
</div>
<div class="carousel-holder">
<?php
$x = 1;
while ($x <= 250) {
echo "<div class='carousel-cards'>".$x."</div>";
$x++;
}
?>
</div>
<div class="carousel-controls carousel-controls-next ">
<i class="fas fa-arrow-right"></i>
</div>
</div>
The result
Problem
I am making a carousel to which Ill add javascript later. Now my problem is that the generated cards which should start from 1 are actually starting from 120 when I am using overflow hidden.
In regards to your content centering, in your css, it should be justify-content:start and not justify-content:center.
So, it should look like this:
.carousel > div{
display: grid;
align-items: center;
justify-content: start;
}
You can change your alignment to left if you want it to start at 1 rather than the center using:
.carousel-cards{
justify-content: left;
}
See it in action below:
body{
margin:unset;
}
.carousel{
height: 200px;
width: 100%;
padding: 10px;
box-sizing: border-box;
display: grid;
grid-template-columns: 50px 1fr 50px;
grid-gap: 10px;
}
.carousel-controls{
color: navy;
}
.carousel > div{
display: grid;
align-items: center;
justify-content: left;
}
.carousel-holder{
background: purple;
display: grid;
grid-gap: 10px;
grid-auto-flow: column;
overflow: hidden;
padding: 10px;
box-sizing: border-box;
}
.carousel-cards{
background: white;
height: 100%;
width: 125px;
display: grid;
place-items:center;
font-weight: bolder;
color: navy;
}
<div class="carousel">
<div class="carousel-controls carousel-controls-prev ">
<i class="fas fa-arrow-left"></i>
</div>
<div class="carousel-holder">
<div class='carousel-cards'>1</div>
<div class='carousel-cards'>2</div>
<div class='carousel-cards'>3</div>
<div class='carousel-cards'>4</div>
<div class='carousel-cards'>5</div>
<div class='carousel-cards'>6</div>
<div class='carousel-cards'>7</div>
<div class='carousel-cards'>8</div>
<div class='carousel-cards'>9</div>
<div class='carousel-cards'>10</div>
<div class='carousel-cards'>11</div>
<div class='carousel-cards'>12</div>
<div class='carousel-cards'>13</div>
<div class='carousel-cards'>14</div>
<div class='carousel-cards'>15</div>
<div class='carousel-cards'>16</div>
<div class='carousel-cards'>17</div>
<div class='carousel-cards'>18</div>
<div class='carousel-cards'>19</div>
<div class='carousel-cards'>20</div>
<div class='carousel-cards'>21</div>
<div class='carousel-cards'>22</div>
<div class='carousel-cards'>23</div>
<div class='carousel-cards'>24</div>
<div class='carousel-cards'>25</div>
</div>
<div class="carousel-controls carousel-controls-next ">
<i class="fas fa-arrow-right"></i>
</div>
</div>

Make the parent div width the same as the children

I made this layout that seems to work, the only problem is that I would like that all che filled div are centered.
There are three possible "states":
the cyan element is to the left of all the others
the gold and pink elements are on two columns
all elements are on a single column.
What I want:
In the first case, everything is centered and it works, in the other two it doesn't: the elements are always aligned to the left.
To center I was thinking of using margin: 0 auto but it seems the divs are bigger than their content even if I used inline-flex (look at the grey area during state #3 in the running example). Why?
How can I solve?
.container {
outline: 1px solid black;
max-width: 490px;
margin: 0 auto;
}
.columns {
outline: 1px solid black;
display: inline-flex;
flex-wrap: wrap;
}
.map {
background-color: cyan;
width: 150px;
min-width: 150px;
height: 150px;
min-height: 150px;
margin-right: 20px;
}
.content {
outline: 1px solid black;
background-color: lightgray;
max-width: 320px;
}
.cards {
outline: 1px solid black;
display: inline-flex;
flex-wrap: wrap;
}
.card {
background-color: pink;
outline: 1px solid black;
width: 150px;
height: 70px;
display: inline-block;
}
.card.left {
margin-right: 20px;
}
.texts {
outline: 1px solid black;
display: inline-flex;
flex-wrap: wrap;
}
.text {
background-color: gold;
outline: 1px solid black;
width: 150px;
height: 200px;
display: inline-block;
}
.text.left {
margin-right: 20px;
}
<div class="container">
<div class="columns">
<div class="map"></div>
<div class="content">
<div class="cards">
<div class="card left">card #1</div>
<div class="card">card #2</div>
<div class="card left">card #3</div>
<div class="card">card #4</div>
</div>
<div class="texts">
<div class="text left">text #1</div>
<div class="text">text #2</div>
</div>
</div>
</div>
</div>
use media queries in the proper way and here you go, to play with it find this fiddle link, try to resize the result window.
.container {
max-width: 490px;
margin: 0 auto;
}
.columns {
display: inline-flex;
flex-wrap: wrap;
}
.map {
background-color: cyan;
width: 150px;
min-width: 150px;
height: 150px;
min-height: 150px;
margin-right: 20px;
}
.content {
background-color: lightgray;
max-width: 320px;
}
.cards {
display: inline-flex;
flex-wrap: wrap;
}
.card {
background-color: pink;
width: 150px;
height: 70px;
display: inline-block;
}
.card.left {
margin-right: 20px;
}
.texts {
display: inline-flex;
flex-wrap: wrap;
}
.text {
background-color: gold;
width: 150px;
height: 200px;
display: inline-block;
}
.text.left {
margin-right: 20px;
}
#media(max-width: 520px){
.container {
display: flex;
flex-direction: column;
align-items: center;
}
.columns {
display: inline-block;
}
}
#media(max-width: 352px){
.container {
display: flex;
flex-direction: column;
align-items: center;
}
.map {margin-right: 0;}
.content {
max-width: min-content;
}
.card.left {
margin-right: 0px;
}
.text.left {
margin-right: 0px;
}
}
<div class="container">
<div class="columns">
<div class="map"></div>
<div class="content">
<div class="cards">
<div class="card left">card #1</div>
<div class="card">card #2</div>
<div class="card left">card #3</div>
<div class="card">card #4</div>
</div>
<div class="texts">
<div class="text left">text #1</div>
<div class="text">text #2</div>
</div>
</div>
</div>
</div>

justify-content: center not working on flex:100% in mobile

I'm trying to build a 3 by 3 flexbox grid of button links that are responsive. The grid looks great on desktop and tablet, however, in the mobile version the items are left aligned and are unable to be horizontally centered. My goal is to get one column for the mobile with all the content centered. I switched to flex: 100%; for the mobile version and tried using justify-content: center, but it doesn't work and I'm not sure why.
#love_button,
#additude_button,
#isnpr_button,
#functional_medicine_button,
#immh_button {
width: 178px;
height: 111px;
display: block;
background-repeat: no-repeat;
}
.flex-container {
height: 100%;
padding: 0;
margin: 0;
list-style: none;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
border: 4px solid orange;
}
.flex-item {
width: 178px;
height: 111px;
flex: 33.3% 33.3% 33.3%;
margin-bottom: 65px;
background: royalblue;
}
Mobile Media Query #media only screen and (max-device-width: 640px) {
/* Fixes bottom gap between resource link and footer mobile */
.push {
margin-bottom: 0;
}
.flex-container {
justify-content: center;
}
.flex-item {
flex: 100%;
}
#hide {
display: none;
}
}
<main>
<section id="resources">
<h1 class="resources_header">RESOURCES</h1>
<div class="flex-container">
</div>
<div class="flex-container push">
</div>
</section>
</main>
Instead try changing display:block and margin:10px auto in the media query.
Please check my snippet, and let me know if you have any questions.
#love_button,
#additude_button,
#isnpr_button,
#functional_medicine_button,
#immh_button {
width: 178px;
height: 111px;
display: block;
background-repeat: no-repeat;
}
.flex-container {
height: 100%;
padding: 0;
margin: 0;
list-style: none;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
justify-content: space-evenly;
}
.flex-item {
width: 178px;
height: 111px;
flex: 33.3% 33.3% 33.3%;
margin-bottom: 65px;
border: 1px solid red;
background: green;
}
#media only screen and (max-width: 640px) {
/* Fixes bottom gap between resource link and footer mobile */
.push {
margin-bottom: 0;
}
.flex-container {
display: block;
margin: auto;
}
.flex-item {
margin: 10px auto;
}
#hide {
display: none;
}
}
<main>
<section id="resources">
<h1 class="resources_header">RESOURCES</h1>
<div class="flex-container">
</div>
<div class="flex-container push">
</div>
</section>
</main>
Use align-items: center or align-content: space-evenly or both.
Without align-items or align-content
.flex-container {
width: 150px;
height: 150px;
border: 1px solid black;
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
align-content: space-evenly;
}
.flex-children {
width: 40px;
height: 40px;
background-color: red;
}
<div class="flex-container">
<div class="flex-children"></div>
<div class="flex-children"></div>
<div class="flex-children"></div>
<div class="flex-children"></div>
<div class="flex-children"></div>
<div class="flex-children"></div>
<div class="flex-children"></div>
<div class="flex-children"></div>
<div class="flex-children"></div>
</div>
With align-items or align-content
.flex-container {
width: 150px;
height: 150px;
border: 1px solid black;
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
align-items: center;
}
.flex-children {
width: 40px;
height: 40px;
background-color: red;
}
<div class="flex-container">
<div class="flex-children"></div>
<div class="flex-children"></div>
<div class="flex-children"></div>
<div class="flex-children"></div>
<div class="flex-children"></div>
<div class="flex-children"></div>
<div class="flex-children"></div>
<div class="flex-children"></div>
<div class="flex-children"></div>
</div>
CSS-tricks: align-items
CSS-tricks: align-content

Flexbox parent fit text content of children

I want to use flexbox to make a column that can scroll as its text content gets longer.
I drew a picture in keynote to make a better explanation.
when texts are small
when texts get big
Here is my current code, just every elements in my code is in flexboxes.
I edited my script to include .app .sidebar
.app {
display: flex;
height: 100vh;
flex-direction: row;
}
.sidebar {
display:flex;
flex: 1;
}
.cv {
display: flex;
flex:5;
flex-direction: column;
margin:20px;
border: 1px solid lightgrey;
border-radius: 10px;
background-color: white;
overflow: scroll;
}
.header {
display: flex;
flex: 0 0 150px;
justify-content: center;
align-items: center;
font-size: 20px;
}
.section {
display: flex;
flex-direction: column;
border: 1px solid lightgrey;
margin: 10px;
border-radius: 10px;
}
.sectionHeader{
display: flex;
align-items: center;
font-size: 18px;
padding-left: 20px;
padding-top: 15px;
padding-bottom: 5px;
flex: 0 0 30px;
background-color: gray;
color:white;
font-weight: 700;
}
.sectionBody{
display: flex;
flex: 1;
padding: 20px;
}
<div class="app">
<div class="sidebar"></div>
<div class="cv">
<div class="header">Header</div>
<div class="section">
<div class="sectionHeader">Section Header</div>
<div class="sectionBody">LONG TEXT</div>
</div>
<div class="section">
<div class="sectionHeader">Section Header</div>
<div class="sectionBody">LONG TEXT</div>
</div>
</div>
</div>
You need to do 2 things:
Give the cv a min-height: 0; (fix for i.a. Firefox)
Add flex-shrink: 0 to the .section so it won't collapse when not fit
Stack snippet
body {
margin: 0;
}
.app {
display: flex;
height: 100vh;
}
.sidebar {
display: flex;
flex: 1;
background: red;
}
.cv {
display: flex;
flex: 5;
flex-direction: column;
margin: 20px;
border: 1px solid lightgrey;
border-radius: 10px;
background-color: white;
overflow: scroll;
min-height: 0; /* added */
}
.header {
display: flex;
flex: 0 0 150px;
justify-content: center;
align-items: center;
font-size: 20px;
}
.section {
display: flex;
flex-direction: column;
border: 1px solid lightgrey;
margin: 10px;
border-radius: 10px;
flex-shrink: 0; /* added */
}
.sectionHeader {
display: flex;
align-items: center;
font-size: 18px;
padding-left: 20px;
padding-top: 15px;
padding-bottom: 5px;
flex: 0 0 30px;
background-color: gray;
color: white;
font-weight: 700;
}
.sectionBody {
display: flex;
flex: 1;
padding: 20px;
}
<div class="app">
<div class="sidebar">sidebar</div>
<div class="cv">
<div class="header">Header</div>
<div class="section">
<div class="sectionHeader">Section Header</div>
<div class="sectionBody">LONG TEXT</div>
</div>
<div class="section">
<div class="sectionHeader">Section Header</div>
<div class="sectionBody">LONG TEXT</div>
</div>
</div>
</div>

How can i create a Tile System like this?

So i am creating a Responsiv Website in which i want to have a Tile System like in the Image above. Unfortunatly i just cant get it done right.Here is my current ATTEMPT. Using Flexbox
.flex-container {
padding: 0;
margin: 0;
list-style: none;
width: 100%;
height: 30px;
display: -webkit-box;
display: -moz-inline-box;
display: -ms-inline-flexbox;
display: -webkit-inline-flex;
display: inline-flex;
-moz-justify-content: space-around;
-ms-justify-content: space-around;
justify-content: space-around;
-webkit-flex-flow: row wrap;
-moz-flex-flow: row wrap;
flex-flow: row wrap;
}
.flex-item {
background: #eaeaea;
padding: 5px;
width: 130px;
height: 90px;
margin-top: 0px;
margin-left: 0px;
color: black;
font-weight: bold;
font-size: 12px;
text-align: center;
cursor: pointer;
}
.flex-item:hover {
background: #d9d9d9;
}
.flex-item-stop {
background: crimson;
padding: 5px;
width: 130px;
height: 90px;
margin-top: 0px;
color: black;
font-weight: bold;
font-size: 12px;
text-align: center;
cursor: pointer;
}
.flex-item-stop:hover {
background-color: #bb1133;
}
#Menue {
position: fixed;
left: 0;
height: 25%;
width: 650px;
float: right;
padding: 25px 0;
margin: -25px 0;
display: inline-flex;
display: -moz-inline-flex;
display: -webkit-inline-flex;
justify-content: space-around;
-moz-justify-content: space-around;
-webkit-justify-content: space-around;
flex-flow: column wrap;
-moz-flex-flow: column wrap;
-webkit-flex-flow: column wrap;
}
<div id="Menue">
<div class="flex-container">
<div class="flex-item">Vanilla</div>
<div class="flex-item">Citrus</div>
<div class="flex-item">Bananasplit</div>
<div class="flex-item">Gum</div>
</div>
<div class="flex-container" style="margin-top:10%;">
<div class="flex-item">Sweden</div>
<div class="flex-item">Austria</div>
<div class="flex-item">Russia</div>
<div class="flex-item">Brazil</div>
</div>
<div class="flex-container" style="margin-top:10%;">
<div class="flex-item">Positiv</div>
<div class="flex-item">Negativ</div>
<div class="flex-item">Neutral</div>
<div class="flex-item-stop"> </div>
</div>
</div>
I just cant create the spacing between the tiles and my result seems different in different browsers, especially in the Internet Explorer 11. What i also would like to have is that there should always be 4 Tiles in a singel "line" is this possible?
Now comes my Question: What exactly do i have to change in my Code to accomplish such a Tile System?
Are the alternatives to Flexbox?
Any Examples suggestions are appreciated.
You can try something like this :
.row{
display:table;
content:'';
clear:both;
width:100%;
}
.item{
box-sizing:border-box;
width:25%;
border:1px solid white;
height:100px;
background-color:yellow;
float:left;
text-align:center;
}
<div class="row">
<div class="item">Vanilla</div>
<div class="item">Gum</div>
<div class="item">Citrus</div>
<div class="item">BananaSplit</div>
</div>
<div class="row">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
<div class="row">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
Give this a crack:
HTML:
<div class="container">
<div class="inner-block"></div>
<div class="inner-block"></div>
<div class="inner-block"></div>
<div class="inner-block"></div>
<div class="inner-block"></div>
<!-- e.t.c... !-->
</div>
CSS:
.container{
width: 100%;
}
.container > .inner-block{
display: inline-block;
position: relative;
width: calc(25% - 13px);
height: 0;
padding-bottom: calc(25% - 13px);
margin: 5px;
background: blue;
}
JsFiddle: https://jsfiddle.net/r4w1v0dm/2/