content logo

React Buttons:

Colorful React Buttons with Dropdown List and Hover Effect

The button we put in this post has a drop-down list. This button is green and its title is white. Clicking on the arrow to the right of the button creates a black-colored drop-down list below the button. The titles in this drop-down list are white. To close the drop-down list, just click the green button on the arrow icon again. The drop-down list also has a hover format.

#

Free React Button Code

#

React Drop Down List

#

CSS Colorful Buttons Code

#

React Buttons Color Change

<!-- This script got from frontendfreecode.com -->
<div id="app"></div><a style="font-size: 8pt; text-decoration: none" target="_blank" href="http://frontendfreecode.com">Free Frontend</a>
                                                                            
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Overpass Mono", monospace;
}
.btn {
  -webkit-appearance: none;
     -moz-appearance: none;
          appearance: none;
  font-family: "Overpass Mono", monospace;
  border: 0;
  float:left;
  font-size: 12px;
  cursor: pointer;
  background: #0CCE6B;
  color: #FFFFFF;
  min-height: 50px;
  min-width: 120px;
  border-radius: 10px;
  transition: background 300ms ease-in-out;
  outline: 0;
  position: relative;
  text-align: center;
  margin-right: 10px;
  margin-bottom: 10px;
}
.btn--secondary {
  background-color: #FF6B6B;
}
.btn--dropdown {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 20px;
}
.btn__trigger {
  height: 50px;
  min-width: 50px;
  background: rgba(0, 0, 0, 0.07);
  border-radius: 0 10px 10px 0;
  position: relative;
}
.btn__trigger:after {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  width: 0;
  height: 0;
  border-top: 8px solid white;
  border-right: 6px solid transparent;
  border-bottom: 0 solid transparent;
  border-left: 6px solid transparent;
  content: "";
}
.btn:hover {
  background: #0bb65e;
}

.dropdown {
  position: absolute;
  top: 60px;
  left: 0;
  min-width: 150px;
  background: #1b1b1b;
  border-radius: 10px;
  text-align: left;
  overflow: hidden;
}
.dropdown li {
  padding: 10px 15px;
  transition: background 300ms ease-in-out;
}
.dropdown li:hover {
  background: #282828;
}
class App extends React.Component {
  render() {
    function Dropdown(props) {
      const options = [
      {
        key: 0,
        text: `Blue` },
      {
        key: 1,
        text: `Green` },
      {
        key: 2,
        text: `Red` }];
      return /*#__PURE__*/(
        React.createElement("ul", { className: "dropdown" },
        options.map(option => /*#__PURE__*/React.createElement("li", { key: option.key }, option.text))));
    }
    function Button(props) {
      const btnClass = `btn ${props.options && `btn--dropdown` || props.level === `secondary` && `btn--secondary`}`;
      const [dropdown, setDropdown] = React.useState(false);
      const toggle = () => setDropdown(!dropdown);
      return /*#__PURE__*/(
        React.createElement("button", { className: btnClass },
        props.content,
        props.options && /*#__PURE__*/
        React.createElement("div", { className: "btn__trigger", onClick: toggle }),
        dropdown && /*#__PURE__*/
        React.createElement(Dropdown, null)));
    }
    return /*#__PURE__*/(
      React.createElement(React.Fragment, null, /*#__PURE__*/
      React.createElement(Button, { options: false, content: "Primary" }), /*#__PURE__*/
      React.createElement(Button, { options: false, level: `secondary`, content: "Secondary" }), /*#__PURE__*/
      React.createElement(Button, { options: true, content: "Button" })));
  }}
ReactDOM.render( /*#__PURE__*/React.createElement(App, null), document.getElementById("app"));
<link href="https://fonts.googleapis.com/css?family=Overpass+Mono&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/16.8.6/umd/react.production.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.8.6/umd/react-dom.production.min.js'></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- This script got from frontendfreecode.com -->

<link href="https://fonts.googleapis.com/css?family=Overpass+Mono&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/16.8.6/umd/react.production.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.8.6/umd/react-dom.production.min.js'></script>
<style>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Overpass Mono", monospace;
}
.btn {
  -webkit-appearance: none;
     -moz-appearance: none;
          appearance: none;
  font-family: "Overpass Mono", monospace;
  border: 0;
  float:left;
  font-size: 12px;
  cursor: pointer;
  background: #0CCE6B;
  color: #FFFFFF;
  min-height: 50px;
  min-width: 120px;
  border-radius: 10px;
  transition: background 300ms ease-in-out;
  outline: 0;
  position: relative;
  text-align: center;
  margin-right: 10px;
  margin-bottom: 10px;
}
.btn--secondary {
  background-color: #FF6B6B;
}
.btn--dropdown {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 20px;
}
.btn__trigger {
  height: 50px;
  min-width: 50px;
  background: rgba(0, 0, 0, 0.07);
  border-radius: 0 10px 10px 0;
  position: relative;
}
.btn__trigger:after {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  width: 0;
  height: 0;
  border-top: 8px solid white;
  border-right: 6px solid transparent;
  border-bottom: 0 solid transparent;
  border-left: 6px solid transparent;
  content: "";
}
.btn:hover {
  background: #0bb65e;
}

.dropdown {
  position: absolute;
  top: 60px;
  left: 0;
  min-width: 150px;
  background: #1b1b1b;
  border-radius: 10px;
  text-align: left;
  overflow: hidden;
}
.dropdown li {
  padding: 10px 15px;
  transition: background 300ms ease-in-out;
}
.dropdown li:hover {
  background: #282828;
}
</style>

</head>
<body>
<div id="app"></div><div id="bcl"><a style="font-size:8pt;text-decoration:none;" href="http://www.devanswer.com">Free Frontend</a></div>
<script>
class App extends React.Component {
  render() {
    function Dropdown(props) {
      const options = [
      {
        key: 0,
        text: `Blue` },
      {
        key: 1,
        text: `Green` },
      {
        key: 2,
        text: `Red` }];
      return /*#__PURE__*/(
        React.createElement("ul", { className: "dropdown" },
        options.map(option => /*#__PURE__*/React.createElement("li", { key: option.key }, option.text))));
    }
    function Button(props) {
      const btnClass = `btn ${props.options && `btn--dropdown` || props.level === `secondary` && `btn--secondary`}`;
      const [dropdown, setDropdown] = React.useState(false);
      const toggle = () => setDropdown(!dropdown);
      return /*#__PURE__*/(
        React.createElement("button", { className: btnClass },
        props.content,
        props.options && /*#__PURE__*/
        React.createElement("div", { className: "btn__trigger", onClick: toggle }),
        dropdown && /*#__PURE__*/
        React.createElement(Dropdown, null)));
    }
    return /*#__PURE__*/(
      React.createElement(React.Fragment, null, /*#__PURE__*/
      React.createElement(Button, { options: false, content: "Primary" }), /*#__PURE__*/
      React.createElement(Button, { options: false, level: `secondary`, content: "Secondary" }), /*#__PURE__*/
      React.createElement(Button, { options: true, content: "Button" })));
  }}
ReactDOM.render( /*#__PURE__*/React.createElement(App, null), document.getElementById("app"));
</script>

</body>
</html>
Preview