+ 4

I want to have a background image in the div tag that doesn't go to the next line. How do i fix it? Code is in the description.

<!doctype html> <head> <title>page</title> </head> <body> <div style="background-image: url('pic.gif);"> </body> </html>

28th Mar 2017, 4:56 AM
chris
chris - avatar
5 ответов
+ 3
I know the div tag automatically goes to the next line because its a block tag. But how do I start the div from the beginning of the page without having the white space that I have with this code.
28th Mar 2017, 4:59 AM
chris
chris - avatar
+ 3
thanks. I write body{ margin: 0;} and it works. But, is the HTML{ margin: 0; padding: 0} necessary ?
28th Mar 2017, 6:57 AM
chris
chris - avatar
+ 3
nope, but it's just my habit to write that^^
28th Mar 2017, 7:00 AM
CHMD
CHMD - avatar
+ 3
why do you have that habit
28th Mar 2017, 7:03 AM
chris
chris - avatar
+ 2
I don't know if I've clearly got your prob, but I guess you're talking about that padding that the browser puts by default in your page. to fix this you'll have to use some CSS. html, body{ padding :0; margin:0;} Also, divs can be changed so as they can be aligned at a line level while "behaving" as a block at the same time. Just apply display: inline-block; to those divs
28th Mar 2017, 6:32 AM
CHMD
CHMD - avatar