How to declare `display:flex` inside an element with `popover` attribute ?

https://codepen.io/sougataghar47/pen/NPKBEmd I am trying to make an image slider which would navigate horizontally instead of vertically
16 Replies
Chris Bolson
Chris Bolsonā€¢4d ago
You can use display: flex in a popover element just as normal. Your codepen works fine if you declare flex and update the JS to slide horizontally rather than vertically.
i_lost_to_loba_kreygasm
if I declare display flex , it stays permanently open I don't want that i want it to stay open and close. I want it to have flex when it opens and none when it close i think js can do it but there must be some css state for popover
Chris Bolson
Chris Bolsonā€¢3d ago
Have you tried using the "popover-open" pseudo-class?
#gallery:popover-open{
display: flex;
}
#gallery:popover-open{
display: flex;
}
i_lost_to_loba_kreygasm
its gone for some reason šŸ˜¦
No description
i_lost_to_loba_kreygasm
nvm it doesnt work in firefox šŸ˜… , just opened it in chrome
Chris Bolson
Chris Bolsonā€¢3d ago
It works for me in Firefox
i_lost_to_loba_kreygasm
Do you have normal or developer edition ?
Chris Bolson
Chris Bolsonā€¢3d ago
normal. I am on mac though so it might be different to Windows (if that is what you are using) though I doubt it. I generaly develop on Firefox as I prefer the dev tools and also am generally sure that things will work cross-browser as it tends to lag behind Chromium browsers in terms of adapting newer CSS properties etc.
i_lost_to_loba_kreygasm
I am on windows , yeah and I prefer firefox too
i_lost_to_loba_kreygasm
btw any tips on how to make the image cover the full container?
No description
i_lost_to_loba_kreygasm
#gallery{
border:none;
height:100vh;
width:400px;
overflow:hidden;
transition:.3s ease-in;
}
#gallery:popover-open{
display: flex;
}
#gallery img{
height:100%;
max-width:100%;
transition:.3s ease-in;
}
#gallery{
border:none;
height:100vh;
width:400px;
overflow:hidden;
transition:.3s ease-in;
}
#gallery:popover-open{
display: flex;
}
#gallery img{
height:100%;
max-width:100%;
transition:.3s ease-in;
}
Chris Bolson
Chris Bolsonā€¢3d ago
This was my test. https://codepen.io/cbolson/pen/raBrEjz It is nothing more than a fork of your pen with the added popover-open and the change to the JS to give it horizontal scroll. Ah yes, I also added object-fit: cover on the images so that don't distort. Try adding flex-basis: 400px to the images (ie the same value as the container width)
i_lost_to_loba_kreygasm
ooh , forgot that would work . it works flawless now , thank you for your help šŸ«”
i_lost_to_loba_kreygasm
hi again ,i added more images and its glitchy like this , can you take a look ? https://codepen.io/sougataghar47/pen/NPKBEmd
No description
Chris Bolson
Chris Bolsonā€¢3d ago
To be honest I would probably use grid for this. By it's very nature, flex is not good at defining exact width contents, whereas this is one of grids (many) strong points. I would also place the gallery/images within a child container so that you don't have issues with the popover element. This child container would be the one that has the grid display etc rather than the main popover. A new fork of your current pen with these suggested changes. Finally, (note - I have not updated my fork of your pen with this), now that you have a child container, I would modify the JS to translate this from side to side as a unit rather than each image. This would mean less work/modifications in the DOM and reduce the possibility of miss-alignment.
i_lost_to_loba_kreygasm
gotcha and thanks again for helping me out , you can delete your fork , I have forked it šŸ™‚

Did you find this page helpful?