我正在开发我的个人网站 - https://cooperativedoilylivedistro.elliott23.repl.co - 它根据喜好有浅色和深色主题。问题是,当我将线性渐变设置为变量时,它不起作用并且整个背景变成白色。 这就是 HTML、CSS 和 JS。如果您想了解发生了什么,请在浏览器中查看该网站。
Elliott D'Orazio Elliott D'Orazio
Front-End Developer
This page isn't viewable on mobile, move to a desktop to view it!
:root{
--accent-color-: #4022d3;
}
body:not(.dark) {
--background: white;
--text: black;
}
body.dark {
--background: #222;
--text: white;
}
html {
height: 100%;
width: 100%;
background-image: linear-gradient(to right, transparent 20%, var(--background) 60% ), url('bd86goc4fhvenj72.jpg');
font-family: 'Rubik', monospace;
background-size: cover;
}
/* *{
outline: 1px red solid;
} */
.split {
height: 100%;
width: 40%;
position: fixed;
z-index: 1;
top: 0;
overflow-x: hidden;
padding-top: 20px;
text-align: center;
background-color: var(--background);
color: var(--text);
}
.right {
right: 0;
background-color: var(--background);
}
h1{
font-size: 7.4em;
font-weight: 800;
}
.icons{
display: flex;
flex-direction: row;
gap: 20px;
margin-left: 40%;
width: 136px;
}
.fa-solid{
color: var(--text) !important;
}
.fa-solid:hover{
content: '';
color: var(--accent-color-) !important;
cursor: pointer;
}
.mobile{
display: none;
}
@media screen and (max-width: 678px) {
body{
display: none;
}
.mobile{
display: block !important;
color: #fff;
}
}
let dark_prefered = window.matchMedia("(prefers-color-scheme: dark)")
if(dark_prefered.matches) document.body.classList.add("dark")
dark_prefered.addEventListener("change", () => {
if(dark_prefered.matches) document.body.classList.add("dark")
else document.body.classList.remove("dark")
})
我尝试过制作多个渐变,但没有成功。我问了一位比较有经验的朋友,他也搞不明白。所以我来到这里,而不是去像 ChatGPT 这样的人工智能。非常感谢您的帮助。谢谢!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
此代码可以帮助您解决线性渐变问题
:root{ --accent-color-: #4022d3; color-scheme: dark light; --background-white: white; --background-dark: #222; } body:not(.dark) { --text: black; /* background-color: var(--background-white); */ } body.dark { background: var( --background-dark); --text: white; } html { height: 100%; width: 100%; background-image: linear-gradient(to right, transparent 20%, var(--background-white) 60% ), url('http://www.skrenta.com/images/stackoverflow.jpg'); font-family: 'Rubik', monospace; background-size: cover; } /* *{ outline: 1px red solid; } */ .split { height: 100%; width: 80%; position: fixed; z-index: 1; top: 0; overflow-x: hidden; padding-top: 20px; text-align: center; background-color: var(--background); color: var(--text); } .right { right: 0; background-color: var(--background); } h1{ font-size: 7.4em; font-weight: 800; } .icons{ display: flex; flex-direction: row; gap: 20px; margin-left: 40%; width: 136px; } .fa-solid{ color: var(--text) !important; } .fa-solid:hover{ content: ''; color: var(--accent-color-) !important; cursor: pointer; } .mobile{ display: none; } @media screen and (max-width: 678px) { body{ display: none; } .mobile{ display: block !important; color: #fff; } }