我想制作一个具有定义宽度的按钮,但是我有一个模板,其中按钮组件定义为包括样式,因此当我尝试修改按钮的样式时,它什么也没有发生,这是我的代码
这是我在react类中调用组件的时候
<Button
className={classes.buttonW}
component={Link}
color="success"
size="lg"
to="/album-carousel-page"
>
Galeria
</Button>
修改css按钮时的类名
buttonW: {
width: "100px",
height: "30px"
}
这是模板原始按钮上方的代码(我认为非常复杂)
button: {
minHeight: "auto",
minWidth: "auto",
backgroundColor: grayColor,
color: "#FFFFFF",
boxShadow:
"0 2px 2px 0 rgba(153, 153, 153, 0.14), 0 3px 1px -2px rgba(153, 153, 153, 0.2), 0 1px 5px 0 rgba(153, 153, 153, 0.12)",
border: "none",
borderRadius: "3px",
position: "relative",
padding: "12px 30px",
margin: ".3125rem 1px",
fontSize: "12px",
fontWeight: "400",
textTransform: "uppercase",
letterSpacing: "0",
willChange: "box-shadow, transform",
transition:
"box-shadow 0.2s cubic-bezier(0.4, 0, 1, 1), background-color 0.2s cubic-bezier(0.4, 0, 0.2, 1)",
lineHeight: "1.42857143",
textAlign: "center",
whiteSpace: "nowrap",
verticalAlign: "middle",
touchAction: "manipulation",
cursor: "pointer",
"&:hover,&:focus": {
color: "#FFFFFF",
backgroundColor: grayColor,
boxShadow:
"0 14px 26px -12px rgba(153, 153, 153, 0.42), 0 4px 23px 0px rgba(0, 0, 0, 0.12), 0 8px 10px -5px rgba(153, 153, 153, 0.2)"
},
"& .fab,& .fas,& .far,& .fal,& .material-icons": {
position: "relative",
display: "inline-block",
top: "0",
fontSize: "1.1rem",
marginRight: "4px",
verticalAlign: "middle"
},
"& svg": {
position: "relative",
display: "inline-block",
top: "0",
width: "18px",
height: "18px",
marginRight: "4px",
verticalAlign: "middle"
},
"&$justIcon": {
"& .fab,& .fas,& .far,& .fal,& .material-icons": {
marginRight: "0px",
position: "absolute",
width: "100%",
transform: "none",
left: "0px",
top: "0px",
height: "100%",
lineHeight: "41px",
fontSize: "20px"
}
}
},
fullWidth: {
width: "100%"
},
谢谢您的帮助:)我讨厌在样式上浪费太多时间:'(
答案 0 :(得分:0)
也许您可以尝试这种方式。制作一个.css文件,并在其中放置以下代码
.buttonW {
width: "100px" !important;
height: "30px" !important;
}
将css文件导入组件的顶部
并分配
className="buttonW"
答案 1 :(得分:0)
确保正确导入CSS文件...
如果是这样,请将您的按钮更改为类似的内容。
<Button
className="buttonW"
component={Link}
color="success"
size="lg"
to="/album-carousel-page"
>
Galeria
</Button>
然后在CSS中添加句点“。”。在班级名称之前
.buttonW {
width: "100px",
height: "30px"}
.. 这应该对您有用。
如果全部失败,则可以使用内联样式,如下所示。
<Button
className="buttonW"
style={{height: '30px', width : '100px'}}
component={Link}
color="success"
size="lg"
to="/album-carousel-page"
>
祝你好运!