Make grid children items shrink or grow according to item content itself - css-grid

I made a simple grid of two columns and two rows, was easy. But for the content inside it wasn't.
I have added snippet here, when I use grid-template-rows with auto or with 4 1fr it gives me sections that is identical in height according to biggest section.
What I want is 4 sections that shrinks when content is less, like in sections have only a number.
To clarify more, I want these parts with green background and very small content to shrink to fit the content only.
UPDATE 1: I added a photo to clarify what I want to achieve with this. You will notice that rows on right and left align together according to content.
The part with aqua color will make its content expand to fit the content, and the part with blue background with expand because the aqua background part is bigger.
I want these parts only expand when there is content only BUT I want both to expand with it or get smaller if there no content.
section {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr 1fr 1fr;
grid-gap: 20px;
}
.grid-section{
background: blue;
display: grid;
grid-template-rows: 1fr 1fr 1fr 1fr;
}
.grid-section div:nth-child(1){
background: yellow;
}
.grid-section div:nth-child(2){
background: green;
}
<section>
<div class="grid-section">
<div>
1
</div>
<div>
1
</div>
<div>
1
</div>
<div>
1
</div>
</div>
<div class="grid-section">
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries
</div>
<div>
1
</div>
<div>
2
</div>
<div>
1
</div>
</div>
<div class="grid-section">
<div>
1
</div>
<div>
1
</div>
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.
</div>
<div>
1
</div>
</div>
<div class="grid-section">
<div>
1
</div>
<div>
1
</div>
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries
</div>
<div>
1
</div>
</div>
</section>

I just set the height with max-content. So the height is gonna fit the content dynamically.
section {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: repeat(4, 1fr);
grid-gap: 20px;
}
.grid-section{
background: blue;
display: grid;
grid-template-rows: repeat( 4, minmax(1px, 1fr) );
}
.grid-section div:nth-child(1){
background: yellow;
}
.grid-section div:nth-child(2){
background: green;
height: max-content
}
<section>
<div class="grid-section">
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries
</div>
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries
</div>
<div>
1
</div>
<div>
1
</div>
</div>
<div class="grid-section">
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries
</div>
<div>
1
</div>
<div>
2
</div>
<div>
1
</div>
</div>
<div class="grid-section">
<div>
1
</div>
<div>
1
</div>
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.
</div>
<div>
1
</div>
</div>
<div class="grid-section">
<div>
1
</div>
<div>
1
</div>
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries
</div>
<div>
1
</div>
</div>
</section>

Is this the result you want you to achieve? Simply used grid-auto-rows: auto; in .grid-section. More about grid-auto-rows.
section {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr 1fr 1fr;
grid-gap: 20px;
}
.grid-section{
background: blue;
display: grid;
grid-auto-rows: auto; /* replaced grid-template-rows with this */
}
.grid-section div:nth-child(1){
background: yellow;
}
.grid-section div:nth-child(2){
background: green;
}
<section>
<div class="grid-section">
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries
</div>
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries
</div>
<div>
1
</div>
<div>
1
</div>
</div>
<div class="grid-section">
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries
</div>
<div>
1
</div>
<div>
2
</div>
<div>
1
</div>
</div>
<div class="grid-section">
<div>
1
</div>
<div>
1
</div>
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.
</div>
<div>
1
</div>
</div>
<div class="grid-section">
<div>
1
</div>
<div>
1
</div>
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries
</div>
<div>
1
</div>
</div>
</section>
UPDATED
If you need left and right blocks in each row to be the same height - you have to use one single grid element instead of two separated. This is the only way to synchronize each row height using CSS. Made one single grid with grid-auto-rows: auto;
section {
display: grid;
grid-template-columns: 1fr 1fr;
grid-auto-rows: auto;
grid-column-gap: 20px;
grid-row-gap: 1px;
}
section div {
background: cyan;
}
<section>
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries
</div>
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries
</div>
<div>
1
</div>
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown
</div>
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries
</div>
<div>
1
</div>
<div>
2
</div>
<div>
1
</div>
</section>

Related

css transition on mouseout appears delayed

I'm trying to add transitions to a list of items where mouse over causes the item to expand by changing max-height.
The expand on mouse enter happens immediately but the mouse out transition is delayed.
jsfiddle https://jsfiddle.net/cawkie/u2eLh18f/2/
<html>
<head>
<style>
.inner {
border: solid 1px #000000;
width: 300px;
max-height: 30px;
overflow: hidden;
transition: max-height 10s linear 0s;
}
.inner:hover {
max-height: 10000px;
}
</style>
</head>
<body>
<div class="outer">
<div class="inner">
Lorem ipsum dolor ....
</div>
<div class="inner">
Lorem ipsum dolor ...
</div>
</div>
</body>
</html>
Possibly not relevant, but the JS mouse-out event is immediate.
Am I missing something?
Is there a workaround?
If this is normal/intended - why?
I could use JS/jQuery but was trying not to :-)
If your not opposed to using Bootstrap, they have a really nice accordion implementation you could use the achieve this effect without writing your own Javascript. If you do want to implement it yourself, you can add their CDN link to your page, then use Chrome DevTools to inspect the CSS in the Sources tab. Just prettify it and Ctrl+F search for the relevant classes.

How to use text-wrap for ion-card in Ionic 2?

