Why is it doing this? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 2

Why is it doing this?

I have a question about this code: https://code.sololearn.com/Wq7n7DNMB5nA/#css If I enable the /*border: 1px solid black;*/ line, the grey cube jumps down. But i don't know why? In Hungarian: Van egy kérdésem a kóddal kapcsolatban. Ha engedélyezem a /*border:1px solid black;/* sort, akkor a szürke kocka lejjebb ugrik. De miért?

11th Apr 2017, 7:48 PM
Tibor Bálint
Tibor Bálint - avatar
4 Respuestas
+ 5
if i am not mistaken, the answer lies with this line inside #orange{...}: margin-top: 40px; my assumption is that without border the margin is calculated from the top of the screen. but once the border is in place, that is new relative point from which the calculation start. can someone confirm that for me?
11th Apr 2017, 8:24 PM
Burey
Burey - avatar
+ 5
same thing happens when you add display inline-block to grey div. bottom line make the div float let and clear the content after it
11th Apr 2017, 9:11 PM
G. keng
G. keng - avatar
+ 3
grey is parent of orange which has margin top 40px. so because grey is not floating, when you add a border to it, it starts floating on the left of the document. you can hack this by simply adding float left to the grey div
11th Apr 2017, 8:36 PM
G. keng
G. keng - avatar
+ 1
And what if you write something after <div id="grey">? It is jump up. What is the relation between #orange's margin-top value and the #grey's margin?
11th Apr 2017, 8:34 PM
Tibor Bálint
Tibor Bálint - avatar