Responsive Image in Neat 2.0 - css

Is there a recommended way to get an image to be 100% of the height of a column in Neat based on the size that the text makes the column? I've attached an example of what I'm trying to accomplish below.
I'm trying to make the image fill the 1/3 column it is placed in with object-fit: cover, the problem is that because the height of the container isn't set, it doesn't know what to fit the image to.
Image With No Height Set
If I put the image in a div with display: flex; and height:100%, the height gets set to the height of the image, when I want it to get set to the height of the parent, which is the grid-container that has the two columns in it.
Image With 100% Height Set
What I'm trying to accomplish is have a responsive image that constantly fills the space of its column to match the height of the text in the next column.
I should note that I'm trying to accomplish this without setting a specific height for the parent container such as height:200px, I want the height to be fluid to the content in it.
HTML Code:
<section class="image-block" style="background: #5777e0; color:#fff;">
<div class="one-thirds-column-full no-padding third-image-box">
<div class="flex">
<img src="https://unsplash.it/1600/1200?image=148" />
</div>
</div>
<div class="two-thirds-column-full">
<div class="text">
<h2>1/3 Image on Left with 2/3 Text on Right</h2>
<p>
The path of the righteous man is beset on all sides by the iniquities of the selfish and the tyranny of evil men. Blessed is he who, in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's
keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy My brothers. And you will know My name is the Lord when I lay My vengeance upon thee.
</p>
</div>
</div>
</section>
CSS:
section {
#include grid-container;
#include grid-media($neat-small) {
#include grid-container($neat-small);
}
#include grid-media($neat-medium) {
#include grid-container($neat-medium);
}
#include grid-media($neat-large) {
#include grid-container($neat-large);
}
#include grid-media($neat-larger) {
#include grid-container($neat-larger);
}
#include grid-media($neat-super) {
#include grid-container($neat-super);
}
}
.one-thirds-column-full {
#include grid-column(1, $neat-grid-full);
padding:1em;
#include grid-media($neat-medium-full) {
#include grid-column(2);
}
#include grid-media($neat-large-full) {
#include grid-column(4);
}
}
.two-thirds-column-full {
#include grid-column(1, $neat-grid-full);
padding:1em;
#include grid-media($neat-small-full) {
#include grid-column(2);
}
#include grid-media($neat-medium-full) {
#include grid-column(4);
}
#include grid-media($neat-large-full) {
#include grid-column(8);
}
}
.image-block{
background: #fff;
text-align: left;
.third-image-box{
height:auto;
}
.half-image-box{
height:auto;
}
.flex{
display:flex;
height:100%;
}
img{
height:auto !important;
object-fit: cover;
}
}
.text{
max-width:$max-text-width;
}

There is a bug in the documentation and grid-container does not require or need access to the grid so you can shorten the first part to ⤵
section {
#include grid-container;
I don't think you need that much markup in the html around the img. You may be able to just do
<section class="image-block">
<img src="https://unsplash.it/1600/1200?image=148" class="one-thirds-column-full">
<div class="two-thirds-column-full">
…
</div>
</section>
and then the css would be like…
.image-block{
align-items: stretch;
display: flex;
}
align-items: stretch will cause both objects to fill the vertical space. The rest is up to object-fit: cover, etc

Related

How to force the right six-column DIV to stay on top in RWD?

I'm using a custom 12-column grid and given a row like:
<div class="row">
<div id="the-pink" class="lg-6 md-12 sm-12"><!-- content --></div>
<div id="the-violet" class="lg-6 md-12 sm-12"><!-- content --></div>
</div>
I'm trying to get this behaviour: On medium and small devices each block will be 12-columns width but, by default, #the-violet will fall below #the-pink. I'd like the opposite, that's #the-violet above #the-pink.
My current (simplified) SCCS is:
.row {
#include clearfix;
[class*="lg-"],
[class*="md-"],
[class*="sm-"] {
float: left;
}
}
.lg-6 {
width: 50%;
}
.md-12 {
#include respond-to("medium") {
width: 100%;
}
}
.sm-12 {
#include respond-to("small") {
width: 100%;
}
}
I'm assuming clearfix and respond-to mixins are well-known.
I've made and approach with fixed height giving my row a class named reversed like (Fiddle):
.reversed {
position: relative;
#include respond-to("small" "medium") {
.sm-12,
.md-12 {
position: absolute;
top: 0;
&::first-child {
top: 200px;
}
}
}
}
But, I'd like to know if anyone has faced this need before and has another approach to solve it in a clean way (without fixing height).
You could use float: right on them and write them in the reverse order in the HTML.

Flexbox - columns and ordering IOS

