cssbuttontexttailwind-css

How to style text in the <button> tag


Im trying to create button with css.But text is in the right side of the button, when i wanna replace it in the left side.Then i tryed to fix problem with tailwind styles in the button class,but i cant fix it.I tryed to fix it with GPT but it didnt help me.

There is my ReactJs code

import React from "react";
export default function About() {
  return (
    <div className="bg-gray-50 min-h-screen flex items-center px-16 w-full overflow-hidden">
      <div className="flex items-center justify-between">
        <img className="w-[30%] animate-phone" src="Iphone.png" alt="" />
        <div className="w-full max-w-[700px]">
          <div className="text-[#1e2238]">
            <h1 className="font-Sara mb-10 text-5xl lg:text-7xl">About Us</h1>
            <h3 className="font-Dsc">
              Используйте уникальные возможности дополненной реальности (AR) для
              проекции виртуальных объектов в реальное пространство. Наше
              приложение для мобильных телефонов позволяет вам создавать
              захватывающие AR проекции, превращая ваше устройство в мощный
              инструмент для визуализации и взаимодействия с виртуальными
              элементами. Погрузитесь в удивительный мир AR Projection прямо
              сейчас!
            </h3>
            <div>
              <div>
                <button className="button"><span>There</span></button>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}

There is my CSS styles

.button {
  position: relative;
  border: none;
  background-color: #1e2238; /* Set your desired button background color */
  color: white; /* Set your desired button text color */
  padding: 10px 20px; /* Adjust padding as needed */
  border-radius: 0.375rem;
  padding-right: 0px;
  z-index: 1; /* Ensure the button text is above pseudo-elements */
}

.button span {
  position: relative; /* Ensure relative positioning */
  left: 0; /* Reset left positioning */
}

.button::before,
.button::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 100%;
  background-color: rgb(252, 68, 12); /* Set your desired pseudo-element background color */
  transition: 0.4s ease; /* Transition effect for the pseudo-element */
  border-radius: 0.375rem;
  color: white; /* Set text color to white */
  z-index: -1; /* Ensure the pseudo-elements are below the button text */
}

.button::before {
  transform: skew(90deg);
  transform-origin: top left;
}

.button:hover::before,
.button:hover::after {
  width: 100%; /* Expand the pseudo-element width on hover */
}


Solution

  • Remove padding-right

    .button {
      position: relative;
      border: none;
      background-color: #1e2238; /* Set your desired button background color */
      color: white; /* Set your desired button text color */
      padding: 10px 20px; /* Adjust padding as needed */
      border-radius: 0.375rem;
      /* padding-right: 0px; */
      z-index: 1; /* Ensure the button text is above pseudo-elements */
    }