كيفية إنشاء: صورة البطل

تعلم كيفية استخدام CSS لإنشاء صورة البطل.

صورة البطل هي صورة كبيرة تحتوي على نص، عادة ما تُوضع في أعلى صفحة الويب:

تجربة شخصية

كيفية إنشاء صورة البطل

第一步 - 添加 HTML:

<div class="hero-image">
  <div class="hero-text">
    <h1>أنا بيل جيتس</h1>
    <p>و أنا مصور</p>
    <button>شغلني</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;
{}

تجربة شخصية