Width does not have a [max] value
"A div is a block-level element that always starts on a new line and takes up the full width available (stretches out to the left and right as far as it can)." w3schools.com
Hence the reason for the line crossing the screen.
I'm not sure why, but when you change the position of the element to fixed, the width is set to how much the element needs. But setting the width to 100% should solve your problem