How to make a div's background color randomly change when the page refreshes

this is my first question here so excuse me if I did anything wrong. I'm doing the layout of a website and I want the header to change colors randomly when the user refresh the page. I already did some research and got these javascript codes: This one goes inside the head tag. It picks a random hexadecimal code between the two ones I want and store it on the var color. The second one I'm using goes on the body. *Header code here*
The problem is that this way of doing it is giving me some troubles, since the div id="header" is written inside javascript. I can't wrap other divs properly and Google Chrome's inspect element tells me that the body size is 1333px x 80px (as it can be seen here [](, exactly and only the header size, and it doesn't wraps the rest of the website content. So my question is: Is there any way to improve that code? Make the background color of that div change via javascript or something like that? I thank you all in advance for reading and appreciate your help.

以上就是How to make a div's background color randomly change when the page refreshes的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准