I have build a Layout relying on Flexbox. On smaller screens the direction switches from "normal" to columns plus some change in ordering.
That does work in Chrome, FF. On Safari #include flex-direction(column) is creating a big mess and whole layout is thrown apart, therefor I have created a mixin like this:
#mixin flex-columns() {
#include flex-direction(column);
display: -webkit-box;
-ms-flex-direction: column;
-webkit-box-orient: vertical;
}
That fixes the problems with IOS and looks as it should, except that #inlcude order(<n>); does not work any longer, neither on Chrome, nor on IOS, Firefox just works.
Far sake of simplicity here is a shortened version of the code:
<!-- html -->
<div class="container">
<div class="child child-1">...</div>
<div class="child child-2">...</div>
<div class="child child-3">...</div>
</div>
//Sass (compass)
div.container {
#include display-flex();
div.child-1 {
#inlcude flex(0 1 10%);
}
.
.
.
}
#media ... {
div.container {
#include flex-columns();
div.child-1 { #include order(2) }
div.child-2 { #include order(3) }
div.child-3 { #include order(1) }
}
}
Any Idea? If Safari does not support ordering if direction is set to columns, how could I exclude chrome from the safari fix (display: -webkit-box;)??
Thanks for help!

Div go to a new line in susy grid sytem instead being in one single line

I want to make a 12 columns page with susy which contain 3 equally spaced centred divs but when I do this
HTML :
<div id='container'>
<div class='col-1'></div>
<div class='col-2'></div>
<div class='col-3'></div>
</div>
SASS :
#container{
#include container(80%);
#include layout(12);
.col-1{ background:red; }
.col-2{ background:blue; }
.col-3{ background:green; }
.col-1,.col-2,.col-3{
#include span(1 of 3);
height:100px;
}
}
The 3rd div go to a new line as this picture but I want them in one single line.
And in my CSS file there is :
#container .col-1, #container .col-2, #container .col-3 {
width: 28.57143%;
float: left;
margin-right: 7.14286%;
height: 100px;
}
UPDATE: If I am right in my calculation 3*28.57143 + 7.14286*3 != 100 , it is approximately 107 , But why ?
28.57143 is the width of each div and 7.14286 is the right margin in percentage
I figured out the solution I had to implement the settings for the susy grid system before .
$susy: (
container: auto,
columns: 12,
gutters: .25,
gutter-position: inside,
math: fluid,
output: isolate,
);

Zen grids produces too large elements

I'm having problem with integration of zen-grids into drupal. I have installed sass and compass and using them. Then I created a content type with 3 fields. That give me structure in html like that:
<article class="node-1 node node-layout1 node-promoted view-mode-full clearfix" typeof="sioc:Item foaf:Document" about="/node/1">
<div class="field field-name-field-topleft field-type-text-long field-label-above">
<div class="field field-name-field-topmid field-type-text-long field-label-above">
<div class="field field-name-field-topright field-type-text-long field-label-above">
</article>
Then I tryied to use zen grids to create layout like that:
topleft___________topmid_______________topright
So I used that code:
$zen-column-count: 5; // Set the total number of columns in the grid.
.node-layout1{
max-width:1200px;
#include zen-grid-container; // Apply this mixin to the container.
}
.field-name-field-topleft {
#include zen-grid-item(2, 1);
}
.field-name-field-topmid {
#include zen-grid-item(1, 2);
}
.field-name-field-topright {
#include zen-grid-item(2, 3);
}
All works kinda ok I get all 3 elements in line but their widths and offsets are way too large, topmid starts where topright should finish, so my page is way too large after that.
Here is css i get generated from compass for all 3 elements:
.field-name-field-topleft {
float: left;
margin-left: 0;
margin-right: -200%;
width: 200%;
}
.field-name-field-topmid {
float: left;
margin-left: 100%;
margin-right: -200%;
width: 100%;
}
.field-name-field-topright {
float: left;
margin-left: 200%;
margin-right: -400%;
width: 200%;
}
I found out that the problem is in
$zen-column-count: 5;
not getting applied, it was set at start to 1 and seems that I can't change it.
It sounds like a problem with compass 1.0, as documented here:
https://github.com/JohnAlbin/zen-grids/issues/68
A fix is to add $zen-float-direction, $zen-column-count to your zen-grid-item call, i.e.
#include zen-grid-item(2, 1, $zen-float-direction, $zen-column-count);
use !global at the end of "$zen-column-count: 5" fixed it for me. it seems you must force zen to use new variable.
$zen-column-count: 5 !global;
https://www.drupal.org/node/2346291#comment-9475791

Bourbon/Neat: Reset margin and let nested divs span the whole width

I am new to Bourbon/Neat. I have a question concerning nesting: I want the red boxes fill the whole width, without a gutter between them. When using "#include omega" on them, the first box removes its margin-right, but the right box has still the margin and doesn't adjust its width.
Can u tell me how I can make them span the whole parent box without any margin between them?
Here's a demo: http://wuergeengel.net.dd13736.kasserver.com/
Here's my markup:
<div class="container">
<div class="box box-left"></div>
<div class="box box-right">
<div class="box-red-left nested"></div>
<div class="box-red-right nested"></div>
</div>
</div>
Here are my styles:
.container
{
#include outer-container;
}
.box
{
border: 1px solid black;
height: 500px;
}
.box-left
{
#extend .box;
#include span-columns(4);
}
.box-right
{
#extend .box;
#include span-columns(8);
.nested
{
border: 1px solid red;
height: 400px;
&.box-red-left
{
#extend .nested;
#include span-columns(3 of 8);
#include omega;
}
&.box-red-right
{
#extend .nested;
#include span-columns(5 of 8);
#include omega;
}
}
}
Or this:
#include span-columns(5 of 8, block-collapse)
See:
http://neat.bourbon.io/docs/#span-columns
There are a couple ways that you can do this.
Use Neat's table display layout. eg: #include span-columns(5 of 8, table);
Use Neat's underlying flex-grid and flex-gutter functions. eg:
width: flex-grid(5, 8) + flex-gutter(8);
float: left;

Resources