顺风背景img未显示



这可能是一个简单的修复方法,但我想知道为什么我的英雄部分的背景图像没有显示?

根据文件,将w-full和h-full与bg封面一起使用至少可以显示图像。唯一的解决方案是添加一个位置:绝对类。我想知道为什么会这样?文档中没有说要添加一个绝对类,但这似乎解决了问题,但我想知道为什么(这让我很困惑,哈哈(


<!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">
<link rel="stylesheet" href="../dist/tailwind.css">
<title>Document</title>
</head>
<body>

<div class=" w-full h-full" style="background-image: url('https://images.unsplash.com/photo-1624542316074-5ce16f7b6d41?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=934&q=80');">
<div></div>
</div>

您应该给div一些height,其中包含一些内容,如文本,或者使用顺风实用程序h-{something}不要使用h-full,因为它与cssheight: 100%;相同。如果您希望它填充屏幕,请使用实用程序类h-screen查看下面的片段

<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet" />
<div class="w-full h-screen" style="background-image: url('https://images.unsplash.com/photo-1624542316074-5ce16f7b6d41?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=934&q=80');">
<div></div>
</div>

最新更新