最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I style react semantic components? - Stack Overflow

programmeradmin9浏览0评论

How can I add CSS for react semantic UI ? I am using create react app. I have installed semantic-ui-react and CSS CDN: /?fbclid=IwAR3ZBaJfpxHGiNcAvophLp7IAPO-gHZfDvSOLs8h-n0-_29ncPoOdjwCX7o#content-delivery-network-cdn

loginForm.js:

import React from "react";
import { Button, Form, Header } from "semantic-ui-react";
import styles from './loginForm.css';

const LoginForm = () => (
<Form className={styles.formStyle}>
<Button className={styles.buttonStyle}>Login</Button>
</Form>
);

export default LoginForm;

loginForm.css:

.formStyle {
margin-left: 500px; 
margin-top: 100px;
width: 550px;
}

.buttonStyle {
border-radius: 18px;
width: 200px;
background-color:#3865FE;
}

Above CSS code is not working for loginForm.js why so ? I also tried following :

<Form style={styles.formStyle}>
    <Button style={styles.buttonStyle}>Login</Button>
  </Form>

Above code is also not working.

How can I add CSS for react semantic UI ? I am using create react app. I have installed semantic-ui-react and CSS CDN: https://react.semantic-ui./usage/?fbclid=IwAR3ZBaJfpxHGiNcAvophLp7IAPO-gHZfDvSOLs8h-n0-_29ncPoOdjwCX7o#content-delivery-network-cdn

loginForm.js:

import React from "react";
import { Button, Form, Header } from "semantic-ui-react";
import styles from './loginForm.css';

const LoginForm = () => (
<Form className={styles.formStyle}>
<Button className={styles.buttonStyle}>Login</Button>
</Form>
);

export default LoginForm;

loginForm.css:

.formStyle {
margin-left: 500px; 
margin-top: 100px;
width: 550px;
}

.buttonStyle {
border-radius: 18px;
width: 200px;
background-color:#3865FE;
}

Above CSS code is not working for loginForm.js why so ? I also tried following :

<Form style={styles.formStyle}>
    <Button style={styles.buttonStyle}>Login</Button>
  </Form>

Above code is also not working.

Share Improve this question asked Nov 14, 2018 at 5:00 fun jokerfun joker 1,7277 gold badges34 silver badges54 bronze badges 2
  • 1 facebook.github.io/create-react-app/docs/… according to this, everything should works fine unless your cra app is outdated, did you try to use your css module without semantic ? Maybe semantic override your css, thus it's working but not visible – Fabien Greard Commented Nov 14, 2018 at 5:19
  • @FabienGreard So what is the fix for this problem ? I am using create react app – fun joker Commented Nov 14, 2018 at 5:21
Add a ment  | 

1 Answer 1

Reset to default 6

Actually you're setting the value of className incorrectly. Here is the modified version of your code.

import React from "react";
import { Button, Form, Header } from "semantic-ui-react";
import from './loginForm.css';

const LoginForm = () => (
  <Form className='formStyle'>
    <Button className='buttonStyle'>Login</Button>
  </Form>
);

export default LoginForm;

and for loginForm.css

.ui.form.formStyle  {
  margin-left: 300px ; 
  margin-top: 100px ;
  width: 550px ;
  height: 400px;
 }

.ui.button.buttonStyle {
  border-radius: 18px;
  width: 200px;
  background-color:#3865FE;
}

thanks @funJoker for suggesting me how to edit semantic-ui style.

发布评论

评论列表(0)

  1. 暂无评论