I know a solution to create equal height columns using display:table like:
.row {
display: table;
width: 100%;
}
.col{
display: table-cell;
}
but my case is a bit different, since I am using flexbox and row class has display:flex:
.row {
display: flex;
display: ms-flex;
flex-wrap: wrap;
}
and all cols have .large-4 class:
.large-4 {
width: 25%;
max-width: 25%;
flex: 0 0 30%;
}
I can't use flex:1 for .large-4 as well because it varies in different viewport.
here is a snippet of html:
<div class="row">
<div class="large-4">
<div class="card">
<img src="https://picsum.photos/200/200" alt="author">
<div class="card-content">
<h1 class="card-title">Title</h1>
<p class="grey-text mgb-05">2012-09-05, by Basir Payenda</p>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Repudiandae quas eligendi id est iste
distinctio
optio vel aliquam provident, ipsa reprehenderit in corrupti quia ratione quisquam amet veniam totam
veritatis.
</p>
</div>
</div>
</div>
<div class="large-4">
<div class="card">
<img src="https://picsum.photos/200/200" alt="author">
<div class="card-content">
<h1 class="card-title">Title</h1>
<p class="grey-text mgb-0">2012-09-05, by Basir Payenda</p>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit.
</p>
</div>
</div>
</div>
<div class="large-4">
<div class="card">
<img src="https://picsum.photos/200/200" alt="author">
<div class="card-content">
<h1 class="card-title">Title</h1>
<p class="grey-text mgb-05">2012-09-05, by Basir Payenda</p>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Repudiandae quas eligendi id est iste
distinctio.
</p>
</div>
</div>
</div>
</div>
code-pen link can be found here! how to I acheive equal height columns using flexbox? or any other better solution. thanks
You need to add display: flex to the .large-4 element:
.large-4 {
width: 25%;
max-width: 25%;
flex: 0 0 30%;
display: flex;
}
You'll notice when you inspect your elements using the inspector tool, large-4 elements are actually all the same height. It's the content inside that is not. So by making the parent element flex, it will make the children elements fill the space.
You already have equal-height columns, but inside them is a container that is contracting to its content. Expand that container.
.card {
height: 100%;
}
Related
I was watching a video that used align items and justify center to put a div on top of the page
why is it only at the top not at in the middle of the page?
.wrapper {
display: flex;
width: 100%;
justify-content: center;
align-items: center;
padding: 0 10%;
overflow: hidden;
height: 100%;
}
<div class="wrapper">
<div class="cols cols0">
<span class="topline">Hello</span>
<h1> I'm <span class="multiText">Coder</span></h1>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Possimus, sed nam quia autem voluptatum quae omnis maiores dolorem hic dolores sint quisquam a. Eaque expedita laborum debitis, dolores fugit assumenda!</p>
<div class="btns"> <button> download CV</button>
<button> hire me</button>
</div>
</div>
<div class="cols cols0"></div>
</div>
The issue is that height: 100% means 100% of the parent's height. The parent's height however is by default set to fit-content means the height is undefined. 100% of undefined is also undefined!
In order to vertically center content within an element, the height of the element must be higher than the content itself!
The simple solution is to give it a min-height of 100vh (the height of your content frame within the browser.
To remove the default vertical scrollbar you have to reset the default body margin and set the box-sizing of the element to border-box as otherwise, the padding will add height on top.
/* need to add this body reset + min-height */
body {
margin: 0;
}
.wrapper {
min-height: 100vh;
box-sizing: border-box;
}
/* original css */
.wrapper {
display: flex;
width: 100%;
justify-content: center;
align-items: center;
padding: 0 10%;
overflow: hidden;
height: 100%;
}
<div class="wrapper">
<div class="cols cols0">
<span class="topline">Hello</span>
<h1> I'm <span class="multiText">Coder</span></h1>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Possimus, sed nam quia autem voluptatum quae omnis maiores dolorem hic dolores sint quisquam a. Eaque expedita laborum debitis, dolores fugit assumenda!</p>
<div class="btns"> <button> download CV</button>
<button> hire me</button>
</div>
</div>
<div class="cols cols0"></div>
</div>
The .wrapper div is not spread over the full height.
You can set its height to 100vh
try to remove second block
<div class="cols cols0"></div>
I am learning CSS screen layout, and I want to use flex to change the display order of an element. I
have found some tutorials on the Internet and still don't know how to write it, so I can simply change the second , change the display order from left to right?
ul{
display: flex;
flex-direction:column;
width: 300px;
}
<ul>
<li>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Maiores doloribus dolor ipsum odit beatae voluptates culpa. Doloremque veniam labore pariatur!</p>
</li>
<li>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Maiores doloribus dolor ipsum odit beatae voluptates culpa. Doloremque veniam labore pariatur!</p>
</li>
<li>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Maiores doloribus dolor ipsum odit beatae voluptates culpa. Doloremque veniam labore pariatur!</p>
</li>
</ul>
if you looking for something like that
.flexed {
width: 400px;
height: 400px;
border: 1px solid #c3c3c3;
display: flex;
align-items: flex-start;
justify-content: center;
height: 50px;
}
.flexed div {
width: 50px;
height: 50px;
}
.reversed{
flex-direction: row-reverse;
}
<div style="text-align:center"> <h4>Without riversed row</h4> </div>
<div class="flexed" >
<div style="background-color:red;">1</div>
<div style="background-color:pink;">2</div>
<div style="background-color:orange;">3</div>
<div style="background-color:lightblue;">4</div>
</div>
<div style="text-align:center"> <h4>With riversed row</h4> </div>
<div class="flexed reversed" >
<div style="background-color:red;">1</div>
<div style="background-color:pink;">2</div>
<div style="background-color:orange;">3</div>
<div style="background-color:lightblue;">4</div>
</div>
<div style="text-align:center"> <h4>With 2 only riversed row</h4> </div>
<div class="flexed " >
<div style="background-color:red;">1</div>
<div class="flexed reversed">
<div style="background-color:pink;">2</div>
<div style="background-color:orange;">3</div>
</div>
<div style="background-color:lightblue;">4</div>
</div>
The actual letters right to left is easily accomplished with the <bdo> element. Just wrap the text in a <bdo> and add the dir attribute and the value of "rtl".
<bdo dir='rtl'>Text to reverse</bdo>
The text is changed from Latin to English to clearly demonstrate the reversed text.
ul{
display: flex;
flex-direction:column;
width: 300px;
}
<ul>
<li>
<p>Did you know that more frozen bananas are sold right here on this boardwalk than anywhere in the OC? You burn down the storage unit? Oh, most definitely. What a fun, sexy time for you.</p>
</li>
<li>
<p><bdo dir='rtl'>Did you know that more frozen bananas are sold right here on this boardwalk than anywhere in the OC? You burn down the storage unit? Oh, most definitely. What a fun, sexy time for you.</bdo></p>
</li>
<li>
<p>Did you know that more frozen bananas are sold right here on this boardwalk than anywhere in the OC? You burn down the storage unit? Oh, most definitely. What a fun, sexy time for you.</p>
</li>
</ul>
I have tried every solution I could find on the web on this subject. I have come to the conclusion that the problem may be that my page contains a scroll-snap-type.
scroll-snap-type: y mandatory;
scroll-behavior: smooth;
This is an overview of the div that I would like to scroll horizontally.
<section id="work">
<h2>WORK</h2>
<div id="carrousel">
<div class==="carr"><img src="./medias/projet1.png" alt="">
<h3>Lorem Ipsum</h3>
<h4>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Velit rerum voluptas iusto ipsam officiis
earum atque unde nesciunt provident ullam rem ea tempore.</h4>
</div>
<div class="carr"><img src="./medias/projet1.png" alt="">
<h3>Lorem Ipsum</h3>
<h4>Lorem Ipsum<h4>
</div>
<div class="carr"><img src="./medias/projet1.png" alt="">
<h3>Lorem Ipsum</h3>
<h4>Lorem Ipsum</h4>
</div>
<div class="carr"><img src="./medias/projet1.png" alt="">
<h3>Lorem Ipsum</h3>
<h4>Lorem Ipsum</h4>
</div>
</div>
</section>
#carrousel {
display: flex;
flex-direction: row;
height: 70vh;
width: 100vw;
}
#work {
background-color: #0F0F0F;
color: white;
display: flex;
flex-flow: column;
justify-content: center;
}
If I understand you correctly, to fix your issue, you can simply in your CSS (stylesheet) type the following code:
#carrouse1 {
overflow-x: auto;
}
...and do the same thing if you have more than one
If you want to make another section be horizontally scrolled, then just use the same CSS property on that too!
I have HTML structure like:
<div class="container">
<div class="btn-1"></div>
<div class="btn-2"></div>
<div class="btn-3"></div>
<div class="text">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. A veritatis harum illum assumenda odio ut, quos, ipsam molestias et sint nemo, saepe! Soluta a, quasi sequi, ut corrupti eius molestias.
</div>
</div>
btn-1 should be aligned to the top left, all other buttons (btn-2, btn-3...) should be aligned to the top right.
The text after all these buttons should be 100% width.
Quick mockup:
I figured out the first part (buttons) with:
.container {
display: flex;
justify-content: flex-end;
}
.btn-1 {
/* align first button to the left */
margin-right: auto;
}
Bu not matter what I do, the text doesn't flow to the next line...
Here's my JSFiddle https://jsfiddle.net/an0o7taq/
Thanks for any help!
You need to add flex-wrap: wrap to the container.
By default, flex containers are set to flex-wrap: nowrap, forcing items to remain on a single line.
revised jsfiddle
Spec reference:
5.2. Flex Line Wrapping: the flex-wrap property
You need more container with different flex flows and styles. Tip: learn most important flex props: align-items, flex-flow, justify-content. They all apply to the direct children of the container. So when you want your layout you need more container with different flex flows.
This guide helped me a lot. They also have great examples:
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
.container {
display: flex;
flex-flow: column nowrap;
}
.header {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
}
.header-left, .header-right {
display: flex;
flex-flow: row nowrap;
}
.btn {
width: 40px;
height: 40px;
border: 1px solid #ddd;
background-color: #eee;
}
.text {
width: 100%;
}
<div class="container">
<div class="header">
<div class="header-left">
<div class="btn">btn1</div>
</div>
<div class="header-right">
<div class="btn">btn2</div>
<div class="btn">btn3</div>
</div>
</div>
<div class="text">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. A veritatis harum illum assumenda odio ut, quos, ipsam molestias et sint nemo, saepe! Soluta a, quasi sequi, ut corrupti eius molestias.
</div>
</div>
I want to make sure the image and the text in the columns are aligned to the bottom of the image and the top of the text. Does anybody know how to achieve this without explicitly setting the height of .c-grid__content to 200px?
Right now I'm using flexbox. Maybe css-grid is the answer?
Please take a look at this codepen: https://codepen.io/simoncoudeville/pen/VMZmVa?editors=1100#0.
p {
margin-bottom: 10px;
font-family: sans-serif;
}
img {
max-width: 100%;
margin-bottom: 10px;
}
.c-grid {
padding: 40px 20px;
display: flex;
}
.c-grid__item {
flex-basis: 100%;
margin: 0 20px;
display: flex;
flex-wrap: wrap;
flex-direction: column;
justify-content: flex-end;
}
.c-grid__picture {
width: 100%;
}
.c-grid__content {
display: flex;
flex-direction: column;
}
<div class="c-grid">
<article class="c-grid__item">
<div class="c-grid__picture">
<img src="http://via.placeholder.com/400x200">
</div>
<div class="c-grid__content">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolore ratione commodi corrupti itaque sed architecto!</p>
</div>
</article>
<article class="c-grid__item">
<div class="c-grid__picture">
<img src="http://via.placeholder.com/400x600">
</div>
<div class="c-grid__content">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolore ratione commodi corrupti itaque sed architecto! Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
</div>
</article>
<article class="c-grid__item">
<div class="c-grid__picture">
<img src="http://via.placeholder.com/400x400">
</div>
<div class="c-grid__content">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolore ratione commodi corrupti itaque sed architecto! </p>
</div>
</article>
</div>
Align-items: baseline on the flexbox container seems to do the trick in this case. See the solution here: https://codepen.io/simoncoudeville/pen/yzOvmN?editors=1100
Looking at your codepen, this doesn't appear to require responsive design. If I am correct in that assumption, why not use a table that separates the images and text by rows, vertically aligning the top row at the bottom and the bottom row at the top?
It would limit the important CSS to just a few lines:
.c-grid__picture {
vertical-align: baseline;
}
.c-grid__content {
vertical-align: top;
}
Here is an example in JSFiddle
I was able to achieve this setting the flex-basis of the .c-grid__content to 0.
.c-grid__content {
...
flex-basis: 0;
}
https://codepen.io/antibland/pen/WZrXpw?editors=1100