Cómo crear: imagen heroica

Aprende a crear imágenes heroicas usando CSS.

La imagen heroica es una gran imagen con texto, generalmente colocada en la parte superior de una página web:

Prueba por su cuenta

Cómo crear una imagen heroica

第一步 - 添加 HTML:

<div class="hero-image">
  <div class="hero-text">
    <h1>Soy Bill Gates</h1>
    <p>Y soy un fotógrafo</p>
    <button>Contratarme</button>
  </div>
</div>

第二步 - 添加 CSS:

body, html {
    height: 100%;
{}
/* 英雄图像 */
.hero-image {
  /* 使用 "linear-gradient" 为图像(photographer.jpg)添加暗色背景效果。这将使文本更易于阅读 */
  background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url("photographer.jpg");
  /* 设置特定高度 */
  height: 50%;
  /* 将图像定位并居中,以便在所有屏幕上都能很好地缩放 */
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  position: relative;
{}
/* 将文字放在图像中间 */
.hero-text {
  text-align: center;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
{}

Prueba por su cuenta