why "width" is not working while using position:fixed? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

why "width" is not working while using position:fixed?

change static into fixed then width will not work. why is this happening? what is the solution? https://code.sololearn.com/WRP2NYcV5nO5/?ref=app

13th Feb 2020, 7:03 AM
RH Tasin
RH Tasin - avatar
7 Answers
+ 2
Width does not have a [max] value https://www.w3schools.com/css/css_dimension.asp "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 https://code.sololearn.com/WbkyCc6j2WEY/#html
13th Feb 2020, 10:44 AM
ODLNT
ODLNT - avatar
+ 2
No problems, I'm glad I could help.
13th Feb 2020, 11:41 AM
ODLNT
ODLNT - avatar
+ 1
Try: position:relative;
13th Feb 2020, 7:07 AM
NightFox
NightFox - avatar
+ 1
Thanks bro, it has worked 😘
13th Feb 2020, 11:23 AM
RH Tasin
RH Tasin - avatar
0
Marzan It has worked, but I wanna fix it. I mean I don't want it to be scrolled. what to do? Gordon Fatima Tuz Johra
13th Feb 2020, 9:23 AM
RH Tasin
RH Tasin - avatar
0
Because it's position is fixed
14th Feb 2020, 9:27 AM
JAYANTHI SAI GOPAL
JAYANTHI SAI GOPAL - avatar
- 1
<html> <head> <style> .bo { padding:0;margin:0; height:1000px; } .po{background-color:red; height:50px; width:100%; border-bottom: 2px solid pink; position:fixed;top:0;} </style> </head> <body class="bo"> <div class="po"> <a href="link"><img src="image.jpg" width="15px" height="15px" alt="pho"></a> </div> </body> </html>
13th Feb 2020, 5:46 PM
Priya gupta
Priya gupta - avatar