首页 > 解决方案 > 无法使文本响应并以背景图像部分为中心

问题描述

您好希望我的页面有一个导航栏,然后在其下方有一个带有背景图像的标题,然后在该主要内容下方。我遇到的问题是,当我将文本放在标题部分的背景图像上时,我无法正确配置它以响应。 小提琴

<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;
}

标签: htmlcss

解决方案


h1 默认左对齐。尝试:

.headertext h1{
   text-align:center;
}

使其居中


推荐阅读