html - 无法使文本响应并以背景图像部分为中心
问题描述
您好希望我的页面有一个导航栏,然后在其下方有一个带有背景图像的标题,然后在该主要内容下方。我遇到的问题是,当我将文本放在标题部分的背景图像上时,我无法正确配置它以响应。 小提琴
<style>
header {
background:
linear-gradient(
rgba(0, 0, 0, 0.5),
rgba(0, 0, 0, 0.5)
),
url('http://getwallpapers.com/wallpaper/full/6/3/b/920866-download-free-beautiful-background-pics-1920x1200-for-ios.jpg');
background-size: cover;
height: 75vh;
}
</style>
<header>
<div class="topnav">
<a class="active" href="#home">Home</a>
<a href="#news">News</a>
<a href="#contact">Contact</a>
<a href="#about">About</a>
</div>
<div class='headertext'>
<h1> Trying To Get This Text Responsive </h1>
</div>
</header>
<main>
Main Content Goes Here
</main>
样式.css
/* Add a black background color to the top navigation */
.topnav {
background-color: #333;
overflow: hidden;
}
/* Style the links inside the navigation bar */
.topnav a {
float: left;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
/* Change the color of links on hover */
.topnav a:hover {
background-color: #ddd;
color: black;
}
/* Add a color to the active/current link */
.topnav a.active {
background-color: #4CAF50;
color: white;
}
解决方案
h1 默认左对齐。尝试:
.headertext h1{
text-align:center;
}
使其居中
推荐阅读
- laravel - 在 v-for 中的 v:bind 中使用动态名称
- javascript - 单击项目后关闭css悬停下拉菜单
- vue.js - 将“活动”类添加到 Nuxt.js Bootstrap
- excel - 初始化时清除用户表单
- c# - 找不到 ODBC 的数据提供程序
- powershell - 如何使用 Ansible 中的自定义事实从 Windows 主机检索已安装软件的列表
- mongodb - Kmongo (Kotlin Server + Mongo) 的 Ktor 服务器配置问题
- regex - PowerShell将字符串切成两半
- git - 执行 git pull 后使用 difftool
- python - 如何从桌面文件中获取 Exec 字段