Styling : Gap between group of element #4459
-
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
TL-DR (this part written by ChatGPT, all else manually):
I don't want to jump to the solution. The discovery process was interesting in my opinion, and I also learnt something new today. First of all, tooling. DevTools Elements is your friend. Click on the first icon in the toolbar to allow you to hover over elements to see how they are laid out. ![]() We see that nobody wants to take up the space. It's like we have leftovers at dinner 🍝. ==> Now an obvious solution would be to apply flex-grow to any of the elements to take up the remaining space. This is because ![]() --> But, your intended solution may be to want to make the gap to be gone, and the other elements to shift to the right. Then we ask, why the row is so long, and so weird as well, 310.010 px. Let's check the width in the computed styles. Are anything explicitly setting the width to this weird value? Well, nope. Otherwise there's an arrow next to it, and you can click to see who cause it. ![]() Digging deeper, do you notice that the input has a width of 51.667? Do a bit of napkin math, and 310.010 / 51.667 = 6.000! ROOT CAUSE: input has w-1/6, so the row has 6 times the width of the input Analogy: Mom looks at first child and cooks 6x the food he can eat. But the two other children aren't hungry at all, and we have a food waste problem.🚮 ==> You may apply other absolute width Tailwind CSS classes. Assuming you like the current width, you can even use Find the code using the 2nd solution here: https://gist.github.com/evnchn/621d61ddb364b44b98dcc031a15cf8bc PS: I actually didn't know of this behaviour. Typically, I set the width of the outside element explicitly, and then use w-1/6 on inner elements. It's like mom is the controller and cooks XXXg of spaghetti today, divide 1/6 to a child always, not the other way round... |
Beta Was this translation helpful? Give feedback.
-
As @evnchn correctly analyzed, "w-1/6" seems to be the problem. What's your intention behind using this class, @chupins? def my_widget(name, value):
with ui.row(align_items='center'):
ui.input(label=name, value=value).props('dense').classes('w-40')
ui.switch(text='var', value=True).props('dense')
ui.button('Edit')
with ui.row():
my_widget('wid1', 'toto')
my_widget('wid2', 'tata') ![]() |
Beta Was this translation helpful? Give feedback.
As @evnchn correctly analyzed, "w-1/6" seems to be the problem. What's your intention behind using this class, @chupins?
Some fixed width might be better: