content logo

React Popups:

Simple React Popup with Border

This pop-up opens by clicking on the button on the left side of the page. The pop-up itself is gray and the border is thin and green. The title of the pop-up is written in black. To close the pop-up, you can use the green button located in the middle of the pop-up. This button has a hover effect.

#

Free React Popup Code

#

Responsive Popup Code Example

#

HTML Simple Popup

#

CSS React Popup Border

<!-- This script got from frontendfreecode.com -->
<div id="content"></div><a style="font-size: 8pt; text-decoration: none" target="_blank" href="http://frontendfreecode.com">Free Frontend</a>
                                                                            
.popup {
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  background-color: rgba(0,0,0, 0.5);
}
.popup_inner {
  position: absolute;
  left: 25%;
  right: 25%;
  top: 25%;
  bottom: 25%;
  margin: auto;
  background: white;
  text-align: center;
  background: #ddd;
  border: 2px solid #4caf50;
  border-radius: 5px;
}
h4, button {
  margin-top: 40px;
}
const Popup = ({ text, closePopup }) => /*#__PURE__*/
React.createElement("div", { className: "popup" }, /*#__PURE__*/
React.createElement("div", { className: "popup_inner" }, /*#__PURE__*/
React.createElement("h4", null, text), /*#__PURE__*/
React.createElement("button", { className: "btn waves-effect waves-light", onClick: closePopup }, "close me")));
class App extends React.Component {
  constructor() {
    super();
    this.state = {
      showPopup: false };
  }
  togglePopup() {
    this.setState({
      showPopup: !this.state.showPopup });
  }
  render() {
    return /*#__PURE__*/(
      React.createElement("div", { className: "app" }, /*#__PURE__*/
      React.createElement("button", { onClick: () => this.togglePopup() }, "show popup"),
      this.state.showPopup ? /*#__PURE__*/
      React.createElement(Popup, {
        text: "Welcome to React Popup",
        closePopup: () => this.togglePopup() }) :
      null));
  }}
;
ReactDOM.render( /*#__PURE__*/
React.createElement(App, null),
document.getElementById('content'));
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css'>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.min.js'></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- This script got from frontendfreecode.com -->

<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css'>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.min.js'></script>
<style>
.popup {
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  background-color: rgba(0,0,0, 0.5);
}
.popup_inner {
  position: absolute;
  left: 25%;
  right: 25%;
  top: 25%;
  bottom: 25%;
  margin: auto;
  background: white;
  text-align: center;
  background: #ddd;
  border: 2px solid #4caf50;
  border-radius: 5px;
}
h4, button {
  margin-top: 40px;
}
</style>

</head>
<body>
<div id="content"></div><div id="bcl"><a style="font-size:8pt;text-decoration:none;" href="http://www.devanswer.com">Free Frontend</a></div>
<script>
const Popup = ({ text, closePopup }) => /*#__PURE__*/
React.createElement("div", { className: "popup" }, /*#__PURE__*/
React.createElement("div", { className: "popup_inner" }, /*#__PURE__*/
React.createElement("h4", null, text), /*#__PURE__*/
React.createElement("button", { className: "btn waves-effect waves-light", onClick: closePopup }, "close me")));
class App extends React.Component {
  constructor() {
    super();
    this.state = {
      showPopup: false };
  }
  togglePopup() {
    this.setState({
      showPopup: !this.state.showPopup });
  }
  render() {
    return /*#__PURE__*/(
      React.createElement("div", { className: "app" }, /*#__PURE__*/
      React.createElement("button", { onClick: () => this.togglePopup() }, "show popup"),
      this.state.showPopup ? /*#__PURE__*/
      React.createElement(Popup, {
        text: "Welcome to React Popup",
        closePopup: () => this.togglePopup() }) :
      null));
  }}
;
ReactDOM.render( /*#__PURE__*/
React.createElement(App, null),
document.getElementById('content'));
</script>

</body>
</html>
Preview