【发布时间】:2021-04-19 14:08:14
【问题描述】:
我制作了一个组件和一个 module.css,因为与我项目的其他输入相比,它具有特定 CSS 样式的输入。
这就是为什么我在全局 CSS 中为我的组件中的所有输入都设置了输入样式。
我已经用module.css 制作了几个组件,到目前为止,一切正常,但是对于这个特定的组件,我不知道为什么,module.css 没有应用,而是全局 CSS。
我的组件:
import React, { useState } from "react";
import style from "./searchBar.module.css";
const SearchBar = () => {
const [city, setCity] = useState("");
return (
<form className={style.searchBar}>
<div>
<label>Ville</label>
<input
type="text"
name="city"
placeholder="Où veux-tu jouer?"
value={city}
onChange={(e) => {
setCity(e.target.value);
}}
/>
</div>
<div>
<label>Sport</label>
<input />
</div>
<div>
<label>Nom</label>
<input />
</div>
<div>
<label>Type</label>
<select></select>
</div>
<button>Rechercher</button>
</form>
);
};
export default SearchBar;
CSS 模块:
.searchBar {
margin: 0 auto;
border: 1px solid var(--grey);
width: 74.37%; /* 937px; */
height: 14.91%; /* 72px; */
background-color: #fff;
border-radius: 42px;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding: 8px;
}
.searchBar input {
width: 100px;
height: 50px;
}
在以下屏幕截图中,您可以看到应用了全局 CSS 而不是 module.css。我错过了什么或做错了什么?
【问题讨论】:
标签: css reactjs css-selectors css-modules react-css-modules