I am using Shopify theme, I am displaying four product in each row. Everything is working perfectly except product column height. I need the equal height of each column. I tried display: tablethe parent class and display:table-cell to child class but still not working. Also tried display:flex
I am sharing the link to code because of my code huge and not allowing me to upload here.
https://jsfiddle.net/a8ag2270/1/
I am getting the output. I need equal height.
Okey, that's the best I can do for now.
https://jsfiddle.net/a8ag2270/49/
.grid.grid--uniform.grid--view-items {
display: flex;
flex-wrap: wrap;
}
/* had to target more specifically with (div.grid-view-item) */
/* so the margin: 0px auto 35px; gets overridden */
div.grid-view-item {
display: flex;
flex-direction: column;
height: 100%;
margin: 0; /* instead of margin: 0px auto 35px; */
}
.grid-view-item__link.grid-view-item__image-container {
display: flex;
flex-direction: column;
flex: 1;
}
/* same story here */
div.grid-view-item__meta {
margin-top: auto; /* override margin-top: 8px; */
}
It can probably be done with a lot fewer styles (or maybe not), but I like flexboxes and working with them, so I used that.
What you need to do on your own is to set min-height to title, description etc. if you want them to be "aligned horizontally" (can't find the right words for that) with each other.
The above styles put the price down, right above the button. If you don't want that behaviour, you can use this:
.grid.grid--uniform.grid--view-items {
display: flex;
flex-wrap: wrap;
}
div.grid-view-item {
display: flex;
flex-direction: column;
height: 100%;
margin: 0;
}
.grid-view-item__link.grid-view-item__image-container {
flex: 1;
}
or this:
.grid.grid--uniform.grid--view-items {
display: flex;
flex-wrap: wrap;
}
.grid__item {
display: flex;
}
div.grid-view-item {
display: flex;
flex-direction: column;
}
.grid-view-item__link.grid-view-item__image-container {
flex: 1;
}
add Below code in your css file:
#Collection > .grid--view-items
{
display: flex;
flex-flow: row wrap;
}
#Collection .grid__item
{
display: flex;
}
#Collection .grid-view-item
{
display: flex;
flex-direction: column;
}
#Collection a.grid-view-item__link.grid-view-item__image-container
{ flex: 1 0 0; }
Just add a style to the grid-view-item__link like
.grid-view-item__link{
height:400px;
}
Change the 400 to whatever height you want.
Here is the fiddle
Related
Prerequisites
It is not possible to place .header_nav-li_bicycle to the right inside a .header_wrapper.
Expected value
Place .header__nav-li_bicycle to the right inside a .header_wrapper
Reproduction procedure
Run the code bellow, please.
<div class="header__wrapper">
<img class="header__profile-icon" src="image/logo.svg" alt="プロフィール">
<nav class="header__nav">
<ul>
<li class="header__nav-li">About</li>
<li class="header__nav-li_bicycle">Bicycle</li>
</ul>
</nav>
</div>
.header {
/* omitted */
.header__wrapper {
display: flex;
align-items: center;
padding: 0px 76.1094px;
margin: 0px 471.5px;
gap: 30vw;
img {
justify-content: space-between;
width: 120px;
height:40px;
}
nav {
justify-content: space-between;
width: 149.39px;
ul {
display: flex;
.header__nav-li {
height: 21px;
display: flex;
justify-content: flex-end;
.header__nav-link {
/* Omitted */
}
}
.header__nav-li_bicycle {
height: 21px;
display: flex;
justify-content: flex-end;
.header__nav-link_bicycle {
/* Omitted */
}
}
}
}
}
}
Those Classes 😵
Okay so, after spending 5 minutes to understand what's going on cuz of those lengthy classNames. ( Yes, I wrote ClassNames on purpose cuz I got a fetish for React. )
The pen for the following example: https://codepen.io/devshot-dotcom/pen/wvrPZZm
Now, lemme tell you something, mate, there're some real issues going on here, let's solve them one after the other.
The header:-
Why do you need this class, when you can use the HTML header element to do the exact same thing? Now the header (previously .header__wrapper) needs some CSS, here's all you need to vertically align and push the children to opposite edges:
header {
display: flex;
align-items: center;
justify-content: space-between;
/* Continue with padding or margin or whatever. */
}
The Image:-
For the image, all you need is the width and height:
img {
width: 120px;
height: 40px;
}
The nav:-
For the nav, consider assigning a single rule:
nav {
flex-grow: 1;
/* Will make it fill the remaining space of the header. */
}
The list:-
Now, the ul needs to replicate the exact styles of the header, i.e To become a flexbox and vertically align its children, hence:
nav ul {
display: flex;
align-items: center;
}
Actual Problem:-
To make the .bicycle stick to the very right:
nav ul {
display: flex;
align-items: center;
justify-content: space-between
}
To make both of the list items stick to the right:
nav ul {
display: flex;
align-items: center;
justify-content: flex-end
}
This will solve (hopefully) all the problems.
Tips & Tricks
When you're using SASS, the BEM naming convention is quite an overkill. Instead, assign a class to the very parent of a block, say .stick-man and then nest all the children as they're nested in the HTML, and you'll save yourself a ton of time and headache. (Yes, naming the classes is a headache.)
I'm currently doing some stuff with Flex Box and I'd like my flex box to stretch but I can't do it. Here is my codepen : https://codepen.io/chevalierv/pen/bGdBKyg
.FlexContainer {
height: 65vh;
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: stretch;
align-content: stretch;
justify-content: center;
padding: 1em;
background-color: red;
}
.SecondChildContainer {
align-self: flex-end;
order: 2;
flex: 1;
flex-basis: 100%;
background-color: green;
}
.FirstChildContainer {
order: 1;
flex-grow: 5;
align-self: stretch;
background-color: blue;
}
<div class="FlexContainer">
<div class="FirstChildContainer">
a
</div>
<div class="SecondChildContainer">
a
</div>
</div>
I have cleaned your css a little bit and made it work. See the jsfiddle below:
https://jsfiddle.net/gqptemhu/
Basically, what your flex container needs is
.FlexContainer {
height: 65vh;
display: flex;
flex-direction: column;
}
so it knows to stack the items vertically.
And you use
flex: 0 1;
flex: 1 0;
On the items inside of the flex container, to tell which item will grow, and which one will shrink. The first number corresponds to flex-grow, and the second to flex-shrink. They are both relative numbers which tell which percentage of space the items will grow/shrink to.
You can read more about flexbox and how to use it on the link below:
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
I've successfully created a list using the following answer with flexbox on my HTML page How to display 3 items per row in flexbox?
I have a need to create a PDF with this data and I'm using wkhtmltopdf (https://wkhtmltopdf.org/) which also works fine however the PDF generated has all my List Items in 1 long column instead of 3 per row.
Looks like the CSS is not being processed when the PDF generation is happening any insight is appreciated.
This worked for me :
.row {
display: -webkit-box; /* wkhtmltopdf uses this one */
display: flex;
-webkit-box-pack: center; /* wkhtmltopdf uses this one */
justify-content: center;
}
.row > div {
-webkit-box-flex: 1;
-webkit-flex: 1;
flex: 1;
}
.row > div:last-child {
margin-right: 0;
}
See https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1522 for more informations.
I resolved this issue using:
equivalent of display:flex; ==> display: -webkit-box;
equivalent of justify-content: space-between; ==> -webkit-box-pack: justify;
Some useful informations coming from:
https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1522
I used autoprefixer in my application to automatically add prefixes. You just need to update browsersList with ie >= 9.
Try to decrease the width of the flex columns. For example when I tried to make 50/50 columns I had to put a width of 49.8% instead of 50%. Hope it helps.
To use flex or boxes while converting to pdf, You need webkit
Example:-
display: flex;
display: -webkit-flex;
for justify-content and align items you have to use
-webkit-align-self: flex-end;
align-self: flex-end;
webkit-justify-content: space-between;
justify-content: space-between;
As fix for Bootstrap 5, working with wkhtmltopdf 0.12.*, I found and completed the following style
<style>
/* Fix wkhtmltopdf compatibility with BS flex features */
.row {
display: -webkit-box;
display: flex;
-webkit-box-pack: center;
justify-content: center;
}
.row>div {
-webkit-box-flex: 1;
-webkit-flex: 1;
flex: 1;
}
.row>div:last-child {
margin-right: 0;
}
/* Fix wkhtmltopdf compatibility with BS tables borders */
/* Requires cellspacing="0" on table to prevent spacing */
table {
border-collapse: separate !important;
}
th,
td {
border-top: none;
border-left: none;
border-right: none;
}
</style>
source saved my day while upgrading from bs 4 to bs 5.
This worked for me:
.row {
white-space: nowrap;
> div {
display: inline-block;
white-space: normal;
}
}
I have a container that uses flex-direction: row and I would like to keep it that way the only problem is that now I want to put something under a div without having to nest it in.
This is what I have.
And I would like to do something like this:
My main_continer css looks something like this:
main_container {
display: flex;
width: 100%;
height: 100%;
align-items: center;
justify-content: center;
flex-direction: row;
border: 1px solid #DDDDDD;
border-bottom: 1px solid #DDDDDD;
text-align: left;
.div_2 {
width: 90%;
}
Is it possible to override flex direction row some way?
Add the ability for the flex items to wrap:
.main_container {
// ...rest of styles
flex-wrap: wrap;
}
Then override the order for that second item, making it come after the fourth item:
.div_2 {
order: 4; // default is 0, you might need to play with this value
}
Last make sure the items layout 3 across, add some new class to all the items in the flex container so you can target them together:
.new_class_on_all_items {
width: 33.333%;
}
I am trying to use Flexbox to create a grid to output WordPress latest posts on my home page. But because the content within each box is different, the height of each box isn't equal, and that create issues. I tried using align-item=justify and a few other recommended options, but nothing seems to be working.
Here is the CSS I am using:
.home-latest-posts {
display: flex;
flex-wrap: wrap;
}
.home-latest-posts .post {
background: #fff none repeat scroll 0 0;
display: inline-flex;
flex-direction: column;
margin: 0;
width: 32%;
}
.home-latest-posts .post:nth-child(3n+2) {
margin-left: 2%;
margin-right: 2%;
}
.home-latest-posts .post .entry-title {
padding: 1em 3em 0.5em;
}
.home-latest-posts .post .entry-content {
padding: 0 3em 1em;
}
However, since there may be other codes that may be interfering, I'll link to the actual page so you guys can get the whole picture.
You can see the issue I am having at this test site (http://moneyrope.com/). It's the section under "Latest Money Tips".
Sorry about the mess. It's just a test site.
Add this part
.widget-wrap {
display: flex;
flex-wrap: wrap;
}
.home-latest-posts .post {
margin-bottom: 3rem;
}
Don't forget to prefix all your code. You should also consider wrapping it inside a min-width #media query