Persistent extra pixels found in CSS radiobutton group buttons that persist despite attempts to remove them

UPDATE: I have corrected the title of this post, as it was mistakenly taken from another post.

For the past few months, I've been working on a sports app using React. However, I am facing a minor cosmetic problem with my radio buttons. Despite my efforts to create a reproducible example, the bug does not appear in the code below. Luckily, a similar issue is present. Here are the buttons:

class App extends React.Component {
  constructor(props) { 
    super(props);
    
    this.state = {
      oneTwoFour: "1 Graph",
      quarter: "All"
    }
  } 
     
  handleQuarterChange = (event) => {
    this.setState({ quarter: event.target.value });
  };
  handleOneTwoFourChange = (event) => {
    this.setState({ oneTwoFour: event.target.value });
  }; 
     
  render() {
    
    const { oneTwoFour, quarter } = this.state;
  
    const oneTwoFourOptions = ["1 Graph", "2 Graphs", "4 Graphs"];
    const oneTwoFourButtons =
      <form>
          <div className="blg-buttons">
              {oneTwoFourOptions.map((d, i) => {
                  return (
                      <label key={'onetwofour-' + i}>
                          <input
                              type={"radio"}
                              value={oneTwoFourOptions[i]}
                              checked={oneTwoFour === oneTwoFourOptions[i]}
                              onChange={this.handleOneTwoFourChange}
                          />
                          <span>{oneTwoFourOptions[i]}</span>
                      </label>
                  )
              })}
          </div>
       </form>; 

    const quarterOptions = ["All", "OT", "Half 1", "Half 2", "Q1", "Q2", "Q3", "Q4"];
    const quarterButtons = 
      <form>
          <div className="blg-buttons">
              {quarterOptions.map((d, i) => {
                  return (
                      <label key={'quarter-' + i} style={{"width":"50%"}}>
                          <input
                              type={"radio"}
                              value={quarterOptions[i]}
                              checked={quarter === quarterOptions[i]}
                              onChange={this.handleQuarterChange}
                          />
                          <span>{quarterOptions[i]}</span>
                      </label>
                  )
              })}
          </div>
      </form>; 
    
    return(
      <div>
        <div style={{"width":"25%", "float":"left", "margin":"0 auto", "padding":"5px"}}>
          {quarterButtons}
        </div>

        <div style={{"width":"25%", "float":"left", "margin":"0 auto", "padding":"5px"}}>
            {oneTwoFourButtons}
        </div>
      </div>
    );
  }
}

ReactDOM.render(
  <App />,
  document.getElementById('root')
);
.blg-buttons {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
}

.blg-buttons input[type=radio] {
    visibility:hidden;
    width:0px;
    height:0px;
    overflow:hidden;
}

.blg-buttons input[type=radio] + span {
    cursor: pointer;
    display: inline-block;
    vertical-align: top;
    line-height: 1;

    font-size: 1.0vw;
    padding: 0.5vw;
    border-radius: 0.35vw;
    border: 0.15vw solid #333;

    width: 90%;
    text-align: center;
    color: #333;
    background: #EEE;
}

.blg-buttons input[type=radio]:not(:checked) + span {
    cursor: pointer;
    background-color: #EEE;
    color: #333;
}

.blg-buttons input[type=radio]:not(:checked) + span:hover{
    cursor: pointer;
    background: #888;
}

.blg-buttons input[type=radio]:checked + span{
    cursor: pointer;
    background-color: #333;
    color: #EEE;
}

