简体   繁体   中英

How can I resize a button with css in ReactJS

我希望这些按钮具有相同的大小,但模板是根据内容字母配置的。

I want to make a button with a define width, but I have a template with the button component defined including styles, so when I try to modify the style of the button, it happened nothing, here is my code

Here is when I call the component in the react class

<Button
    className={classes.buttonW}
    component={Link}
    color="success"
    size="lg"
    to="/album-carousel-page"
 >
 Galeria
</Button>

The classname when I modify the css button

buttonW: {
  width: "100px",
  height: "30px"
}

And here is the code above the template original button (Very complex for my opinion)

  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%"
  },

Thank you for helping me :) I hate to lose too much time with styles :'(

Make sure you are importing your CSS file correctly...

If so, change your button to something like this.

<Button
    className="buttonW"
    component={Link}
    color="success"
    size="lg"
    to="/album-carousel-page"
 >
 Galeria
</Button>

Then in your CSS, prefix a period "." before the class name

.buttonW {
width: "100px",
height: "30px"}

.. this should work for you..

If all fails, you can then use inline styling as shown below.

<Button
    className="buttonW"
    style={{height: '30px', width : '100px'}}
    component={Link}
    color="success"
    size="lg"
    to="/album-carousel-page"
 >

Good luck!

May be you can try this way. Make a .css file and put the following code there

.buttonW {
  width: "100px" !important;
  height: "30px" !important;
}

Import that css file top of your component

and assign it

className="buttonW"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM