images that squishes when I add more using flexbox - html

I'm using amchart and I want to display multiple charts in one page (as columns), my problem is that I don't want scroll bar no matter how many charts I add (yes I want them to squish) also when I display only one chart I want it in it's normal size (not squished or small)
How can I achieve that?
I'm trying now with images and if it works I will do it on my charts.
html:
<div class="content">
<div class="row">
<div class="cell">
<img src="http://i.imgur.com/OUla6mK.jpg"/>
</div>
<div class="cell">
<img src="http://i.imgur.com/M16WzMd.jpg"/>
</div>
<div class="cell">
<img src="http://i.imgur.com/M16WzMd.jpg"/>
</div>
<div class="cell">
<img src="http://i.imgur.com/M16WzMd.jpg"/>
</div>
</div>
</div>
</div>
css:
body{ overflow-y : hidden;}
.content {
background-color: yellow;
}
.row {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-orient: vertical;
-moz-box-orient: vertical;
box-orient: vertical;
flex-direction: column;
-webkit-box-pack: center;
-moz-box-pack: center;
box-pack: center;
justify-content: center;
-webkit-box-align: center;
-moz-box-align: center;
box-align: center;
align-items: center;
background-color: red;
}
.cell {
-webkit-box-flex: 1;
-moz-box-flex: 1;
box-flex: 1;
-webkit-flex: 1 1 auto;
flex: 1 1 auto;
padding: 10px;
margin: 10px;
background-color: green;
border: 1px solid red;
text-align: center;
}
img {max-height:100%;}
on jsfiddle: http://jsfiddle.net/89dtxt6s/356/
Thanks!

Step 1: Add the following to .row to ensure it fills the viewport height:
.row {
height: 100vh;
}
Step 2: You need to give each .cell a flex display. Additionally, you'll need to adjust your flex-basis (third argument to the shorthand) to 100%. Finally, you'll need to set min-height to zero, in order for each element to totally shrink, if need be.
.cell {
display: flex;
flex-direction: column;
flex: 1 1 100%; /* no longer auto */
min-height: 0;
}
Step 3: Add a one-hundred percent width and height to the image.
img {
width: 100%;
height: 100%;
}
Result: squishy images. Ugly? Sure. But I'm not judging.
https://jsfiddle.net/jaunkv7k/

Related

Make flex child equal height of parent inside of grid column

I'm trying to build a pricing table where each column contains a card. I want all cards to stretch to the height of their parent (.col) elements.
Note: I'm using Bootstrap 4, and trying to achieve this with the existing grid system (for the sake of consistency) and with this particular piece of markup. I can't get the cards to grow to the height of their parent containers. Is this even possible with the current markup?
The basic markup is this:
<div class="row">
<div class="col">
<div class="card">
blah
blah
blah
</div>
<div class="card">
blah
</div>
<div class="card">
blah
</div>
</div>
</div>
Here is my pen: https://codepen.io/anon/pen/oZXWJB
Add flex-grow : 1; to your .card rule. HTML markup is fine.
.row {
display: flex;
flex-flow: row wrap;
background: #00e1ff;
margin: -8px;
}
.col {
display: flex;
flex: 1 0 400px;
flex-flow: column;
margin: 10px;
background: grey;
}
.card {
display: flex;
padding: 20px;
background: #002732;
color: white;
opacity: 0.5;
align-items: stretch;
flex-direction: column;
flex-grow: 1;
}
You may also look at Foundation 6 Equalizer plugin. They use JavaScript though.
You just need to add height: 100% on .card
.card {
display: flex;
padding: 20px;
background: #002732;
color: white;
opacity: 0.5;
align-items: stretch;
flex-direction: column;
height: 100%;
}
DEMO
Just add flex: 1 to your card class. Should be enough. And you don't need display: flex; align-items: stretch; flex-direction: column in this class.
Add height: 100% to .card
.card {
display: flex;
height: 100%;
padding: 20px;
background: #002732;
color: white;
opacity: 0.5;
align-items: stretch;
flex-direction: column;
}
example - https://codepen.io/anon/pen/zZGzyd
Just make your .cardheight to 100%.
.card{
height: 100%;
display: flex;
padding: 20px;
background: #002732;
color: white;
opacity: 0.5;
align-items: stretch;
flex-direction: column;
}
If you're using Bootstrap 4, they already have build-in classes for what you're trying to achieve.
Add card-deck to <div class="row card-deck">
Add display: inline-block; on .col and min-height: 100%; on .class
.row {
display: flex;
...
}
.col {
display: inline-block;
...
}
.card {
min-height:100%;
...
}`

HTML Flex divs leaving empty space on the right

I am having an issue where I am trying to use flex to show divs left, center, and right. Although I run into an issue where the center column isn't in-line with the div above it. When I change the flex to flex: 1, it does put each column in line but leaves an empty space to the right of my furthest right div. Can someone offer some advice or tips on how to correct this? I have seen similar questions about flex, but nothing the specifically addressed this concern. I have provided some of the code I am using currently. Thank you in advance!
.container {
display: flex;
width: 100%;
justify-content: space-between;
}
.item {
flex: 1;
}
<body>
<div class="container">
<div class="item">Hello World</div>
<div class="item">It is me</div>
<div class="item">BYE</div>
</div>
<div class="container">
<div class="item">Hello World, again!</div>
<div class="item">It is me, again?</div>
<div class="item">BYE</div>
</div>
</body>
You need to swap
justify-content: space-between;
for
justify-content: space-around;
Working Example:
.container {
display: flex;
justify-content: space-around;
}
.item {
flex: 1 1 33%;
margin: 6px;
padding: 6px;
color: rgb(255,255,255);
background-color: rgb(255,0,0);
font-weight: bold;
}
<div class="container">
<div class="item">Hello World</div>
<div class="item">It is me</div>
<div class="item">BYE</div>
</div>
<div class="container">
<div class="item">Hello World, again!</div>
<div class="item">It is me, again?</div>
<div class="item">BYE</div>
</div>
Please check the code. There is no empty space on right. padding: 10px for body and .container have margin-bottom: 30px; also .item have margin-bottom: 10px;. I think you need to learn more about the flex box.
body
{
margin: 0;
padding: 10px;
background-color: #898989;
}
.container
{
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
margin-bottom: 30px;
border: 2px solid #000;
-webkit-box-align: center;
-webkit-align-items: center;
-moz-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-flex: 0;
-webkit-flex: 0 0 100%;
-moz-box-flex: 0;
-ms-flex: 0 0 100%;
flex: 0 0 100%;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-box-pack: start;
-webkit-justify-content: flex-start;
-moz-box-pack: start;
-ms-flex-pack: start;
justify-content: flex-start;
}
.container .item
{
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
margin-bottom: 10px;
border: 5px solid #f0f;
-webkit-box-align: center;
-webkit-align-items: center;
-moz-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-flex: 1;
-webkit-flex-grow: 1;
-moz-box-flex: 1;
-ms-flex-positive: 1;
flex-grow: 1;
-webkit-box-pack: center;
-webkit-justify-content: center;
-moz-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
}
<body>
<div class="container">
<div class="item">Hello World</div>
<div class="item">It is me</div>
<div class="item">BYE</div>
</div>
<div class="container">
<div class="item">Hello World, again!</div>
<div class="item">It is me, again?</div>
<div class="item">BYE</div>
</div>
</body>
If I understood the question correctly:
.item {
flex: 1;
text-align: center;
}
If you instead mean centering the entire div, use:
.container {
margin: 0 auto;
}
I hope your code is working correctly, just applied background and observed there is no space after the right most div
Refer this bootply http://www.bootply.com/T0TTJD1kTO
Instead of flex:1 you can use opacity:0.99 on child items, it will solve your Issue.
Here is an link to fiddle:
.item {
opacity: 0.99;
}
It's because all the child has same name, it's creating some problem.
Other Way to solve this is simply remove flex:1 or remove .item in css, it will automatically resolve it.
Here is working example of that in my Fiddle, you can check it.
https://jsfiddle.net/ABhimsaria/z7a4b7jo/
It's important to remember the initial settings of a flex container.
Some of these settings include:
flex-direction: row - flex items will align horizontally.
justify-content: flex-start - flex items will stack at the start of the line on the main axis.
align-items: stretch - flex items will expand to cover the cross-size of the container.
flex-wrap: nowrap - flex items are forced to stay in a single line.
flex-shrink: 1 - a flex item is allowed to shrink
Note the last setting.
Because flex items are allowed to shrink by default (which prevents them from overflowing the container), the specified flex-basis / width / height may be overridden.
For example, flex-basis: 100px or width: 100px, coupled with flex-shrink: 1, will not necessarily be 100px.
To render the specified width – and keep it fixed – you will need to disable shrinking:
div {
width: 100px;
flex-shrink: 0;
}
OR
div {
flex-basis: 100px;
flex-shrink: 0;
}
OR, as recommended by the spec:
flex: 0 0 100px; /* don't grow, don't shrink, stay fixed at 100px */
Some Cool Useful Links to know in-depth about flex and to play with them are:
http://flexboxfroggy.com/
https://scotch.io/tutorials/a-visual-guide-to-css3-flexbox-properties
Center and bottom-align flex items
https://philipwalton.com/articles/what-no-one-told-you-about-z-index/

side by side boxes with full width across all devices

I need boxes to show side by side for the same full width of 100% for each box inside my container and across all device dimensions.
Now the following works, it shows what I am after, however this solution does not work on the actual physical devices such as tablets and smartphones, I dont know why, but is it possible to change my code so that the effect actually shows how designed on the physical devices (and not just in my browser and resizing the browser to see the effect)?
.box2 {
margin: 5px 5px 5px 0;
text-align: center;
float: left;
background-color: #FFF;
color: #000;
border: 2px solid #A10000;
height: auto;
width: calc((100% / 2) - 5px);
box-sizing: border-box;
font-size: 12px;
}
.row {
margin-right: -15px;
margin-left: -15px;
}
.container {
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}
#media screen and (min-width: 768px) {
.box2 {
width: calc((100% / 3) - 5px);
}
}
#media screen and (min-width: 992px) {
.box2 {
width: calc((100% / 6) - 5px);
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<h1>1</h1>
<h1>2</h1>
<h1>3</h1>
<h1>4</h1>
<h1>5</h1>
<h1>6</h1>
</div>
</div>
</div>
Set the display of the div child of the .row, which is the third div, to flex, like this:
.container > .row > div {
display: flex;
}
Heres one way you can do that using flex boxes instead, which will create a platform independent rendering that you can be sure will work everywhere:
CSS Code for FlexBox setup
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<center>
<div id="flexcanvas">
<div id="container" class="flexChild rowParent">
<div class="flexChild" id="box1">
<h1>Box #1</h1>
</div>
<div class="flexChild" id="box2">
<h1>Box #2</h1>
</div>
<div class="flexChild" id="box3">
<h1>Box #3</h1>
</div>
<div class="flexChild" id="box4">
<h1>Box #4</h1>
</div>
<div class="flexChild" id="box5">
<h1>Box #5</h1>
</div>
<div class="flexChild" id="box6">
<h1>Box #6</h1>
</div>
</div>
</div>
</center>
<style>
#flexcanvas {
width: 100%;
height: 600px !important;
}
.rowParent,
.columnParent {
display: flex;
/* wrapping flex boxes causes platform independent arrangement*/
flex-wrap: wrap;
justify-content: flex-start;
align-content: stretch;
align-items: stretch;
flex-direction: row;
/* webkit-based browser support */
display: -webkit-flex;
display: -webkit-box;
-webkit-box-direction: normal;
-webkit-box-orient: horizontal;
-webkit-flex-direction: row;
-webkit-flex-wrap: wrap;
-webkit-box-pack: start;
-webkit-justify-content: flex-start;
-webkit-align-content: stretch;
-webkit-box-align: stretch;
-webkit-align-items: stretch;
/* MS-based browser support */
display: -ms-flexbox;
-ms-flex-direction: row;
-ms-flex-wrap: wrap;
-ms-flex-pack: start;
-ms-flex-align: stretch;
-ms-flex-line-pack: stretch;
}
.columnParent {
flex-direction: column;
/* webkit-based browser support */
-webkit-box-orient: vertical;
-webkit-flex-direction: column;
/* MS-based browser support */
-ms-flex-direction: column;
}
.flexChild {
flex: 1;
align-self: auto;
padding: 20px;
border: 1px black solid;
-webkit-box-flex: 1;
-webkit-flex: 1;
-webkit-align-self: auto;
-ms-flex: 1;
-ms-flex-item-align: auto;
}
</style>
</body>
</html>
The above snippet basically creates flexible boxes that can warp and change to accomodate any device no matter how large or small, and is probably the best way to go.
In terms of viewing pages as they would appear on devices, try the "responsive design view" option in the developer tools of most modern browsers.
enjoy.

vertically align content within Chrome

I got a situation where flex box is not working the way I want it to within Chrome but it works in other browsers (apart from iOS mobile devices).
I am struggling to vertically align any content within Chrome but works in everything else. Any ideas?
Also, does anyone know a way I can dynamically stretch a div to a certain % of the div class content which will also work within chrome?
Thanks in advance. See the bottom for demo and screenshots.
HTML
<div class="container">
<div class="content">
<h2>Ticket System <span style="color:#339933; font-weight:bold;">Open</span> Customer Ticket List</h2>
<a class="BlueButton" href="ticket_view_cust_ticket.php">Open Customer Tickets</a>
<a class="BlueButton" href="ticket_view_cust_ticket_rejected.php">Rejected Customer Tickets</a>
<div class="centerContent">
There are currently no open customer tickets
</div>
</div>
</div>
CSS
html,body
{
height: 100vh;
}
body
{
display: table;
margin: 0 auto;
font-family: Tahoma,Arial,Sans-Serif;
}
.container
{
height: 98vh;
vertical-align: middle;
width: 70vw;
min-width:1024px;
margin-left:auto;
margin-right:auto;
margin-top: 1vh;
display: flex;
flex-direction: column;
}
.content
{
background-color: #ff0000;
flex: auto;
webkit-flex-direction: column;
-moz-flex-direction: column;
-ms-flex-direction: column;
-o-flex-direction: column;
flex-direction: column;
webkit-flex-shrink: 0;
-moz-flex-shrink: 0;
-ms-flex-shrink: 0;
-o-flex-shrink: 0;
flex-shrink: 0;
text-align: center;
font-size: 12px;
padding-top:20px;
min-height:600px;
}
.centerContent
{
height: 95%;
padding: 0;
margin: 0;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
align-items: center;
justify-content: center;
}
Demo - https://jsfiddle.net/qr2tpgo6/1/
Container Screenshot - http://prntscr.com/azp8bk
Firefox - http://prntscr.com/azp4oj
Chrome - http://prntscr.com/azp4hy
Your container is missing display: flex, so flex properties aren't working.
Add this:
.content
{
background-color: #ff0000;
flex: auto;
flex-direction: column;
flex-shrink: 0;
text-align: center;
font-size: 12px;
padding-top:20px;
min-height:600px;
display: flex; /* new; establish flex container */
justify-content: center; /* new; center children vertically */
}
Revised Fiddle

flex-box IE10 doesn't respect overflow

I'm attempting to create a flexbox with a header and footer of a set height and have a flexible content area that may or may not scroll depending on the amount of content within.
You can see my fiddle here http://jsfiddle.net/evilbuck/EtQXf/3/
This works in FF, chrome, but not IE10. IE10 seems to not respect the overflow property and bleeds into the content below.
My expectation is that the .content area will expand to fill the remaining space of it's parent and scroll when necessary.
<div class="container">
<header>A header</header>
<div class="content">Some content that will overflow or not.</div>
<footer>A footer</footer>
</div>
.container {
margin: 10px auto;
width: 300px;
height: 350px;
display: flex;
display: -webkit-flex;
display: -moz-flex;
display: -ms-flex;
flex-direction: column;
-webkit-flex-direction: column;
-moz-flex-direction: column;
-ms-flex-direction: column;
}
header, footer {
border: 1px solid grey;
height: 30px;
padding: 5px;
text-align: center;
clear: both;
}
.content {
flex: 1;
-webkit-flex: 1;
-moz-flex: 1;
-ms-flex: 1;
overflow: auto;
}
What am I doing wrong here?
I'll leave this here for others, but the short of it is that I needed to use
display: -ms-flexbox;
updated fiddle: http://jsfiddle.net/EtQXf/4/