Div width for relative position | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Div width for relative position

My code: <div id="box">I am a box</div> #box{ width:100px; height:100px; background:red; position:relative;} As you see,Ive setted my div width and height into 100px but it doesnt seen to work.It keeps defining its width and height as the width and height of the element inside because of the relative position. Can anyone tell me is there anyway to set the div position into "relative" while setting its width and height to 100px?

10th Dec 2016, 10:15 AM
Foxtrot Pipe
Foxtrot Pipe - avatar
1 Answer
0
Do you have the CSS in tag <style> in its head or the external CSS file. <html> <head> <style> #box{ width:100px; height:100px; background:red; position:relative;} </style> </head> <body> <div id="box">I am a box</div> </body> </html>
11th Dec 2016, 8:25 AM
Fran Lopez
Fran Lopez - avatar