THE SITUATION:
I need to use the text-wrap for an ion-card but it seems it doesn't work.
THE CODE:
<ion-card>
<ion-card-header text-wrap>
<h2> <ion-icon name="list-box"></ion-icon> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labor</h2>
</ion-card-header>
<ion-card-content>
<p>content</p>
</ion-card-content>
</ion-card>
THE PLUNKER:
http://plnkr.co/edit/z5ehOQgz0oArhg6mMtUj?p=preview
THE QUESTION:
There is a way to use text-wrap for the ion-card?
<ion-card-header text-wrap>
you can use text-wrap in other components too.
Ok, setting white-space: normal; to the ion-card-header fixed this.
<ion-card-header style="white-space: normal;"> could be placed in css file as well.
Plunker: http://plnkr.co/edit/GjDmJBNMdnoPiteAKpDB
white-space: normal; is correct. But it should be placed on the header tag IE h2. By default "ion-labels" (a class that can be injected into the DOM) have white-space: nowrap; applied to them. So setting white-space: normal; on the header tag selecting the ion-label tag through css will work.

Central aligning nested items using Foundations 'Flex Grid'

With the Flex Grid of Foundation 6, I'm trying to centrally align a child of a parent ele that has been centrally aligned with Foundation's 'align-center' class.
The parent .row uses Flex Box to align (justify) the content of its children. How do I apply central alignment to the ele on line 4, using the Framework?
Notes:
The 'align-self-center' on line 4 has no effect.
In-line styling used for sample/readability only.
Applying 'margin:auto' to line 4 resolves the issue, however would not in the case of using an img.
<section class="row expanded align-middle align-center" style="height: 100%;">
<div class="columns small-7 medium-4">
<h3 class="text-center">lakakakaka</h3>
<div class="align-self-center" style="height: 20px; width: 20px; background: pink;"></div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
In the case of using an img, applying a wrapper as a column and setting margin: auto also achieves the desired effect, but surely theres a better way to do this?
<section class="row expanded align-middle align-center" style="height: 100%;">
<div class="columns small-7 medium-4">
<h3 class="text-center">lakakakaka</h3>
<div class="row columns small-6" style="margin:auto">
<img src="..." alt="..." style="width: 100%;" />
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</section>
By default, .row is a flex parent so .columns are flex children. To make a .column a flex parent so that it's children can be aligned, you need some CSS like
.align-middle {
display: flex;
align-items: center;
justify-content: center;
}
We wrote a lesson on this recently that will help https://zurb.createsend.com/campaigns/reports/viewCampaign.aspx?d=y&c=E5D5A5C6700B86DC&ID=3053EAAD5186C206&temp=False&tx=0

In Foundation 5, how do you place three images side by side without spaces?

I've been using Foundation 5 for about a month, but I'm having trouble placing three images side by side without spaces. Any ideas please?
Here's the code prior to adding Foundation 5:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style>
body {
margin: 0;
border: 0;
padding: 0;
}
.left {
float:left;
width: 15%;
}
.center {
float: left;
background:white;
width: 70%;
}
.main {
float:left;
width:70%;
}
aside {
float:left;
width:30%;
}
.right {
float: left;
width: 15%;
}
</style>
</head>
<body>
<div class="left"><img src="_images/topo_l.jpg" alt="topo map" /></div>
<div class="center">
<div class="header">
<h1>Header H1</h1>
</div>
<div class="main">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. </p>
</div>
<aside>
<ul>
<li>Aside li items here</li>
<li>Aside li items here</li>
<li>Aside li items here</li>
<li>Aside li items here</li>
<li>Aside li items here</li>
<li>Aside li items here</li>
</ul>
</aside>
</div>
<div class="right"><img src="_images/topo_r.jpg" alt="topo map" /></div>
</body>
</html>
It looks okay at this point, but after I include Foundation (foundation.css, etc.) the code breaks.
I believe you're looking for Foundation's Block Grid feature.
http://foundation.zurb.com/docs/components/block_grid.html
You could also use the regular grid, and in the class="row", modify to something like class="row small-collapse". Example below.
<!-- BEGIN BLOCK GRID EXAMPLE -->
<div class="row">
<ul class="small-block-grid-3">
<li style="background-color:blue;height:100px;"></li>
<li style="background-color:red;height:100px;"></li>
<li style="background-color:green;height:100px;"></li>
</ul>
</div>
<!-- END BLOCK GRID EXAMPLE -->
<!-- BEGIN REGULAR GRID EXAMPLE -->
<div class="row small-collapse">
<div class="small-4 columns" style="background-color:blue;height:100px;"></div>
<div class="small-4 columns" style="background-color:red;height:100px;"></div>
<div class="small-4 columns" style="background-color:green;height:100px;"></div>
</div>
<!-- END REGULAR GRID EXAMPLE -->
The block grid uses ul and li tags, while the regular grid uses the traditional row and columns classes inside div.

find open/close tag and replace?

I have string:
<p>Lorem ipsum dolor sit amet. <object width="500" height="500" type="application/x-shockwave-flash"
data="http://www.abc.com/m/l5J16d65wOpT" style="display: block; margin-left: auto; margin-right: auto;">
<param value="always" name="allowscriptaccess">
</object> Lorem ipsum dolor sit amet</p> Lorem ipsum dolor sit amet
Now, i want to add <div class="player"></div> around object tag, it's will become:
<p>Lorem ipsum dolor sit amet. <div class="player"><object width="500" height="500" type="application/x-shockwave-flash"
data="http://www.abc.com/m/l5J16d65wOpT" style="display: block; margin-left: auto; margin-right: auto;">
<param value="always" name="allowscriptaccess">
</object></div> Lorem ipsum dolor sit amet</p> Lorem ipsum dolor sit amet
a preg_replace might be useful here :)
$result = preg_replace('|(<object.*</object>)|sui', '<div class="player">$1</div>', $html);
If you want to replace it like this, then just use the normal str_replace
//PHP
$myString = str_replace("<object>", "<div class=\"player\"><object>", $originalString);
$myString = str_replace("</object>", "</object></div>", $originalString);