Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何在主体样式中正确设置一行中的背景不透明度?_Html_Css - Fatal编程技术网

Html 如何在主体样式中正确设置一行中的背景不透明度?

Html 如何在主体样式中正确设置一行中的背景不透明度?,html,css,Html,Css,如何使用“下一步”正确设置背景不透明度: <body style="background-image: url(images/background.jpg); background-color: white; background-position: center center; background-size: 100%; background-repeat: no-repeat"> 但是失败了 应该是这样的: background-image: url(images/ba

如何使用“下一步”正确设置背景不透明度:

<body style="background-image: url(images/background.jpg); background-color: white;
 background-position: center center; background-size: 100%; 
 background-repeat: no-repeat">
但是失败了

应该是这样的:

background-image: url(images/background.jpg) opacity: 0.5;
甚至

不影响图像,但影响文本和整个身体

不接受使用div的解决方案

我的网页:


浏览器:firefox和chrome使用
opacity
属性更改元素本身的不透明度

要使用透明的
背景色
,可以使用
rgba()
作为背景色:

background-color: rgba(255, 255, 255, .5);
或者简而言之:

background: rgba(255, 255, 255, .5) url(path/to/transparent/background.png) center center no-repeat;
但是如果需要透明背景图像,则图像本身应该是透明的


顺便说一下,为背景图像设置不透明度,但我不确定在这种情况下是否有用。

不能使用CSS设置元素整个背景的不透明度

  • 可以设置整个元素的不透明度(使用
    opacity
    属性)
  • 您可以设置背景色的不透明度(使用
    rgba
    颜色:
    背景色:rgba(50%,50%,50%,0.5);

如果想要半透明的背景图像,则必须对图像本身的不透明度进行编码(使用PNG或WebP图像格式,它们支持这一点)。

使用以下代码并根据需要调整宽度

<p><img style="opacity:0.9;" src="C:\Users\Desktop\images.jpg" width="300" height="231" alt="Image" /></p>


您的答案:使用css只能更改颜色?:不幸的是,它不起作用,请检查我的页面,我使用您的示例代码。@我提到的innocent world图像本身应该是透明的,但请查看答案中的链接,它可能会有所帮助。这存在于我的问题“不接受使用div的解决方案”中,我知道如何使用div。但body的样式看起来很强大,应该保留此选项。@Innomy world您也可以使用
::before
伪元素来实现此效果。
background: rgba(255, 255, 255, .5) url(path/to/transparent/background.png) center center no-repeat;
<p><img style="opacity:0.9;" src="C:\Users\Desktop\images.jpg" width="300" height="231" alt="Image" /></p>