DEV Community

Cover image for React Basics~styling component/ inline_style
Ogasawara Kakeru
Ogasawara Kakeru

Posted on

React Basics~styling component/ inline_style

  • The inline style must be written in Javascript.

・The name of the property must be 'style'

・It makes no difference whether you set the style by dividing a value or by setting it directly.

・The property must be written in camel case,
like this fontWeight: "bold",.

・If we want to write property in CSS style(kebabcase),
We need to write it inside 'double quote' or 'single quote'.
This is an example "border-radius: 9999,.

・src/Example.js

import { useState } from "react";

const Example = () => {
  const [isSelected, setIsSelected] = useState(false);

  const clickHandler = () => setIsSelected((prev) => !prev);

  const style = {
    width: 120,
    height: 60,
    display: "block",
    fontWeight: "bold",
    "border-radius": 9999,
    cursor: "pointer",
    border: "none",
    margin: "auto",
    background: isSelected ? "pink" : "",
  };

  return (
    <>
      <button style={style} onClick={clickHandler}>
        Button
      </button>
      <div style={{ textAlign: "center" }}>{isSelected && "Clicked!"}</div>
    </>
  );
};

export default Example;

Enter fullscreen mode Exit fullscreen mode

・Befor pushing the button.

Image description

・After pushing the button.

Image description

Top comments (6)

Collapse
 
anis_mer_ profile image
Anis Mer_

Cool, thanks. Have you tried tailwindcss.com/docs/max-width? It's great and it'll save you a lot of time with css.

Collapse
 
kkr0423 profile image
Ogasawara Kakeru • Edited

I haven't tried Tailwind Css yet.
However, I have decided to use it in my development team's current project.
I'm looking forward to use it.

Thank you very much.

Collapse
 
anis_mer_ profile image
Anis Mer_

You're most welcome, Ogasawara. If you've any questions, feel at ease to reach out. I use it extensively. Happy to share tips.

Thread Thread
 
kkr0423 profile image
Ogasawara Kakeru

Oh! thank you for your support.

Collapse
 
kenny_ting_fbe47a1660c634 profile image
Kenny Ting

If you any question, Please leave a message.
I can help with Tailwind CSS

Thread Thread
 
kkr0423 profile image
Ogasawara Kakeru

I really thank you for your support.