JSX/CSS: the text on the button is positioned outside of the button in Chrome browser

As I work on styling a React component using CSS, I noticed that I'm getting different results in Chrome and Firefox:

Firefox (which is the desired behavior for both): https://i.sstatic.net/Q0LSD.png

Chrome: https://i.sstatic.net/s2MWJ.png

While I'm not overly concerned about matching the display exactly between the two browsers, I do want it to look presentable on Chrome as well. It seems like Chrome is interpreting the button text as a separate element appearing after the button. I have set the white background to be visible for the question, but it will eventually be transparent, so there's no need to address that specifically.

I currently utilize normalize.css without any vendor prefixes, as I'm not very familiar with them yet (any simple resources to learn more about this would be greatly appreciated!).

Here's the JSX for the entire component (with the class "slide__caption__button" as my main concern):

    <div className = "slide">

    <img className = "slide__image" src = {this.chooseImage()}></img>
    <div className = "slide__caption"
      onMouseEnter = {() => {
        this.props.pausingSlideshow();
      }}
      onMouseLeave = {() => {
        this.props.unpausingSlideshow();
        setTimeout(this.props.changeSlide, 0);
      }}
      >
      <p>{this.props.caption}</p>
        <br />
      <button
        className = "slide__caption__button"
        onClick = {this.sendTo.bind(this, this.props.buttonHref)}
      >
        <span>{this.props.buttonText}</span>
      </button>

      {/* slide chooser */}
      <div className = "chooser">
        {
          this.props.slidesLength.map((index) => {
            return (
              <div
                key = {index}
                className = "chooser__button"
                onClick = {this.props.goToSlide.bind(this, index)}
                >
                  o
              </div>
              );
            })
          }
      </div>

    </div>
  </div>

And here's my CSS styling:

    .slide {
      position: absolute;
      background: white;
      height: 100vh;
      width: 100vw;
    }

    .slide__image {
      opacity: 0.5;
      object-fit: cover;
      width: 100%;
      min-height: 100%;
    }
    // mobile
    .slide__caption {
      display: flex;
      flex-direction: column;
      justify-content: center;

      position: absolute;
      top: 20%; bottom: 0; left: 0; right: 0;
      font-weight: 600;
      margin: auto;
      width: 40%;
      height: 20%;
      background: white;
      border-radius: 1rem;
      text-align: center;
      text-shadow: -2px 2px 2px $cream, 2px -2px 2px $cream, -2px -2px 2px $cream, 2px 2px 2px $cream;
      color: #112233;
    }

    .slide__caption__button {
      position: relative;
      padding: 1rem;
      background: purple;
      border: 1px solid #112233;
      border-radius: 3rem;
      color: white;
      box-shadow: 0 2px 2px grey;
      margin: auto;
    }
    .slide__caption__button:hover {
      cursor: pointer;
      box-shadow: none;
      background: lighten(purple, 10%);
    }
    .chooser {
      display: flex;
      justify-content: center;
    }
    .chooser__button {
      color: transparent;
      width: .8rem;
      height: .8rem;
      border: solid 1px $dark;
      border-radius: 1rem;
      background: lighten($dark, 10%);
      text-shadow: none;
      opacity: .4;
      margin: 2rem .6rem;
    }
    .chooser__button:hover {
      cursor: pointer;
      background: lighten($dark, 40%);
    }

    // desktop
    @media (min-width: $desktop-breakpoint) {
      .slide__caption {
        top: 0;
        bottom: 20%;
      }
    }

Answer №1

Although I couldn't identify the root cause of the issue, I managed to come up with a solution by changing the button tag to a div, which surprisingly resolved the problem. :S

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to apply the addClass method to a list element

I've been searching for a solution to this issue for some time now, and while I believed my code was correct, it doesn't appear to be functioning as expected. HTML <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js ...

Updating the CSS style of an inner DIV using JavaScript

Can you provide guidance on how to modify the background color using JavaScript for the different styles listed below? i) Internal Style sheet and/or ii) External Style sheet I am currently working with the card deck slide show available at https://githu ...

The dispatch function of useReducer does not get triggered within a callback function

Can anyone assist me with this issue I am facing while using React's useReducer? I'm trying to implement a search functionality for items in a list by setting up a global state with a context: Context const defaultContext = [itemsInitialState, ...

Using Angular's Hostbinding feature to toggle a button and change the background color of the

How can I change the background color of a page and all child components when a toggle button is clicked? Can this be accomplished using HostBinding in Angular? <div class="mainbody" [class.bgnight]="haveClass"> <button (click) ...

Tips on customizing the background color of a MaterialUI form dialog box while ensuring that the text field color remains

Is there a way to change the background color of the Material-UI form dialog box without affecting the text-field color? I need some guidance on how to achieve this. https://i.stack.imgur.com/iOa2X.png ...

Unable to get click function to work with multiple div elements

Using four div elements, I have implemented a feature where clicking on the first div causes all other div elements to change opacity. This is working correctly. However, I would like the opacity of the first div to remain unchanged when moving to another ...

fixed footer with fixed height on parent container

I have successfully implemented a sticky footer on my web pages by following specific instructions. http://css-tricks.com/snippets/css/sticky-footer/ The recommended approach includes using min-height:100% and not specifying the height property. .page-w ...

Quick tip: Showing a default Font Awesome icon in Vue, Angular, or React when the desired icon is not found

Utilizing the <fa-icon> fontawesome component, I implement the library approach as follows: export const faIconsDefinitionsToRegister: IconDefinition[] = [ ...proRegularFaIcons, ...proSolidFaIcons, ...proLightFaIcons, ...proThinFaIcons, ... ...

Error retrieving the potsdamer_platz_1k.hdr file. Unable to load the file

Currently, I am in the process of developing a custom t-shirt website using Three.js, but I have come across a persistent error while running the project. The same error occurs when attempting to run the project live as well. Despite including the file "pl ...

Creating trendy designs with styled components: A guide to styling functional components as children within styled parent components

I am looking to enhance the style of a FC styled element as a child inside another styled element. Check out the sandbox example here const ColorTextContainer = styled.div` font-weight: bold; ${RedBackgroundDiv} { color: white; } `; This resul ...

The mobile version of the page has extra white space at the bottom

I have a responsive design that is working well, but I am experiencing an issue on mobile devices where there is white space at the bottom of the page. * { margin: 0; padding: 0; box-sizing: border-box; } html { scroll-behavior: smooth; ...

Implementing a combination of Webpack loaders to convert SVG files into React components

My goal is to blend various Webpack loaders together in order to load my SVG assets, transform them for inline use, and then convert the result into a functional React component for application usage. const path = require('path') module.exports ...

Combining a Hyperlink with a Table Target

I'm currently trying to find a way to target both a table cell (TR > TD) and a hyperlink within the same row. Here's an example of the HTML: <div class="CourseLayout"> <table width="100%" border="0" cellpadding="0" cellspacing="0"&g ...

Which is Better for Creating DropDown Menus: CSS or JavaScript?

Starting a new project that involves dropdown menus with categories and subcategories within them. I'm curious about the advantages of using CSS3 only menus compared to traditional JavaScript ones. There are several jQuery menu options available as we ...

What steps do I need to follow in order to add an axis label to my chart?

I'm working on creating a bar chart using the @devexpress/dx-react-chart-material-ui library in React and here's the code I have so far: import React from 'react' import { Chart, ArgumentAxis, ValueAxis, BarSeries } from '@devexpre ...

jquery expanding the width of the final element

Is there a way to increase the width of the last 'th' in a string? I want it to be the current width plus 20px. Here is the code on Fiddle var header="<th id='tblHeader_1' style='width: 80px;'><span>Id</span&g ...

Unable to create 'WebSocket' instance: The provided URL, '[object Object]', is not valid

I attempted to establish a connection to the websocket in React router in order to retrieve data. However, I encountered an error message Uncaught SyntaxError: Failed to construct 'WebSocket': The URL '[object Object]' is invalid. in th ...

Fetching initial values from API calls in React Draft Wysiwyg

Hey there, I'm new to this. I am trying to populate my react-draftjs-wysiwyg initial value from a database using an API call inside a useEffect hook. Here's the code snippet: const [journal,setJournal] = useState([]) useEffect(() => { const g ...

Find your favorite artist on Spotify through the search function

Recently, I stumbled upon this intriguing demo showcasing how to search for an artist using the Spotify API. However, despite several attempts, I have been unable to make it function properly. Can anyone provide any tips or guidance on making this work suc ...

Exploring Next.js: A guide to implementing a GET request with React Query

Looking to integrate React Query for data fetching from a server. Previously, I was using Axios to fetch the REST API. I've created a custom hook for fetching and now want to incorporate it with React Query. However, when trying to destructure t ...