How to change title position in react js?

Hi Friends πŸ‘‹,

Welcome To aHoisting!

To change title position in react js, you can set width="100" height="100" in <svg>. It will change title position in react js.

Today, I am going to show you, how to change title position in react js.

Table of contents

  • Install and create a new React app.
  • Import react component.
  • Create a Component.

Let’s start with the first step.

Step 1: Install and create a new React app.

First you have to install the React project. You should use create-react-app command to create a new React project.

npx create-react-app my-app
cd my-app
npm start

Step 2: Import react component.

After installing, you have to import your React component.

Step 3: Create a Component.

You can use width="100" height="100" to change title position in react js.

Change title position example.

The below code is an example of a React. You have to import react and set width="100" height="100" in <svg> to change title position in react js.

App.js


import React from 'react';
import Tooltip from './Tooltip';

const App = () => {
  return (
    <div style={{ padding: '50px' }}>
      <Tooltip position="top" text="Tooltip on top">
        <button>Hover me (Top)</button>
      </Tooltip>
      <Tooltip position="right" text="Tooltip on right">
        <button>Hover me (Right)</button>
      </Tooltip>
      <Tooltip position="bottom" text="Tooltip on bottom">
        <button>Hover me (Bottom)</button>
      </Tooltip>
      <Tooltip position="left" text="Tooltip on left">
        <button>Hover me (Left)</button>
      </Tooltip>
    </div>
  );
};

export default App;

App.css

/* Tooltip.css */
.tooltip-container {
  position: relative;
  display: inline-block;
}

.tooltip-text {
  visibility: hidden;
  background-color: #ed2828;
  color: #fff;
  text-align: center;
  border-radius: 4px;
  padding: 5px;
  position: absolute;
  z-index: 1;
  white-space: nowrap;
}

.tooltip-container:hover .tooltip-text {
  visibility: visible;
}

/* Position variants */
.tooltip-top {
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 8px;
}

.tooltip-right {
  top: 50%;
  left: 100%;
  transform: translateY(-50%);
  margin-left: 8px;
}

.tooltip-bottom {
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 8px;
}

.tooltip-left {
  top: 50%;
  right: 100%;
  transform: translateY(-50%);
  margin-right: 8px;
}

Tooltip.js

import React from 'react';
import './App.css';

const Tooltip = ({ position = 'top', text, children }) => {
  return (
    <div className="tooltip-container">
      {children}
      <span className={`tooltip-text tooltip-${position}`}>{text}</span>
    </div>
  );
};

export default Tooltip;

In the above code example, I have used the width="100" height="100" to change title position in react js.

Check the output of the above code.

React, title, position

All the best πŸ‘