我在文件夹中有一个徽标,需要将其覆盖在矩阵画布/背景上。最下面的代码段是带有位置的Logo png文件。只是似乎没有出现。我添加了一个带有0边框的logo.png,但是它在顶部留下了一个黑色的空白块。我需要图像在页面中心重叠矩阵代码。
非常感谢。
附言:如果您不希望对我的logo.png文件提出建议,请不要编辑我的代码。我已经看到了尝试,它改变了我想要的结果。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>CybernetiX Corp</title>
<style>
/*basic reset */
*{
margin: 0;
padding: 0;
}
/* Page settings */
html {
width: 100%;
height: 100%;
background: radial-gradient(circle, #fff 0%, #aaa 100%) no-repeat;
overflow-x: hidden;
overflow-y: hidden;
}
body {
text-align: center;
display: table;
background: black;
width: 100%;
height: 100%;
overflow-x: hidden;
overflow-y: hidden;
}
canvas {display:block;}
#author {
position: absolute;
bottom: 10px;
left: 10px;
color : #0F0;
z-index : 1;
box-sizing: border-box;
vertical-align: middle;
}
span {
font-family: monospace;
font-size: 1.5em;
}
span:after {
content:"CybernetiX-S3C";
opacity: 0;
animation: cursor 1s infinite;
}
@keyframes cursor {
0% {
opacity: 0;
}
40% {
opacity: 0;
}
50% {
opacity: 1;
}
90% {
opacity: 1;
}
100% {
opacity: 0;
}
}
</style>
</head>
<img src="img/LOGO.png" alt="CybernetiX-Corp">
<body>
<canvas id="c"></canvas>
<span id = "author">John Modica @ </span>
<script>
// geting canvas by id c
var c = document.getElementById("c");
var ctx = c.getContext("2d");
//making the canvas full screen
c.height = window.innerHeight;
c.width = window.innerWidth;
//chinese characters - taken from the unicode charset
var matrix = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789@#$%^&*()*&^%";
//converting the string into an array of single characters
matrix = matrix.split("");
var font_size = 10;
var columns = c.width / font_size; //number of columns for the rain
//an array of drops - one per column
var drops = [];
//x below is the x coordinate
//1 = y co-ordinate of the drop(same for every drop initially)
for(var x = 0; x < columns; x++)
drops[x] = 1;
//drawing the characters
function draw()
{
//Black BG for the canvas
//translucent BG to show trail
ctx.fillStyle = "rgba(0, 0, 0, 0.04)";
ctx.fillRect(0, 0, c.width, c.height);
ctx.fillStyle = "#0F0"; //green text
ctx.font = font_size + "px arial";
//looping over drops
for( var i = 0; i < drops.length; i++ )
{
//a random chinese character to print
var text = matrix[ Math.floor( Math.random() * matrix.length ) ];
//x = i*font_size, y = value of drops[i]*font_size
ctx.fillText(text, i * font_size, drops[i] * font_size);
//sending the drop back to the top randomly after it has crossed the screen
//adding a randomness to the reset to make the drops scattered on the Y axis
if( drops[i] * font_size > c.height && Math.random() > 0.975 )
drops[i] = 0;
//incrementing Y coordinate
drops[i]++;
}
}
setInterval( draw, 35 );
</script>
<p style-"text-align:center;"><img src="img/LOGO.png" alt="CybernetiX Corp"></p>
</body>
<body>
</body>
</html>
<img src="img/LOGO.png" alt="CybernetiX-Corp">
答案 0 :(得分:0)
这是您的操作方法。主要变化是。
将以下HTML添加到正文中。图像周围的包装将全屏显示,因此您可以使用CSS flex
将图像在图像的中间对齐。
<div class="img-wrapper"><img src="your-image"></div>
以下CSS在包装器的中间对齐图像。
.img-wrapper {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
display: flex;
justify-content: center;
align-items: center;
}
.img-wrapper {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
display: flex;
justify-content: center;
align-items: center;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>CybernetiX Corp</title>
<style>
/*basic reset */
* {
margin: 0;
padding: 0;
}
/* Page settings */
html {
width: 100%;
height: 100%;
background: radial-gradient(circle, #fff 0%, #aaa 100%) no-repeat;
overflow-x: hidden;
overflow-y: hidden;
}
body {
text-align: center;
display: table;
background: black;
width: 100%;
height: 100%;
overflow-x: hidden;
overflow-y: hidden;
}
canvas {
display: block;
}
#author {
position: absolute;
bottom: 10px;
left: 10px;
color: #0F0;
z-index: 1;
box-sizing: border-box;
vertical-align: middle;
}
span {
font-family: monospace;
font-size: 1.5em;
}
span:after {
content: "CybernetiX-S3C";
opacity: 0;
animation: cursor 1s infinite;
}
@keyframes cursor {
0% {
opacity: 0;
}
40% {
opacity: 0;
}
50% {
opacity: 1;
}
90% {
opacity: 1;
}
100% {
opacity: 0;
}
}
</style>
</head>
<body>
<canvas id="c"></canvas>
<span id="author">John Modica @ </span>
<script>
// geting canvas by id c
var c = document.getElementById("c");
var ctx = c.getContext("2d");
//making the canvas full screen
c.height = window.innerHeight;
c.width = window.innerWidth;
//chinese characters - taken from the unicode charset
var matrix = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789@#$%^&*()*&^%";
//converting the string into an array of single characters
matrix = matrix.split("");
var font_size = 10;
var columns = c.width / font_size; //number of columns for the rain
//an array of drops - one per column
var drops = [];
//x below is the x coordinate
//1 = y co-ordinate of the drop(same for every drop initially)
for (var x = 0; x < columns; x++)
drops[x] = 1;
//drawing the characters
function draw() {
//Black BG for the canvas
//translucent BG to show trail
ctx.fillStyle = "rgba(0, 0, 0, 0.04)";
ctx.fillRect(0, 0, c.width, c.height);
ctx.fillStyle = "#0F0"; //green text
ctx.font = font_size + "px arial";
//looping over drops
for (var i = 0; i < drops.length; i++) {
//a random chinese character to print
var text = matrix[Math.floor(Math.random() * matrix.length)];
//x = i*font_size, y = value of drops[i]*font_size
ctx.fillText(text, i * font_size, drops[i] * font_size);
//sending the drop back to the top randomly after it has crossed the screen
//adding a randomness to the reset to make the drops scattered on the Y axis
if (drops[i] * font_size > c.height && Math.random() > 0.975)
drops[i] = 0;
//incrementing Y coordinate
drops[i]++;
}
}
setInterval(draw, 35);
</script>
<div class="img-wrapper"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSYygrZgIU_1WjY1yAai9pp1hc56sm9bxMDa9aFOb5zyo5iA7mq" alt="CybernetiX Corp"></div>
</body>
</html>