gpt4 book ai didi

html - 使用 flex 定位元素

转载 作者:行者123 更新时间:2023-11-28 02:20:08 24 4
gpt4 key购买 nike

这里只是一个快速的。我正在尝试使用 float:left 在我的网页的右上角放置一个 Logo ,但它似乎与其余元素一起卡在页面的中央。我试图将 text-align:center 从 #showcase 移开,但我仍然得到相同的结果。

#logo h2 {
float: left;
color: #ffffff;
text-decoration: line-through;
}

#showcase {
background-image: url("../img/sky.jpg");
height: 100vh;
background-size: cover;
background-position: center;
display: flex;
flex-direction: column;
text-align: center;
padding: 0 20px;
align-items: center;
}

.header p {
float: left;
}

#showcase h1 {
color: #ffffff;
line-height: 1.2;
word-spacing: 5;
text-transform: capitalize;
font-family: 'Open Sans', sans-serif;
font-weight: bold;
font-size: 120px;
margin-top: 150px;
}
<body>

<header id="showcase">
<h1>404</h1>
<p>Oops! the page you're looking for cannot be found</p>
<a href="#" class="button">GO BACK</a>
<h2 id="logo">Daily UI</h2>
</header>

</body>

最佳答案

一个简单的解决方案是使用绝对位置 并将 Logo 准确放置在您希望的位置。另外,请注意 #logo h2 不是您的 Logo 元素的正确选择器。您应该改用 h2#logo

请检查下面的代码段。

h2#logo {
text-decoration: line-through;
position:absolute;
top:10px;
right:10px;
}

#showcase {
background-image: url("../img/sky.jpg");
height: 100vh;
background-size: cover;
background-position: center;
display: flex;
flex-direction: column;
text-align: center;
padding: 0 20px;
align-items: center;
}

#showcase h1 {
line-height: 1.2;
word-spacing: 5;
text-transform: capitalize;
font-family: 'Open Sans', sans-serif;
font-weight: bold;
font-size: 120px;
margin-top: 150px;
}
<body>

<header id="showcase">
<h1>404</h1>
<p>Oops! the page you're looking for cannot be found</p>
<a href="#" class="button">GO BACK</a>
<h2 id="logo">Daily UI</h2>
</header>

</body>

关于html - 使用 flex 定位元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48256440/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com