I have to display some item card. Each card has min-width property. When my screen size change, card size also changed. Because of that, I am facing a problem. That is, the last item/items takes whole area. Is it possible to keep a minimum width for each card, though it is last item or not? Please help.
Problem:
Attempt:
Please find in codesandbox: https://codesandbox.io/s/multiple-items-arrange-926fx
It sounds like you also want to specify a max-width for your cards.
In your example it could simply be:
const Container = styled.div`
flex: 1;
margin: 5px;
max-width: 300px;
min-width: 280px;
height: 300px;
display: flex;
align-items: center;
justify-content: center;
background-color: #f5fbfd;
position: relative;
&:hover ${Info} {
opacity: 1;
}
`;
You can of course also leave max-width: 280px if you don't wish to change the width of the elements at all.
Additionally you can add justify-content: flex-start to the container to make it look less weird on resizes. In your example:
const Container = styled.div`
padding: 20px;
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
`;
Related
I'm using vertical full screen Swiper and ran into a problem. Due to content overflow for slide, I set flex-wrap: wrap and overflow: scroll so that this content can be viewed. But when I try to scroll the contents of the slide, the swipe scroll to the next one works at the same time. How to disable switching to the next slide until the previous one has scrolled completely?
MainSlider.js
<Swiper
className={styles.swiper}
direction={"vertical"}
slidesPerView={"auto"}
spaceBetween={0}
mousewheel={true}
speed={700}
touchReleaseOnEdges={true}
threshold={20}
pagination={{
clickable: true,
}}
>
<SwiperSlide className={styles.slide}>
<SectionOne/>
</SwiperSlide>
<SwiperSlide className={styles.slide}>
<AnswersTwo/>
</SwiperSlide>
</Swiper>
MainSlider.module.scss
.swiper {
width: 100%;
height: 100vh;
}
.slide {
min-height: 100vh;
text-align: center;
font-size: 18px;
background: #fff;
display: flex;
justify-content: center;
align-items: center;
margin: auto;
overflow: hidden;
#media only screen and (max-width: 1023px) {
flex-wrap: wrap;
overflow: scroll;
}
Added a link to a similar example.
https://codesandbox.io/s/swiper-mousewheel-control-react-forked-c97l1q
Please note that if you display the code in full screen and then turn on the mobile version, the mouse wheel will work, but scrolling inside the container will also work, but with swipe you will not be able to flip the slide until you reload the page. After that, swipe will work, but there will be a problem that I wrote about at the very beginning. The woman needs to solve them both
Is it possible to make flex-wrap wrap after the last row overflows without vertical scroll like it is possible horizontally?
My CSS currently looks like this:
.flex-container {
height: calc(100% - 0.125rem);
display: flex;
flex-direction: column;
flex-wrap: wrap;
align-content: flex-start;
overflow: hidden;
align-items: center;
}
.item {
width: 6.25rem;
height: 6.25rem;
margin: 1px 0 0 1px;
font-size: 2.25rem;
line-height: 6.25rem;
background-color: rgb(225, 225, 225);
}
My output looks like this (flex wraps and empty space below)
What I am trying to achieve looks like this
If I understand your question right, I think the challenge you have is with the height property of the .flex-container class.
height: calc(100% - 0.125rem) will leave an offset(gap) since the height of .item 6.25rem > 0.125rem.
For the height of .flex-container try height: calc(100% - 6.25rem) instead, or tweak the height property until you get your desired output.
Note that the flex-wrap property only specifies if the flex items should stay on one line or can wrap onto multiple lines, which you already have specified. And with the overflow property set to hidden, you should not have any challenges with scrolls.
I cant get this too work. Im using react and styled components and my justify/aligning isnt working.
div - set to flex, flex-direction is column
div - header div
div - body div, flex grow set to 1 so that the flexbox takes up the full height of the container
Now the flex item for the body takes up the full height (good) and im trying to center the content in the middle of this div. I have tried all combinations of align/justify on both the parent and body div but it doesnt work and im not sure why.
Heres my code
const Div = styled.div`
display: flex;
flex-direction: column;
min-height: 100vh;
justify-items: center;
& > * :nth-child(2){
flex-grow: 1;
background-color: red;
/* position:relative; */
/* align-self: center; */
}
`
const OuterWrapper = styled.div`
padding: 10vw 1.5rem;
overflow: hidden;
// this is the div that contains content that i want to center
Can anyone see why its not working?
On your wrapper:
display: flex;
justify-content: center;
align-items: center;
I have an array of objects I'm mapping over to make a grid of time blocks. Each block represents 10 minutes so 12:00 - 12:10, 12:10 - 12:20, etc...
Right now I'm using a grid to make the blocks go horizontally across the screen and wrap back down.
const GridLayout = styled.div`
display: grid;
grid-template-columns: repeat(6, 2fr);
justify-content: center;
grid-gap: 0;
margin: 0 auto;
width: 16rem;
`;
I want to get it so my blocks are laid out vertically with 12:00am in the bottom left corner and the times moving in an upwards direction like so:
I can do this by adding a -webkit-transform: rotate(270deg); to the GridLayout however I prefer to achieve this without having to rotate the entire grid if I can. Is there a way to use the css-grid rows/columns to achieve this view?
I achieved this by removing the display: grid and instead making the div display: flex.
My final styled component looks like this:
const Wrapper = FlexColumn.extend`
flex-wrap: wrap;
flex-flow: column wrap;
align-content: stretch;
max-height: 13rem;
width: 48rem;
align-items: flex-start;
justify-content: center;
`;
I am using Flexbox for a series of content blocks. The idea is to have blocks in a flex container whose height will be determined by the total of the flex items within it. This is working well on Chrome and Safari as it calculates the container height automatically and correctly, but the same does not happen on Firefox + IE. My CSS looks like this:
.container {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-flow: row wrap;
-ms-flex-flow: row wrap;
flex-flow: row wrap;
-webkit-box-pack: justify;
-webkit-justify-content: space-between;
-ms-flex-pack: justify;
justify-content: space-between;
.primary {
position: relative;
background-size: contain;
background-repeat: no-repeat;
width: 100%;
height: 0;
padding-top: 56.25%;
margin-bottom: 10px;
-webkit-box-flex: 1;
-webkit-flex: 1 0 100%;
-ms-flex: 1 0 100%;
flex: 1 0 100%;
}
.secondary {
position: relative;
background-size: contain;
background-repeat: no-repeat;
width: 100%;
height: 0;
padding-top: 28.10026385%;
flex: 2 1 40%;
margin-left: 10px;
}
}
Essentially, the padding-top: 28.1% decoration is for a background image set as an inline style. On chrome + safari, this calculates the height just fine. However, the container's height is not set up on IE + FF. I have tested all my browser prefixes and checked a lot of questions, but I'm a bit lost on why the height is calculated differently. If anyone has any suggestions that would be excellent. Setting a min-height on the blocks is not an option, as we will have varying sizes of blocks, so we don't want to constrain ourselves to a fixed or min height.
Short version: is there a difference in how Firefox + IE calculate height of flex containers and items? If so, what is the best way to get it to behave like Safari + chrome?
Here is a contrived example: http://codepen.io/anon/pen/NGjYGR
I'm noticing a few potential issues with the code you're referencing. Also, without full context of the referenced code—missing HTML—recommendations are based on the assumption that your HTML is structured in the following manner:
.container
.primary
.secondary
No height set on .container
If dimensions aren't set on this element how are the dimensions calculated for the children elements (i.e.: "28.1%" of ?) ?
There are many known issues with certain browser implementations of the flex specification
There are known issues with implementations flex-basis, and height calculations. Here is a comprehensive article on browser nuances on flex: here.
References:
Normalizing Cross-browser Flexbox Bugs:
http://philipwalton.com/articles/normalizing-cross-browser-flexbox-bugs/