Column with fixed aspect ratio in two column flex layout - html

I need an image (image container to be precise) to resize according to container height and maintain its aspect ratio. Longer the text = bigger the image. Right now its ether image getting out of container or just staying still.
article,
.information,
.image {
margin: 8px;
border: 2px solid black;
}
article {
display: flex;
}
.information {
flex-grow: 1;
}
.image {
font-size: 0;
}
<article>
<div class="information">
<h3>too much text. image must be resized to fill whole height and stay square</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer congue, turpis in sollicitudin fringilla, sapien augue consectetur augue, id lacinia nibh massa at justo. Praesent pellentesque nunc elementum cursus faucibus. Donec vel diam scelerisque,
pharetra velit a, pharetra quam. Ut tristique justo id justo pharetra, eget sollicitudin libero mattis.</p>
</div>
<div class="image">
<img src="https://via.placeholder.com/150" />
</div>
</article>
<hr/>
<article>
<div class="information">
<h3>too little text</h3>
<p>Lorem ipsum dolor sit amet</p>
</div>
<div class="image">
<img src="https://via.placeholder.com/150" />
</div>
</article>

article,
.information,
.image {
margin: 8px;
border: 2px solid black;
}
.image{
width:50%;
}
.image img{
height:100%;
width:100%;
}
article {
display: flex;
}
.information {
width:50%;
flex-shrink:0;
}
.image {
font-size: 0;
}
<article>
<div class="information">
<h3>too much text. image must be resized to fill whole height and stay square</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer congue, turpis in sollicitudin fringilla, sapien augue consectetur augue, id lacinia nibh massa at justo. Praesent pellentesque nunc elementum cursus faucibus. Donec vel diam scelerisque,
pharetra velit a, pharetra quam. Ut tristique justo id justo pharetra, eget sollicitudin libero mattis
pellentesque nunc elementum cursus faucibus. Donec vel diam scelerisque,
pharetra velit a, pharetra quam. Ut tristique justo id justo pharetra, eget sollicitudin libero mattis.</p>
</div>
<div class="image">
<img src="https://via.placeholder.com/150" />
</div>
</article>
<hr/>
<article>
<div class="information">
<h3>too little text</h3>
<p>Lorem ipsum dolor sit amet</p>
</div>
<div class="image">
<img src="https://via.placeholder.com/150" />
</div>
</article>

Related

Maintain same height in elements inside columns located side by side with CSS

I have a template like this:
I want to maintain the same height between each item of both columns, depending on the one that has the biggest height, but only when they are side by side. In smaller screens, when they have width: 100%, each div has its own height depending of its own content height.
It should look like this:
I think that what I want is something like display: table, but I need both columns to be responsive.
All the questions I´have found are about maintaining the same height in both columns, but I´m already using flexbox to achieve this.
Is it possible to achieve what I vant with css only?
EDIT: Added code snippet. I forgot to mention that it needs to be supported by Chrome 36 (Android L WebView).
This question´s first answer shows what I wanted to achieve, but display:subgrid is not supported by any version Chrome at present:
Align child elements of different blocks
.title {
background: #b6fac0;
}
.content {
background: #b6b6fa;
}
.footer {
background: #f7f5b5;
}
.col-50 {
border: 1px solid red;
}
<link href="http://code.ionicframework.com/1.3.3/css/ionic.min.css" rel="stylesheet" />
<ion-content>
<div class="row responsive-sm">
<div class="col-50">
<div class="padding title">
Veeeeeeeeeeeeeeery veeeeeeeeeery veeeeeeeeeeeeeeery veeeeeeeeeery veeeeeeeeeeeeeeery veeeeeeeeeery veeeeeeeeeeeeeeery veeeeeeeeeery loooooooooooong title </div>
<div class="padding content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque rhoncus neque vitae lorem varius placerat. Donec blandit mi non mauris ornare faucibus. Quisque mollis nunc in tortor dapibus, et ornare lacus pharetra
</div>
<div class="padding footer">
Footer
</div>
</div>
<div class="col-50">
<div class="padding title">
Title </div>
<div class="padding content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque rhoncus neque vitae lorem varius placerat. Donec blandit mi non mauris ornare faucibus. Quisque mollis nunc in tortor dapibus, et ornare lacus pharetra. Phasellus tortor tortor, luctus
in dapibus sed, ultrices eget lorem. Morbi vehicula fermentum arcu, nec egestas augue. Fusce orci ex, sodales ut tellus sit amet, pretium pulvinar odio. Suspendisse potenti. Phasellus convallis metus sed erat rhoncus, eu tristique lacus fermentum.
</div>
<div class="padding footer">
Footer
</div>
</div>
</div>
</ion-content>
you may take a look at #supports to filter possible display:option or subgrid .
example with display:contents
.title {
background: #b6fac0;
}
.content {
background: #b6b6fa;
}
.footer {
background: #f7f5b5;
}
.col-50 {
border: 1px solid red;
}
#supports (display: contents) {
.row.responsive-sm {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-column-gap: 1em;
}
.col-50 {
display: contents
}
.title {
grid-row: 1
}
.content {
grid-row: 2;
}
#media screen and (max-width:500px) {
/* set the break point to the right value */
.row.responsive-sm,
.col-50 {
display: block;
}
}
}
<link href="http://code.ionicframework.com/1.3.3/css/ionic.min.css" rel="stylesheet" />
<ion-content>
<div class="row responsive-sm">
<div class="col-50">
<div class="padding title">
Veeeeeeeeeeeeeeery veeeeeeeeeery veeeeeeeeeeeeeeery veeeeeeeeeery veeeeeeeeeeeeeeery veeeeeeeeeery veeeeeeeeeeeeeeery veeeeeeeeeery loooooooooooong title </div>
<div class="padding content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque rhoncus neque vitae lorem varius placerat. Donec blandit mi non mauris ornare faucibus. Quisque mollis nunc in tortor dapibus, et ornare lacus pharetra
</div>
<div class="padding footer">
Footer a
</div>
</div>
<div class="col-50">
<div class="padding title">
Title </div>
<div class="padding content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque rhoncus neque vitae lorem varius placerat. Donec blandit mi non mauris ornare faucibus. Quisque mollis nunc in tortor dapibus, et ornare lacus pharetra. Phasellus tortor tortor, luctus
in dapibus sed, ultrices eget lorem. Morbi vehicula fermentum arcu, nec egestas augue. Fusce orci ex, sodales ut tellus sit amet, pretium pulvinar odio. Suspendisse potenti. Phasellus convallis metus sed erat rhoncus, eu tristique lacus fermentum.
</div>
<div class="padding footer">
Footer
</div>
</div>
</div>
</ion-content>
usefull for a fast check on supports on properties: https://caniuse.com/

