简体   繁体   English

如何在另一个元素 REACT 上更改元素 onClick 的样式?

[英]How to change style of an element onClick at another element REACT?

I want to change .page-header when i click on standard-basic.我想在单击标准基本时更改 .page-header。 I tried to do this:我试图这样做:

#standard-basic:focus ~ .page-header{
  display: none;
}

But it can't help me.但它帮不了我。 How can change style of page-header in react or maybe just in js?如何在反应中或仅在 js 中更改页眉的样式? I use functional component我使用功能组件

 <span id="pageHeader" className="page-header">TechPrice</span>
  <form
    className={props.classes.root}
    noValidate
    autoComplete="off"
    className="search-form"
  >
    <TextField className="textField" id="standard-basic" label="Поиск" />
    <SearchIcon className="search-icon" />
  </form>

I think you need to use style object and set display prop to none depend on some state我认为您需要使用样式对象并将显示道具设置为无取决于某些状态

Example:例子:

<span id="pageHeader" style={{"display": `isVisible ? "block" : "none"`}}>TechPrice</span>

There is no parent selector in CSS/CSS3 . CSS/CSS3没有父选择器

Please read this topic: Is there a CSS parent selector?请阅读此主题: 是否有 CSS 父选择器?

To achieve your goal you have to use JavaScript/React/any other framework/library为了实现你的目标,你必须使用JavaScript/React/any other framework/library

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何更改 React 中元素的样式? - How to change the style of an element in React? React:如何根据另一个 JSX 元素更改样式属性? - React: how to change the style property of one JSX element based on another? 在 React 中,如何更改在迭代中创建的一个元素的类名,即另一个元素的 onclick? - In React, how do I change the classname of one element that was created in an iteration, onclick of another element? 如何使用 react &#39;onClick&#39; 改变元素的 style.backgroundColor - How to use reacts 'onClick' to change a style.backgroundColor of an element 无法使用onClick更改数组元素的样式 - Cannot change style of an array element with onClick 如何根据其他元素样式更改HTML元素的样式? - How to change style of HTML element depending on another elements style? 在其他元素悬停时更改元素样式 - Change element style on hover of another element 如何检查元素是否具有特定样式以及是否具有样式更改其他元素的样式? - How to check if the element has certain style and if it has style change the style of another element? 如何使用React.js在Redux容器中更改onClick元素? - How to do onClick element change in Redux a container with React.js? 如何通过另一个元素的onClick事件更改div的backgroundPosition - How to change the backgroundPosition of a div with a onClick event from another element
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM