default width in absolute positioned elements? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

default width in absolute positioned elements?

Why the default value in width in positioned elements is zero(normally block element take the whole width of its parents) ? div element is not displayed. because its width is zero. https://code.sololearn.com/W9OEbfTQ5BxK/?ref=app

6th Apr 2021, 8:50 PM
Mehran
Mehran - avatar
12 Answers
+ 3
Reboot Answered the question:absolute positioned elements removed from normal flow of document, so some behaviors like taking width of parent, no longer work.
7th Apr 2021, 10:35 AM
Mehran
Mehran - avatar
7th Apr 2021, 8:22 AM
Mehran
Mehran - avatar
+ 2
ممنون من هم دنبال همین نکته بودم و میخواستم ببینم واقعا اینجوریه یا نه.
7th Apr 2021, 10:25 AM
Mehran
Mehran - avatar
+ 1
https://code.sololearn.com/W9BT7pUPfjgo/?ref=app See, you didn't define width value so it doesn't have width, not that the width value be 0.
7th Apr 2021, 8:42 AM
Root
Root - avatar
+ 1
ببینید من حالتی رو میگم که width رو تو استایل تنظیم نکنیم. اگر شما امتحان کنید میبینید که در حالت معمولیstatic position عنصر دیو کل فضا رو اشغال میکنه اگر چه ما پهنا را تنظیم نکرده باشیم. ولی وقتی روی ابسلوت نیزاریمش پهنا اتوماتیک صفر میشه. چرا؟ معمولا چنین اتفاقاتی یه دلیلی تو قواعد css دارند.
7th Apr 2021, 9:28 AM
Mehran
Mehran - avatar
+ 1
بله اون قسمت اولی که میگید درسته، ولی نکته اینه که شما روی absolute که میذارین پهنا شما صفر نمیشه، چون absolute دیگه با مقدار طول و عرض کاری نداره، توی کد شما وقتی روی absolute میذارین، دیگه طول و عرض رو باید حتما براش تنظیم کنید وگرنه خروجی که بهتون میده میشه مثل خروجی کد خودتون که هیچ چیز رو نشون نمیده. Absolute تنها تاثیر بر روی مکان شی هست نه اندازه ولی static position بر روی همه جنبه های شی تاثیر میذاره. یه نگاهی به مقاله زیر بندازین : you can read this article to learn about positions in css and html embedded css code. https://www.w3schools.com/css/css_positioning.asp این موضوعات دلیلشون خاصیت خود absolute و بقیه انواع مکان هست، شما نمیتونی بگی چرا برف سفیده؟ چون خاصیتش سفید بودنه، سفیدی تو ذاتشه
7th Apr 2021, 9:40 AM
Root
Root - avatar
0
Mehran Raeesi Can you make it clear?
6th Apr 2021, 8:55 PM
Matias
Matias - avatar
0
ok delete comment
6th Apr 2021, 8:56 PM
Mehran
Mehran - avatar
0
Mehran Raeesi I see your code attempt so your question is why it is 0?
6th Apr 2021, 8:58 PM
Matias
Matias - avatar
0
yes why is it 0? He usually has to occupy its entire width of parent.
6th Apr 2021, 9:00 PM
Mehran
Mehran - avatar
0
Reboot Pay attention to my question. if we don't set position to absolute, it take width of its parent, but when it have absolute position, default width is zero. why this happen?
7th Apr 2021, 8:50 AM
Mehran
Mehran - avatar
0
Mehran Raeesi I got your question. Take a look at this part of code : <div style= "background-color:green; height:100px; width:100px; position:absolute;" > </div > Absolute value refers to **posiotion** SO WHAT happens then absolute just effects on position not the value of height and width. you can't say cause I defined absolute value for position the width or height is automatically 0. cause that doesn't effect this one. if didn't get just tell you this: مقدار absolute فقط بر روی position تاثیر میگذارد نه بر روی مقادیر height و width. ولی absolute بر روی مقادیر top و left تاثیر میگذارد و به صورت پیش فرض انهارا صفر فرض میکند.
7th Apr 2021, 9:03 AM
Root
Root - avatar