0

I have a help box component that can contain text and in its natural state is collapsed. Text overflow is hidden using text-overflow: ellipsis; When clicking on it, it expands and displays the whole text.

I cannot get it to work in a dynamically sized container. It works fine otherwise.

Please see the following JSFiddle where the code is reduced to its essentials: https://jsfiddle.net/gmbt76or/

The first helpbox is displayed correctly and is not wider than the display area. The second helpbox is inside the dynamically sized container and is not restricted in its width at all.

Can you please answer me what I have to do to get the second help box to behave like the first one? Naturally I cannot use any fixed widths.

Thank you very much in advance!

2 Answers 2

2

Adding min-width probably solves the problem:

.ui-g {
    display: flex;
    flex-wrap: wrap;
    box-sizing: border-box;
    
    min-width: 0px;   /* add ths */
}

.ui-g-12 {
    width: 100%;
    float: left;
    box-sizing: border-box;
    
    min-width:0px;    /* add this */
}

Only two lines to add to your OP code. https://jsfiddle.net/9aq34rt7/
Resize the browser window see it adjusts. Hope this solves the issue in actual code.


found a nice article explaining the issue: https://newbedev.com/css-text-overflow-ellipsis-not-working

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you very much for your answer. That works in the simplified example I posted but not in my real scenario. I guess I simplified too much. It's actually a two-column layout. I have updated the JSFiddle above. Can you please amend your answer? Thank you very much!
Thank you. Using the viewport dimensions means that the components are no longer relative to each other but relative to the viewport size. In a smaller window everything looks different than in a larger window. That's not really acceptable. Are you saying there is no other way to do it?
updated the answer. try resizing window in jsfiddle
Thank you, the min-width solves the problem as well! I was able to set it directly on the fieldset surrounding my help box and it works. I don't understand why, but it works. So thank you very much!
1

While viewing your code in JSfiddle, I just modified your .ui-g-12 class css

.ui-g-12 { width: 100%; }

to

.ui-g-12 { width: calc(100vw - 47px); }.

I hope it will fullfill your expectation.

Code: JSFiddle

Thanks.

1 Comment

Surprisingly this led me to the correct solution for me in my 2-column layout. Just setting the width of the help box directly (style="width: calc(50vw - 100px)") led to a good result which also stays the same when resizing the window. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.