- This topic is empty.
-
AuthorPosts
-
April 10, 2015 at 6:51 am #200141ShaggyParticipant
As you can see from this Fiddle, an absolutely positioned, columnar flexbox won’t expand to fit its children.
In Chrome, for example, it will only be as wide as the widest child element and as tall as the shortest column.
Can anyone suggest a solution without using any additional markup?
April 10, 2015 at 7:51 am #200142Paulie_DMemberI’m curious..why would you absolutely position a flexbox item?
April 10, 2015 at 8:31 am #200146ShaggyParticipantIt’s a dropdown menu.
April 10, 2015 at 8:36 am #200151Paulie_DMemberIt’s not clear to me what you are trying to do.
How is this supposed to look?
April 10, 2015 at 8:59 am #200154ShaggyParticipantAs you can see in this Fiddle, the ul is nested in an li and positioned off-screen with a negative left value. The :hover state of the parent li sets the left value of the flexed ul to 0. Pretty standard stuff.
The submenus have the potential to contain many items so, to ensure they don’t drop off the end of the screen, I need to break to a new column after a set number of items.
April 10, 2015 at 9:12 am #200158Paulie_DMemberI’m pretty sure that
display:flex
andposition:absolute
are incompatible in this respect.It works slightly better if you make the height a fixed value rather than
max-height
.April 13, 2015 at 2:13 am #200312ShaggyParticipantThanks, Paulie. The problem with setting a specific height is that some menus will have less than 6 items in them so that solution would create too “white space” in those instances.
Currently, I’m using CSS columns until I can solve this flexbox issue but they’re creating a few problems of their own:
- I have to specify the exact number of columns I want, rather than allowing the menus to break as necessary.
-
The menus will always spread across that number of columns, regardless of how many items there are in each.
-
All columns are as wide as the longest item in each menu.
Now, admittedly, I haven’t worked much with columns so I may well be overlooking something that would give me the same results I’m trying to achieve with the flexbox.
April 13, 2015 at 2:47 am #200313Paulie_DMemberAs always, a Codepen Demo would be useful.
April 13, 2015 at 7:03 am #200332ShaggyParticipantFor the columns, you mean? Here’s a Fiddle: http://jsfiddle.net/fndroeee/
That one primarily illustrates the problem of both columns being the width of line 8 but you can see the other problems I’m having by adding or removing items, the list will no longer break to a new column after every 6th item.
April 14, 2015 at 1:09 pm #200460genaParticipantHave you considered using position-relative + top & display:none
Then change to display: block on hover?I would think that would work with flexbox.
.parent ul {
display: none;
position: relative;
top: height of parent element;
}
.parent:hover ul {
display: none;
}April 15, 2015 at 1:58 am #200489ShaggyParticipantUnfortunately not, gena; setting the display property to “block” would overwrite the “flex” value.
June 23, 2016 at 8:28 am #243075matfish2ParticipantHad the same problem but with a one column dropdown. Solved by applying
width:100%
to the dropdown ul.December 14, 2016 at 6:00 am #248982madhurgargParticipantIf you want to give display:flex to absolutely positioned element, then you have to set left:0, right:0 like this:
.parent { position: absolute; left: 0; right: 0; display: flex; }
This worked for me !
-
AuthorPosts
- The forum ‘CSS’ is closed to new topics and replies.