HTML>使用HTML / CSS℃的网页设置背景图片; VS<身体GT; [英] Set background image of a webpage using HTML/CSS <html> vs <body>

查看:128
本文介绍了HTML>使用HTML / CSS℃的网页设置背景图片; VS<身体GT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTML文件和链接到一个CSS文件。我得到了它由(在CSS文件中身下标记),这样做是为了显示CSS文件下一个重复的背景图片和它的作品:

  {体
    / *设置背景图片* /
    背景:网址(../ IMG /背景/ main.jpg)重复;
}

但是,当我尝试做这样(在HTML标签中的CSS文件),它不工作:

  HTML {
    / *设置背景图片* /
    背景:网址(../ IMG /背景/ main.jpg)重复;

据本网它显示使用HTML标签的例子:
本网站显示HTML CSS正与HTML标记

那么,如何使这项工作,或者我应该不会做这样说?


解决方案

它通常被认为是不好的做法,把CSS的HTML标签,所以你应该保持它在身上的标签。通常这是语义的原因 - HTML元素包含了不应该,也不会应用到他们(即头。)

风格子元素。

开发往往样式应用到HTML元素出于懒惰或者是因为他们不知道任何好转或避免添加其他元素的DOM,但这并不作出正确选择。

相当方便,用body元素已经为你工作,所以NBD。 :)

I have an HTML file and links to a CSS file. I got it to display a repeating background image under the CSS file by doing this (under body tag in the CSS file) and it works:

body {
    /*Set background image*/
    background: url("../img/background/main.jpg") repeat;
}

But when I try to do it this way (under html tag in the CSS file) it doesnt work:

html {
    /*Set background image*/
    background: url("../img/background/main.jpg") repeat;

According to this site it shows the example using the html tag: This site shows html in css being used with html tag

So how do I make this work, or should I NOT be doing it this way?

解决方案

It's generally considered bad practice to put CSS on the HTML tag, so you should keep it on the body tag. Usually this is for semantic reasons - the HTML element contains child elements that should not and cannot have styles applied to them (ie. the head).

Developers tend to apply styles to the HTML element out of laziness or because they don't know any better or to avoid adding additional elements to the DOM, but that doesn't make it right.

Handily, using the body element already works for you, so nbd. :)

这篇关于HTML>使用HTML / CSS℃的网页设置背景图片; VS<身体GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