gpt4 book ai didi

css - React - 使用样式渲染

转载 作者:行者123 更新时间:2023-11-27 23:33:26 26 4
gpt4 key购买 nike

抱歉,如果这太基础了,我是 React 的新手。

我正在尝试导入一些 CSS(由动画组成),如下所示:

import './css/mug.css'

杯子.css

@import url(https://fonts.googleapis.com/css?family=Josefin+Sans:100,400);

body {
background:rgb(223,189,150);
font-family: 'Josefin Sans', sans-serif;
text-align:center;
}

.cup {
width:76px;
height:76px;
background:#dedede;
border-radius:50%;
position:absolute;
left:50%;
margin-left:-38px;
top:100px;
box-shadow:-4px -1px 0 rgba(0,0,0,0.2);
}

.cup:after{
content:"";
width:66px;
height:66px;
position:absolute;
border-radius:50%;
background:linear-gradient(-45deg, #cbcbcb, #f2f2f2 );
left:50%;
margin-left:-33px;
top:5px;
}

.coffee{
width:47px;
height:47px;
background:#613317;
/*background-image: linear-gradient(15deg, transparent 0px, transparent 29px, rgba(255,255,255,0.05) 29px, rgba(255,255,255,0.05) 47px);*/
border-radius:50%;
position:absolute;
left:50%;
margin-left:-25px;
z-index:1;
top:50%;
margin-top:-26px;
border:3px solid #e9e9e9;
box-shadow:-3px 2px 0 rgba(0,0,0,0.1);
transform:rotate(30deg);
transition:transform 0.3s;
}

.coffee:after{ /*assa*/
content:"";
width:15px;
height:8px;
position:absolute;
left:-19px;
top:18px;
background:linear-gradient(90deg, #d6d6d6, #aeaeae);
box-shadow:0px 2px 0 rgba(0,0,0,0.2);
}

.coffee:before {
content:"";
width:47px;
height:47px;
background-image: radial-gradient(75% 59%, ellipse, rgba(255,255,255,0.2), transparent 95%), radial-gradient(5% 9%, ellipse, rgba(255,255,255,0.1), transparent 5%), radial-gradient(0% 0%, ellipse, rgba(255,255,255,0.3), transparent 55%);
background-image: -webkit-radial-gradient(75% 59%, ellipse, rgba(255,255,255,0.2), transparent 95%), -webkit-radial-gradient(5% 9%, ellipse, rgba(255,255,255,0.1), transparent 5%), -webkit-radial-gradient(0% 0%, ellipse, rgba(255,255,255,0.3), transparent 55%);
background-image: -moz-radial-gradient(75% 59%, ellipse, rgba(255,255,255,0.2), transparent 95%), -moz-radial-gradient(5% 9%, ellipse, rgba(255,255,255,0.1), transparent 5%), -moz-radial-gradient(0% 0%, ellipse, rgba(255,255,255,0.3), transparent 55%);
position:absolute;
left:0;
border-radius:50%;
}
.cup:hover .coffee {
transform:rotate(15deg);
}

.smoke {
width:70px;
height:100px;
background:;
position:absolute;
left:50%;
margin-left:-40px;
top:43px;
background-image: -webkit-radial-gradient(75% 59%, ellipse, rgba(255,255,255,0.2), transparent 25%), -webkit-radial-gradient(25% 70%, ellipse, rgba(255,255,255,0.2), transparent 15%), -webkit-radial-gradient(35% 61%, ellipse, rgba(255,255,255,0.2), transparent 10%), -webkit-radial-gradient(55% 35%, ellipse, rgba(255,255,255,0.2), transparent 15%);
background-image: -moz-radial-gradient(75% 59%, ellipse, rgba(255,255,255,0.2), transparent 25%), -moz-radial-gradient(25% 70%, ellipse, rgba(255,255,255,0.2), transparent 15%), -moz-radial-gradient(35% 61%, ellipse, rgba(255,255,255,0.2), transparent 10%), -moz-radial-gradient(55% 35%, ellipse, rgba(255,255,255,0.2), transparent 15%);
background-image: radial-gradient(75% 59%, ellipse, rgba(255,255,255,0.2), transparent 25%), radial-gradient(25% 70%, ellipse, rgba(255,255,255,0.2), transparent 15%), radial-gradient(35% 61%, ellipse, rgba(255,255,255,0.2), transparent 10%), radial-gradient(55% 35%, ellipse, rgba(255,255,255,0.2), transparent 15%);
animation:bk 11s infinite ;
}

.smoke:after {
content:"";
width:100px;
height:100px;
background:;
position:absolute;
background-image: -webkit-radial-gradient(75% 59%, ellipse, rgba(255,255,255,0.2), transparent 25%), -webkit-radial-gradient(25% 70%, ellipse, rgba(255,255,255,0.2), transparent 15%), -webkit-radial-gradient(35% 61%, ellipse, rgba(255,255,255,0.2), transparent 10%);
background-image: -moz-radial-gradient(75% 59%, ellipse, rgba(255,255,255,0.2), transparent 25%), -moz-radial-gradient(25% 70%, ellipse, rgba(255,255,255,0.2), transparent 15%), -moz-radial-gradient(35% 61%, ellipse, rgba(255,255,255,0.2), transparent 10%);
background-image: radial-gradient(75% 59%, ellipse, rgba(255,255,255,0.2), transparent 25%), radial-gradient(25% 70%, ellipse, rgba(255,255,255,0.2), transparent 15%), radial-gradient(35% 61%, ellipse, rgba(255,255,255,0.2), transparent 10%);
animation:bk 2s 1s infinite;
}


@keyframes bk {
0%{ background-position:0 0; opacity:0; }
15%, 85% { opacity:1;}
100%{ background-position:-20px -25px, -5px -25px, 0px -25px, 0px -25px; opacity:0;}
}

.txt{
position:absolute;
top:184px;
width:150px;
left:50%;
margin-left:-75px;
}

.txt a{
text-decoration:none;
color:#613317;
}

.txt a:hover {
text-decoration:underline;
}

像这样渲染(动画)它:

    <div>
<div className="cup">
<div className="coffee"></div>
</div>
<div className="smoke"></div>

并将此样式添加到 <Link>

const Brewing = (props) => (
<div>
<Link
to="/brewing">Brew
style=?
</Link>
</div>
)

export default Brewing;

我不能像这样简单地添加多个类:

var myClassNames = "cup coffee smoke"

并将其传递给样式:

style={myClassNames}   

因为“咖啡”包含在“杯子”中。

那么如何添加此样式并在单击它时将其正确呈现到我的链接中呢?

最佳答案

对于任何 Web 开发,使用 react-router-dom,然后使用包含 activeClassName 属性的 NavLink

...
<NavLink to="/brewing" activeClassName="cup coffee smoke">
Brewing
</NavLink>
...

这里是 documentation 的链接.

关于css - React - 使用样式渲染 <Link>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57366777/

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