.blg-buttons label {
    line-height: 0;
    font-size: calc(0.85vw);
    margin-bottom: 0.1vw;
    width: 90%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.13.0/d3.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.2.0/umd/react.development.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.2.0/umd/react-dom.development.js"></script>


<div id='root'>
  Let's Make It Work!
</div>

Here is an observation screenshot from my app's buttons' inspection (also available at bigleaguegraphs.com/nba/shotcharts-pro), indicating the actual error I'm experiencing:

https://i.sstatic.net/VYMJl.png The issue lies in the button overhang that is unrelated to padding or margin. I have carefully reviewed every aspect of CSS styling for my radio buttons, yet I can't explain why the element extends a bit further to the right.

Surprisingly / unfortunately, this doesn't occur in the above example. However, a separate issue in the example causes the label element to extend slightly upwards instead of sideways, which I cannot resolve.

I would greatly appreciate any assistance in eliminating these extra pixels on the button group!

Answer №1

.blg-buttons {
    display: flex;
    justify-content: center;
    /* flex-wrap: wrap;  you shouldn't need this */
    flex-direction: column;
    flex: 1;
}

 .blg-buttons label {
    display: flex;
    line-height: 0;
    font-size: 0.85vw;
    flex: 1;
    align-items: center;
    margin-bottom: 5px; /* you don't need that 0.1vw */
    font-weight: 700;
 }

.blg-buttons input[type=radio]+span {
    cursor: pointer;
    display: flex;
    flex: 1;
    justify-content: center;
    vertical-align: top;
    line-height: 1;
    font-size: 1vw;
    padding: .5vw;
    border-radius: .35vw;
    border: .15vw solid #333;
    width: 90%;
    /* text-align: center; <-- you don't need this with flex */
    color: #333;
    background: #eee;
}

It is recommended to utilize flexbox whenever possible. By experimenting on your website, I substituted .nba_scp_cp_rbs with .blg-buttons (assuming it's correct). Avoid specifying widths like width: 90%, as with flexbox, explicit width definitions are often unnecessary. Instead, use padding and margins for sizing elements to prevent unusual sizing bugs like the one you encountered :)

Check out this image for proof of it working

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

Concealing columns in DataTables based on designated screen sizes

Issue I am facing a challenge with two DataTables — one with five columns and the other with four columns. My goal is to find a solution for hiding certain columns based on specific screen widths. Approaches I've Tested While resizing the browser ...

Upon successful registration, users will be automatically redirected to their profile page

Having trouble with the redirection to the login page from my profile page, which is an HTML file and the main page is the login page. I've tried redirecting to both pages, but it always lands in the catch block whenever a redirect is attempted. angu ...

Using jQuery Flot to dynamically load data onto the x-axis from an array

I have a jQuery flot graph that loads the x-axis data as follows: xaxis: { tickColor: 'transparent', tickDecimals: 0, ticks: ticks }, When I manually set the ticks variable like this, everything works fine and the x-axis displays the 7 da ...

How come the values (quantity, cost, total) are being stored as zero upon submission, despite successfully transferring the values from the dropdown list to the input using JavaScript?

1. Explanation I am transferring the quantity and price of a product from a dropdown list to input fields. Then I calculate the sum of quantity * price in the third input field. If the quantity or price changes, the sum is automatically updated and disp ...

Manually sending the form via Ajax for submission

I'm facing an issue where I am trying to utilize ajax to call a servlet upon form submission. However, the ajax call is not being triggered and the page ends up reloading. To solve this problem, I have set up a manual trigger for the form submission, ...

Is the bearer terminology used for the authentication token or is it meant for a separate token?

In my MEVN application, I am incorporating JWT tokens and currently exploring how to transmit authentication tokens via axios. It is common practice to add "Bearer " before the token and have the server strip off "Bearer " to access the token's conten ...

Ways to eliminate text following a string substitution

When running the code below with keys assigned to summer, spring, fall, and winter, the output for ins would be: ['req.body.summer, req.body.spring, req.body.fall, req.body.winter'] I need to eliminate the surrounding string from the replace co ...

Excessive messages are being sent to the child process from the nodejs/electron stream

When trying to send messages from an Electron frontend to a C++ child process via stdin upon button press, I encountered an issue where multiple identical sends were triggered with each click. What is the recommended approach to prevent redundant messages ...

Using an imported material icon as a background in JSS styling

I have implemented a draggable dialog component in React-mui with a resizable box feature. const styles = theme => ({ resizable: { position: "relative", "& .react-resizable-handle": { position: "absolute" ...

What are the implications of incorporating listeners in redux action creators?

While developing my app, I have a feature that involves constantly monitoring location changes and updating the store accordingly. One question that has arisen is whether it would be beneficial to keep the listeners inside the action creator rather than th ...

Typescript's Nested Type Assignments

Simply put, I'm making an API call and receiving the following data: { getUserInfo: { country: 'DE', email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3c48594f487c59445d514c5059125f5351">[e ...

Routing in Next.js to create custom URL slugs for usernames, like (site.com/username), is a

I have a requirement to create username pages on my website, where each username will have its own page like site.com/jack The current folder structure I am using is pages > [user] > index.js, but this setup causes issues when someone tries to acces ...

The issue with jQuery click function seems to be limited to Firefox

After a long hiatus from posting here, I hope this isn't breaking any rules. For those who prefer visual examples, you can visit the live page at: The drop-down menu functions perfectly in IE, Chrome, and Safari, but seems to be causing issues in Fir ...

What's the process for including delivery charges in Stripe transactions?

I am facing an issue with Stripe where I am unable to incorporate delivery fees into my transactions. How can I successfully integrate this feature? let line_items = []; for (let productId of uniqIds) { const quantity = productsIds.filter(id => id == ...

The side button is not functioning properly on IE Edge

Objective: The button on the right side should be functional in the latest versions of IE, Chrome, and Firefox. Challenge: It currently works in Chrome and Firefox but not in Edge. The code is extracted from this webpage () and functions perfectly wel ...

Using CSS to style the last element in a set of dynamic content

I am currently working on targeting the last element in a dynamically generated content set. For instance, here is an example of how the generated content appears: <div class="block"> <div class="block-inner"> <div class="box"> ...

Maximizing Efficiency with React.js: Optimizing Value Calculation

Within my JSON, there are several fields that require calculation. I am unsure of the optimal location to perform these calculations. Currently, I have set them within: componentWillMount: function () { //Iterating over the JSON object } After calculat ...

Evaluation of jQuery code

Just starting out with jQuery and programming in general. I posted my first hour of work here and would appreciate some feedback on how to improve it. $(function() { function hideElements() //Hides specified elements on page load. { $("li.credentia ...

Utilizing JavaScript to trigger an email with PHP variables included

i am trying to pass a few php variables using a javascript trigger. Everything seems to be working with the variables, databases, and script but I am struggling with the PHP part. Here is my attempt at the PHP code, although it clearly has some issues. I ...

Removing a Dynamic Element in ReactJS

--CustomFieldSection.js-- import React, { Component } from 'react'; import CustomField from './CustomField.js'; class CustomFieldSection extends Component{ constructor(props){ super(props); this.stat ...