0

I have a div which requires scrollbar. I used style="overflow-y:auto" for my div. But if the scrollbar gets displayed, it is affecting the width of the content. Is there any way to maintain the width of the content, constant inspite the scrollbar getting displayed or not. Also I can't set the width of the div in pixel, since my application must be compatible for all screen size.

lalithkumar
  • 3,480
  • 4
  • 24
  • 40

2 Answers2

1

The element's content width includes the width of scrollbar.

So sorry to disappoint you, but this behavior can not be changed.

Kiran Dash
  • 4,816
  • 12
  • 53
  • 84
0

Even though you haven't shared much details on your specific case, this could probably be solved by using JavaScript/jQuery, as explained here in various forms:

How can I check if a scrollbar is visible?

LoDef
  • 5
  • 3
  • I don't want the scrollbar's presence to affect the width of my div. so whether the scrollbar is present or not inside my div, its width should be constant. right now if scrollbar appears it is decreasing the width of the div. – Solai Kannan Jun 02 '17 at 05:11
  • That's why you need to use Javascript to detect weather the inner content has a bigger height than the container, and then change the width dynamically. See the link I posted above. – LoDef Jun 02 '17 at 10:04