responsive columns all same height with heading, paragraph, button all same height

I'm struggling to achieve responsive column. Currently all columns are not the same height. When the screen gets smaller, the paragraphs are not the same level, I am trying to make them the same level no matter what screen size. My next problem is the button will also not be the same level in all columns.
Bellow is currently my HTML:
<div class="container">
<div class="section">
<img src="http://via.placeholder.com/500x400" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
<h2>test heading text</h2 >
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
Learn more
</div>
<div class="section">
<img src="http://via.placeholder.com/500x400" alt="" width="400" height="300" style="max-width:90%;height:auto;" /> <h2>Fencing and Gates</h2>
<h2>test heading text long</h2 >
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vestibulum faucibus turpis, sed blandit mauris bibendum sit amet. Praesent congue enim at orci dapibus accumsan. Maecenas id leo at elit vestibulum sagittis at in ex. Cras vulputate laoreet dictum. Vestibulum nec quam placerat, blandit orci in, hendrerit ante. </p>
Learn more
</div>
<div class="section">
<img src="http://via.placeholder.com/500x400" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
<h2>test heading text longer </h2 >
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vestibulum faucibus turpis, sed blandit mauris bibendum sit amet. Praesent congue enim at orci dapibus accumsan. </p>
Learn more
</div>
<div class="section">
<img src="http://via.placeholder.com/500x400" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
<h2>test heading text longer longer </h2 >
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vestibulum faucibus turpis, sed blandit mauris bibendum sit amet. Praesent congue enim at orci dapibus accumsan. </p>
Learn more
</div>
<div class="section">
<img src="http://via.placeholder.com/500x400" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
<h2>test heading text</h2 >
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vestibulum faucibus turpis, sed blandit mauris bibendum sit amet. Praesent congue enim at orci dapibus accumsan. </p>
Learn more
</div>
<div class="section">
<img src="http://via.placeholder.com/500x400" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
<h2>Block Paved Driveways and Paths</h2>
<h2>test heading text</h2 >
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vestibulum faucibus turpis, sed blandit mauris bibendum sit amet. Praesent congue enim at orci dapibus accumsan. Maecenas id leo at elit vestibulum sagittis at in ex. Cras vulputate laoreet dictum. Vestibulum nec quam placerat, blandit orci in, hendrerit ante. </p>
Learn more
</div>
<div class="section">
<img src="http://via.placeholder.com/500x400" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
<h2>test heading text</h2 >
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vestibulum faucibus turpis, sed blandit mauris bibendum sit amet. Praesent congue enim at orci dapibus accumsan. </p>
Learn more
</div>
<div class="section">
<img src="http://via.placeholder.com/500x400" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
<h2>test heading text</h2 >
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vestibulum faucibus turpis, sed blandit mauris bibendum sit amet. Praesent congue enim at orci dapibus accumsan. </p>
Learn more
</div>
<div class="section">
<img src="http://via.placeholder.com/500x400" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
<h2>test heading text</h2 >
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vestibulum faucibus turpis, sed blandit mauris bibendum sit amet. Praesent congue enim at orci dapibus accumsan. </p>
Learn more
</div>
</div>
Below is my CSS:
.container:after { /*clear float*/
content: "";
display: table;
width: 100%;
clear: both;
}
.container {
margin-left: 100px;
margin-right: 100px;
text-align: center;
padding-top: 30px;
}
.section {
float: left;
width: 33.3333%;
padding-bottom: 50px;
border: 1px solid;
box-sizing: border-box;
display: table-cell;
}
.section p {
padding-bottom: 50px;
text-align: center;
font-family: "Montserrat", sans-serif;
font-size: 19px;
padding-left: 25px;
padding-right: 25px;
}
.section h2 {
text-align: center;
font-family: "Slabo 27px", serif;
font-size: 24px;
font-weight: 700;
text-align: center;
padding-left: 25px;
padding-right: 25px;
}
#media (max-width: 768px) {
.section {
float: none;
width: auto;
}
}
below is a js fiddle of what I currently have
https://jsfiddle.net/b147rmdh/
Any help on this would be greatly appreciated!
You need to specify a height for each column for them to all be the same height. If you don't then the columns will size themselves based on the amount of content they contain (which is currently what is happening in your code). More specifically relating to your code, if you add a specific height to your .section class, then all the columns should be the same height.
Once you have done this, you could use absolute positioning on all of the elements within the columns (the headers, paragraphs, buttons, etc) so that they all line up. If you aren't very familiar with absolute positioning and the position property in general, here is a great reference that explains positioning well. Definitely recommend giving it a read and taking the time to get a good understanding of positioning since it's one of the most fundamental CSS skills.
I'd suggest a Flexbox with wrapping.
.container {
display: flex;
flex-wrap: wrap;
}
.section {
width: 33.3333%;
}
Once you've done that, you can use a similar method vertically if you wrap the upper content in one element and keep the button separate. Set your flex-direction to column and justify-content to space-between.

Positioning an image in a 100vh box

I've been looking around for some time but couldn't find a solution.
So I'm working on a Personal portfolio with different sections (height: 100vh;). The problem I have is that I'm unable to position the images within the section itself (I want the image of the pinguïns to be positioned like the first lion image. But in the section below.). Can someone help me with this? (I'm using a bootstrap grid)
Code:
.section-1 {
background: radial-gradient(#2d2d2d, #1a1a1a);
height: 100vh;
}
.section-2 {
background: #fc6621;
height: 100vh;
}
.section-3 {
background: #20468b;
height: 100vh;
}
.col-sm-6 {
height: 100vh;
}
#profile img {
display: inline;
float: right;
position: absolute;
bottom: 0;
right: 0;
z-index: 0;
}
.center {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
}
.text {
height: 100vh;
position: relative;
z-index: 10;
}
<!-- 1st section -->
<div class="section-1">
<div id="profile"><img src="https://i.gyazo.com/4cefd23a7fdc59ac022cc46d44fe9321.jpg" width="1006" height="821"></div>
<div class="container">
<div class="row">
<div class="col-sm-6 center text">
<h1>I'm <strong>Gilles</strong></h1>
<p>Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Nullam id dolor id nibh ultricies vehicula ut id elit. Vestibulum id ligula porta felis euismod semper. Maecenas sed diam eget risus varius blandit sit amet non magna. Nullam
id dolor id nibh ultricies vehicula ut id elit. Donec sed odio dui. Cras mattis consectetur purus sit amet fermentum.</p>
<div class="col-sm-4 button">CONTACT ME</div>
</div>
</div>
</div>
</div>
<!-- 2nd section -->
<div class="section-2">
<div id="smartschool"><img src="https://i.gyazo.com/abdeb771b58043c53cfb08e5ffd42f6e.jpg" width="990" height="753"></div>
<div class="container">
<div class="row">
<div class="col-sm-6 center text">
<h1>I'm <strong>Gilles</strong></h1>
<p>Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Nullam id dolor id nibh ultricies vehicula ut id elit. Vestibulum id ligula porta felis euismod semper. Maecenas sed diam eget risus varius blandit sit amet non magna. Nullam
id dolor id nibh ultricies vehicula ut id elit. Donec sed odio dui. Cras mattis consectetur purus sit amet fermentum.</p>
<div class="col-sm-4 button">READ MORE</div>
</div>
</div>
</div>
</div>
<!-- 3th section -->
<div class="section-3">
<div id="dutchcreativestudio"><img src="https://i.gyazo.com/4cefd23a7fdc59ac022cc46d44fe9321.jpg" width="933" height="643"></div>
<div class="container">
<div class="row">
<div class="col-sm-6 center text">
<h1>I'm <strong>Gilles</strong></h1>
<p>Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Nullam id dolor id nibh ultricies vehicula ut id elit. Vestibulum id ligula porta felis euismod semper. Maecenas sed diam eget risus varius blandit sit amet non magna. Nullam
id dolor id nibh ultricies vehicula ut id elit. Donec sed odio dui. Cras mattis consectetur purus sit amet fermentum.</p>
<div class="col-sm-4 button">READ MORE</div>
</div>
</div>
</div>
</div>
The first one does the right thing!
But then it gets a mess (or they stack above each other)
position: absolute; is relative to the nearest parent. if no parents have a set position, it will be relative to the body which is what seems to be happening here.
so each 100vh section will need to have position: relative;
its also worth noting that float won't do anything on an element with absolute positioning, since position: absolute; takes the element out of the document flow.

How put 4 images and title and description side by side in a html box

How put 4 images and title and description side by side in a html box? No link, only text. As shown below:
Flex box is the way to go:
https://jsfiddle.net/s1mreoe8/1/
.flex{
display:flex;
}
Here is a guide : https://css-tricks.com/snippets/css/a-guide-to-flexbox/
.first {
float: left;
width: 50%;
}
.img {
float: left;
width:39%;
padding:10px;
}
.text
{
width:39%;
float: left;
padding:10px;
}
.img img {
width: 100%;
}
<div class="row">
<div class="first">
<div class="img">
<img src="http://www.fogosglobo.com.br/img/250x250-circle.png" alt="img">
</div>
<div class="text">
<p><strong>Lorem ipsum dolor sit amet</strong>, consectetur adipiscing elit. Nunc molestie, nibh eu molestie vestibulum, urna neque interdum orci, ut egestas diam massa vel magna. Mauris eget nunc nec sem ultrices varius.</p>
</div>
</div>
<div class="first">
<div class="img">
<img src="http://www.fogosglobo.com.br/img/250x250-circle.png" alt="img">
</div>
<div class="text">
<p><strong>Lorem ipsum dolor sit amet</strong>, consectetur adipiscing elit. Nunc molestie, nibh eu molestie vestibulum, urna neque interdum orci, ut egestas diam massa vel magna. Mauris eget nunc nec sem ultrices varius.</p>
</div>
</div>
</div>

How to clear float only in curent div?

I have the followin g HTML:
<div class="wrapper">
<div class="left-block">
<p>
some text
</p>
</div>
<div class="right-block">
<p>
some text
</p>
<div class="some-block">654</div>
<div class="some-block">132</div>
<div class="some-block">987</div>
<div class="clear"></div>
<div class="regular-block">10002</div>
</div>
</div>
blocks with class left-block and some-block have property float:left
This looks like http://jsfiddle.net/5k5v67jj/
block with class clear has clear:left;
How can I make block regular-block to like on this screenshot:
You have to contain the float and the clear in a block formatting context. To set up such a context, a common practice is to use overflow:auto or overflow:hidden. You'd add this to the styling of the div with the "right-block" class.
See http://jsfiddle.net/5k5v67jj/1/
I would change .some-block from float:left; to display:inline;. That way, a standard div like .regular-block will automatically show underneath and you don't need a clear between them.
Then you can put the clear div at the bottom to fix the block heights:
.wrapper{
border: 1px solid brown;
}
.left-block{
float:left;
width:100px;
padding:5px;
border: 1px solid red;
}
.right-block{
margin-left: 112px;
border: 1px solid green;
padding:5px;
padding-bottom:0;
}
.some-block{
display:inline;
border: 1px solid yellow;
}
.regular-block{
margin-top:10px;
border: 1px solid violet;
}
.clear{
clear:left;
}
<div class="wrapper">
<div class="left-block">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tristique, lorem dapibus tristique rhoncus, justo erat volutpat erat, in malesuada enim libero quis metus. Nunc tristique maximus efficitur. Sed nec dolor ut quam consequat molestie id quis justo.
</p>
</div>
<div class="right-block">
<p>
Nunc a lectus enim. Quisque sit amet iaculis turpis, a auctor tortor. Mauris aliquet sapien non odio tempor, auctor gravida nunc commodo. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec elementum eu tellus vel volutpat. Cras sed neque egestas, ullamcorper purus id, viverra odio. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Fusce et malesuada est, et bibendum lectus.
</p>
<div class="some-block">654</div>
<div class="some-block">132</div>
<div class="some-block">987</div>
<div class="regular-block">10002</div>
<div class="clear"></div>
</div>
</div