【发布时间】:2023-02-04 04:33:08
【问题描述】:
我的网页上有一张图片,我试图在图片中央显示文本“欢迎来到华盛顿州”,但到目前为止都失败了。我尝试使用 flexbox 和显示功能,文本将在图像上对齐,但我无法将其置于图像中心。我怎样才能让它到达文本可以对齐图像中心的位置?
-谢谢您的帮助!
* {
margin: 0;
padding: 0;
}
/*------------------------------HEADER--------------------*/
.header {
background-color: #00843D;
height: 125px;
position: relative;
}
.logo img {
height: 200px;
width: 200px;
position: relative;
z-index: 1;
}
.logo {
position: absolute;
left: 5%;
top: 15%;
}
.nav-links {
text-align: right;
}
.nav-links ul {
color: white;
padding: 25px;
}
.nav-links ul li {
display: inline-block;
font-size: 35px;
padding: 20px;
}
/*--------------------------WELCOME PAGE----------------*/
.welcome-page {
position: relative;
}
.welcome-page img {
width: 100%;
height: 100%;
position: relative;
}
.welcome-page h1 {
position: absolute;
color: black;
text-align: center;
top: 20%;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Homepage</title>
<link rel="stylesheet" href="homepage.css">
</head>
<body>
<!--Navigation Link-->
<div class="header">
<div class="logo">
<img src="C:\Users\\Documents\Washington State Project\Images\Seal_of_Washington.svg.png">
</div>
<!--Tabs-->
<div class="nav-links">
<ul>
<li>Things to do</li>
<li>History</li>
<li>Education</li>
<li>Sports</li>
</ul>
</div>
</div>
<!--Welcome Page-->
<div class="welcome-page">
<img src="C:\Users\Roger Garcia\Documents\Washington State Project\">
<h1>Welcome to Washington State</h1>
</div>
</body>
</html>
【问题讨论】:
-
为什么不在 css 中将图像设置为背景?否则你可以使用绝对定位和 z-index