背景渐变问题
Background gradient problems
我尝试为我的网站制作渐变背景。你能帮我么?我现在正在学习 CSS/HTML。所以背景应该有一个从红色到黄色的渐变。我在等你的回答 c;
这是我的个人网站
body {
background-image: linear-gradient(to bottom, red, yellow);
margin: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
#card {
position: relative;
box-shadow: 5px 5px 10px rgba(0, 0, 0, .5);
background-color: #ffffff;
padding: 75px;
border-radius: 35px 35px;
-webkit-transition-duration: 0.2s;
transition-duration: 0.2s;
}
#card:hover {
box-shadow: 0 25px 50px black;
}
#person {
background-image: linear-gradient(to bottom, #c94370, #3a679a);
font-size: 67px;
font-size-adjust: 0.58;
font-family: 'Open Sans', bold;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
#profile {
display: block;
height: 320px;
margin-left: auto;
margin-right: auto;
border-radius: 100% 100%;
box-shadow: 0 0 25px rgba(0, 0, 0, 0.5);
-webkit-transition-duration: 0.2s;
transition-duration: 0.2s;
}
#profile:hover {
box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
}
#mail {
display: block;
border: 5px solid #303030;
font-family: 'Open Sans', bold;
border-radius: 15px 15px;
background-color: #ffffff;
padding: 15px 42px;
font-size: 36px;
color: #303030;
text-align: center;
-webkit-transition-duration: 0.4s;
transition-duration: 0.4s;
margin-left: auto;
margin-right: auto;
}
#mail:hover {
color: white;
background-color: #303030;
}
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i,800,800i&display=swap" rel="stylesheet">
<link rel="shortcut icon" href="oskar.png" type="image/png" />
<link rel="icon" href="oskar.png" type="image/png" />
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="card">
<img src="oskar.png" id="profile"> <br>
<b id="person">Oskar </b><br><br>
<button id="mail" onclick="window.location.href='mailto:mail@mail.mail?subject=Die%20Website%20ist%20krass'">E-Mail</button>
</div>
</body>
</html>
我希望有红色和黄色的渐变背景
我会看看这个 link
它似乎有你要找的东西。我认为由于默认是从上到下,您代码中的 "to bottom" 部分可能会导致问题?
我在这里 link 测试了它,它似乎以任何方式工作(有或没有 "to bottom")。
您的 CSS 应如下所示:
body {
background-image: linear-gradient(to bottom, red, yellow);
background-repeat: no-repeat;
background-attachment: fixed;
position: static;
}
#card {
position: relative;
width: 300px;
height: 500px;
margin: auto;
box-shadow: 5px 5px 10px rgba(0, 0, 0, .5);
background-color: #ffffff;
padding: 75px;
border-radius: 35px 35px;
-webkit-transition-duration: 0.2s;
transition-duration: 0.2s;
}
position: absolute 弄乱了背景的显示。这会相对于它的 parent 定位一个元素。由于 body 的 parent 是 html 标签,我不太确定 body 的位置,但它不是您想要的位置它。
看这里:https://www.w3schools.com/css/css_positioning.asp
您也不应该描述 body 内部的定位,因为您放入其中的所有内容都会尽量远离顶部和左侧 50%。与变换相同。这些样式应该添加到您正在设置样式的实际元素中。
background-repeat: no-repeat, background-attachment: fixed, position: static 将确保渐变调整到 window 大小并且不会出错。
您可以看到我是如何将高度、宽度和边距样式添加到您的卡片中的class。
我尝试为我的网站制作渐变背景。你能帮我么?我现在正在学习 CSS/HTML。所以背景应该有一个从红色到黄色的渐变。我在等你的回答 c;
这是我的个人网站
body {
background-image: linear-gradient(to bottom, red, yellow);
margin: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
#card {
position: relative;
box-shadow: 5px 5px 10px rgba(0, 0, 0, .5);
background-color: #ffffff;
padding: 75px;
border-radius: 35px 35px;
-webkit-transition-duration: 0.2s;
transition-duration: 0.2s;
}
#card:hover {
box-shadow: 0 25px 50px black;
}
#person {
background-image: linear-gradient(to bottom, #c94370, #3a679a);
font-size: 67px;
font-size-adjust: 0.58;
font-family: 'Open Sans', bold;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
#profile {
display: block;
height: 320px;
margin-left: auto;
margin-right: auto;
border-radius: 100% 100%;
box-shadow: 0 0 25px rgba(0, 0, 0, 0.5);
-webkit-transition-duration: 0.2s;
transition-duration: 0.2s;
}
#profile:hover {
box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
}
#mail {
display: block;
border: 5px solid #303030;
font-family: 'Open Sans', bold;
border-radius: 15px 15px;
background-color: #ffffff;
padding: 15px 42px;
font-size: 36px;
color: #303030;
text-align: center;
-webkit-transition-duration: 0.4s;
transition-duration: 0.4s;
margin-left: auto;
margin-right: auto;
}
#mail:hover {
color: white;
background-color: #303030;
}
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i,800,800i&display=swap" rel="stylesheet">
<link rel="shortcut icon" href="oskar.png" type="image/png" />
<link rel="icon" href="oskar.png" type="image/png" />
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="card">
<img src="oskar.png" id="profile"> <br>
<b id="person">Oskar </b><br><br>
<button id="mail" onclick="window.location.href='mailto:mail@mail.mail?subject=Die%20Website%20ist%20krass'">E-Mail</button>
</div>
</body>
</html>
我希望有红色和黄色的渐变背景
我会看看这个 link 它似乎有你要找的东西。我认为由于默认是从上到下,您代码中的 "to bottom" 部分可能会导致问题?
我在这里 link 测试了它,它似乎以任何方式工作(有或没有 "to bottom")。
您的 CSS 应如下所示:
body {
background-image: linear-gradient(to bottom, red, yellow);
background-repeat: no-repeat;
background-attachment: fixed;
position: static;
}
#card {
position: relative;
width: 300px;
height: 500px;
margin: auto;
box-shadow: 5px 5px 10px rgba(0, 0, 0, .5);
background-color: #ffffff;
padding: 75px;
border-radius: 35px 35px;
-webkit-transition-duration: 0.2s;
transition-duration: 0.2s;
}
position: absolute 弄乱了背景的显示。这会相对于它的 parent 定位一个元素。由于 body 的 parent 是 html 标签,我不太确定 body 的位置,但它不是您想要的位置它。
看这里:https://www.w3schools.com/css/css_positioning.asp
您也不应该描述 body 内部的定位,因为您放入其中的所有内容都会尽量远离顶部和左侧 50%。与变换相同。这些样式应该添加到您正在设置样式的实际元素中。
background-repeat: no-repeat, background-attachment: fixed, position: static 将确保渐变调整到 window 大小并且不会出错。
您可以看到我是如何将高度、宽度和边距样式添加到您的卡片中的class。