Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
129 views
in Technique[技术] by (71.8m points)

javascript - !important inline styles in react

It's there a way to add inline styles with the !important override?

style={
  height: 20+'!important'
};

<div style={style}></div>

This isn't working as I would have hoped.

question from:https://stackoverflow.com/questions/23074748/important-inline-styles-in-react

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

20+'!important' is '20!important'.

When you just give a number, react adds "px" for you; but you're using a string, so you have to specify the unit. Also I'm pretty sure there needs to be a space between "!important" and whatever's to the left of it.

style={{ height: '20px !important' }};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...