提问人:backslashdev 提问时间:10/9/2023 更新时间:10/9/2023 访问量:28
如何在css中将2个文本放在一起?
How to bring 2 texts together in css?
问:
对CSS来说相对较新,我不知道如何向谷歌表达这一点。我如何将这两个文本放在一起,以便“按任意键继续”位于其顶部,但仍然对齐。
索引.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;
}
我不确定在这里要改变什么。
如果你能说出如何做到这一点,我将不胜感激, 谢谢。
答:
1赞
ralph.m
10/9/2023
#1
标题和段落(像许多元素一样)具有浏览器设置的默认边距。听起来你只是想用这样的东西来减少这些默认边距: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>
评论