html - 在标题中的径向渐变顶部居中透明背景图像

标签 html css background header transparent

我刚刚为我正在 build 的网站设计了一个新 Logo ,并制作了一个透明背景 PNG 图像,我想要在它后面有一个径向图像,并使图像保持在半径起源的中心。

它在桌面上看起来很好,直到您最小化屏幕然后出现严重溢出。我在 HTML 和 Body 部分尝试了 overflow-x: hidden,它消除了两侧的灰色空间,但图像偏离了径向渐变并且看起来很俗气。移动端也有这个问题,显示溢出,如果我选择隐藏就很偏心。

我尝试了 CSS 中不同 background 值的多种组合,-image, -position, -size, -cover 无济于事。

目前我有:

<style>
 html,body {
			width: 100%;
			height: 100%;
			margin: 0px;
			padding: 0px;
		}
   #banner {
			background-image: black; /* For browsers that do not support gradients */
			background-image: -webkit-radial-gradient(red, gray, black); /* Safari 5.1 to 6.0 */
			background-image: -o-radial-gradient(red, gray, black); /* For Opera 11.6 to 12.0 */
			background-image: -moz-radial-gradient(red, gray, black); /* For Firefox 3.6 to 15 */
			background-image: radial-gradient(red, gray, black); /* Standard syntax */
			width: 100%;
			background-position: center;
			background-repeat: no-repeat;
			background-size: cover;
    }
</style>

<header id="banner">
	<img src="banner.png" style="position:center"/>
</header>

有没有办法将它们相互叠加,我已经尝试列出 background-colorbackgroundbackground-image径向渐变以及 url("banner.png") 但这没有用,事实上,如果我尝试从 CSS 中包含它,图像将不会出现。

非常难过,我认为最简单的事情是创建渐变作为背景,但我不希望 Logo 在调整大小时变形。我放弃了尝试在 SVG 中这样做,并认为这会更容易。

最佳答案

<style>
 html,body {
			width: 100%;
			height: 100%;
			margin: 0px;
			padding: 0px;
		}
   #banner {
			background-image: black; /* For browsers that do not support gradients */
			background-image: -webkit-radial-gradient(red, gray, black); /* Safari 5.1 to 6.0 */
			background-image: -o-radial-gradient(red, gray, black); /* For Opera 11.6 to 12.0 */
			background-image: -moz-radial-gradient(red, gray, black); /* For Firefox 3.6 to 15 */
			background-image: radial-gradient(red, gray, black); /* Standard syntax */
			width: 100%;
			background-position: center;
			background-repeat: no-repeat;
			background-size: cover;
			text-align: center;
    }
</style>

<header id="banner">
	<img src="banner.png"/>
</header>

关于html - 在标题中的径向渐变顶部居中透明背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40114526/

相关文章:

php - 将单击事件附加到表格单元格的最佳方式是什么?

c# - 使用 C# 将图像上传到 .NET 服务器

html - 更改没有 body.background 的自定义博主模板中的背景

android - 无法将颜色转换为可绘制对象

javascript - 使用 anchor 作为 javascript 操作,链接应该是什么?

javascript - angularjs 将计数限制为当前范围

html - 列表显示为 block 而不是内联 block

javascript - 如何在 Javascript 中更改 HTML 背景颜色 - IE9 问题

html - 具有可编辑颜色的棋盘状背景

html - 如何从 Firefox 中的 <area> 元素中删除虚线边框?