如何在CSS中将2个文本组合在一起?

问题描述 投票:0回答:1

CSS 相对较新,我不知道如何向谷歌表达这一点。我如何将两个文本放在一起,以便“按任意键继续”位于其顶部,但仍然对齐。

index.html

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Montserrat">
        <title>Ameglass</title>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        <div class="container">
            <p>Press Any Key to Continue</p>
            <h1 class="gradient-text" style="font-size:400%">Welcome to Ameglass</h1>
        </div>
    </body>
</html>

样式.css

body {
    background: linear-gradient(to bottom left, #EE82EE 30%, #00D1FF 100%);
    height: 100vh;
    font-family: Montserrat;
}

.container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100vh
}

.gradient-text {
    background-image: linear-gradient(to right, #d173d1 33%,#9460e7 66%, #00D1FF 100%);
    color: transparent;
    -webkit-background-clip: text;
    background-clip: text;
}

我不确定这里要改变什么。

如果您能告诉我该怎么做,我将非常感激, 谢谢你。

html css flexbox centering
1个回答
0
投票

标题和段落(像许多元素一样)具有浏览器设置的默认边距。听起来您只是想用

h1, p {margin: 0;}
:

之类的东西来减少这些默认边距

h1, p {margin: 0;}
body {
    background: linear-gradient(to bottom left, #EE82EE 30%, #00D1FF 100%);
    height: 100vh;
    font-family: Montserrat;
}

.container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100vh
}

.gradient-text {
    background-image: linear-gradient(to right, #d173d1 33%,#9460e7 66%, #00D1FF 100%);
    color: transparent;
    -webkit-background-clip: text;
    background-clip: text;
}
<div class="container">
  <p>Press Any Key to Continue</p>
  <h1 class="gradient-text" style="font-size:400%">Welcome to Ameglass</h1>
</div>

© www.soinside.com 2019 - 2024. All rights reserved.