简体   繁体   English

如何在不使用CSS样式表的情况下使背景图像适合html中的屏幕

[英]how to make the background image fit to the screen in html without using CSS style sheet

I want to display a video in my local host site using html. 我想使用html在本地主机站点中显示视频。 In that I like to add a background image sized 748x489. 为此,我想添加大小为748x489的背景图片。 But it is not fit to the screen. 但是它不适合屏幕。 I want to fit it to the screen without using any external style sheets, CSS etc. please help me.. 我想使其适合屏幕而不使用任何外部样式表,CSS等。请帮助我。

<!DOCTYPE html>
<html>
<head>
<title style="color:red"> GOWTHAM </title>

<body background="C:\Users\win7\Desktop\sand.jpg" style="width:1040;height:960;">

<center>
<br>
<video width="640" height="540" controls>
<source src="C:\Users\win7\Desktop\gow.mp4" type="video/mp4">
</video>
<h1 style="color:red"> GOWTHAM IN STYLE!!! </h1>
</center>
</body>
</html>

Well, if you don't want to use an external stylesheet, thing that I personally discourage, then you have to rely on inline style. 好吧,如果您不想使用外部样式表(我个人不建议这样做),则必须依靠内联样式。

Firstly you'll need to set the size of the <body> element then, set his background value. 首先,您需要设置<body>元素的大小,然后设置其背景值。 To do it you need to go like 要做到这一点,你需要像

<body style="size:1040px;height:960px;background:url('path/to/file.jpg') no-repeat; background-size: cover">

Please mind in the example above the presence of px which stands for pixel and which you omitted and the presence of the rule no-repeat and background-size: cover which means that the background will be stretched to cover the whole size of the element. 请注意,在上面的示例中,存在px (代表像素,已将其省略)以及规则no-repeatbackground-size: cover ,这意味着背景将被拉伸以覆盖元素的整个尺寸。 Otherwise if the image is not big enough and / or is part of a repetitive pattern remove both and go like 否则,如果图像不够大和/或属于重复模式,则将两者都移除,然后像

<body style="size:1040px;height:960px;background:url('path/to/file.jpg');">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM