Button alignment issue in react

Having a bit of trouble with my code image here

I'm trying to make the button display justified

https://i.sstatic.net/uJYyA.png

I managed to justify the button as shown in this image, but it's not working in my React code

https://i.sstatic.net/dsIQt.png

Here's the code that's causing issues:

 <div className="hidden-xs buttons col-lg-12 col-md-12">
                    <button>Kartonnen brillen</button>
                    <button>Kartonnen brillen</button>
                    <button>Kartonnen brillen</button>

                    <button>Kartonnen brillen</button>
                    <div className="stretch-spacing-buttons"></div>
                    <button>Kartonnen brillen</button>
                    <button>Kartonnen brillen</button>
                    <button>Kartonnen brillen</button>

                    <button>Kartonnen brillen</button>
                    <button>Kartonnen brillen</button>
                    <div className="stretch-spacing-buttons"></div>

                </div>

CSS styling:

.buttons {
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    text-align: justify;
    -ms-text-justify: distribute-all-lines;
    text-justify: distribute-all-lines;
}

.stretch-spacing-buttons {
    width: 100%;
    display: inline-block;
    font-size: 0;
    line-height: 0;
}

Answer №1

Give this a shot: HTML:

<div class="buttons">
  <div class="first-row">
     <button>Cardboard glasses</button>
     <button>Cardboard glasses</button>
     <button>Cardboard glasses</button>
     <button>Cardboard glasses</button>
  </div>
  <div class="second-row">
     <button>Cardboard glasses</button>
     <button>Cardboard glasses</button>
     <button>Cardboard glasses</button>
     <button>Cardboard glasses</button>
     <button>Cardboard glasses</button>
  </div>
 </div>

CSS:

.first-row {
  display:grid;
  grid-template-columns:repeat(4, auto);
  justify-content: space-between;
}
.second-row{
  display:grid;
  grid-template-columns:repeat(5, auto);
  justify-content: space-between;
}

You can view the Codepen example here: https://codepen.io/sphr1313/pen/BOpWVg

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

Difficulty accessing `evt.target.value` with `RaisedButton` in ReactJS Material UI

My goal is to update a state by submitting a value through a button click. Everything works perfectly when using the HTML input element. However, when I switch to the Material UI RaisedButton, the value isn't passed at all. Can someone help me identif ...

Is it possible to nest multiple onClick events within each other?

I've been working on creating a pomodoro clock that includes both break and session timers. My approach involves using a single numpad to input data into each clock by nesting the 'click' event to set the time for each. The idea is to click ...

At a certain point, the scrolling iframe within the mobile app suddenly jumps back to the top of the page

Looking for some assistance with my HTML code. Here it is: <header class="bar-title"> <a class="button-prev" onclick="history.back(-1)">back</a> <h1 class="title">Page</h1> </header> <div style="overflow:auto;-we ...

What is the best way to horizontally align an element within a Material UI Grid item?

How do I align elements in the center of a Material UI Grid item? Check out this code snippet from my React project: <Grid container> <Grid item xs={4}> // Other content goes here </Grid> <Grid item xs={4}> // How can ...

Executing an external JavaScript function from within an internal JavaScript code block

Currently, I am dealing with 2 JavaScript blocks. One is contained within my HTML and handles touch functionality, while the other is an external file serving as a content slider. My goal is to utilize touch events to control the slider - allowing users to ...

What is the optimal way to configure a click event with three distinct functions as potential outcomes?

When implementing a component in my application, the onClick event presents three different possibilities: 1. function#1 2. function#2 3. no click event Given a certain condition, how can I properly assign the correct event to the component? class UserC ...

What is the method for importing a CSS file in NPM and Meteor?

I am trying to integrate the react-date-picker module (https://github.com/zippyui/react-date-picker) into my project. The documentation states that I need to include the following lines: require('react-date-picker/index.css'); var DatePicker = r ...

The class is failing to be applied to the parent div that holds an id starting with the letter x

I have been attempting to assign a class to the parent container when the child element has the 'hidden' class. If not, then a different class should be added. function tagMissions() { if ($('span[id^="mission_participant_new"]').h ...

Java Applet for capturing specific sections of a webpage to create a screenshot

Does anyone know of a way (applet or something else) to capture a screenshot of the content within a specific div on a webpage? I came across this Java code for capturing a screenshot of the entire screen: import java.awt.AWTException; import java.awt.Re ...

The inclusion of float: left disrupts the formatting of the list

My webpage features a visual element known as a "plan", which consists of a small table and an image. I want these two elements to appear side by side without any styling. Currently, they are displayed one below the other. You can view how it looks like he ...

Consistent Gaps Among Any Number of Buttons

I have a scenario where I have multiple buttons arranged in different lines. Currently, when a button doesn't fit on a line, it moves to the next line leaving blank space behind. What I want is to evenly space out the buttons that manage to be on the ...

The use of DIV tags allows the element to be displayed in an inline

In my project, I decided to add three div tags. The first two are positioned next to each other with the third div tag placed below them. However, when I tried to insert a slideshow into the first div tag, all of the div tags ended up displaying as "block" ...

Using jQuery and CSS to animate DOM elements hidden with display: none

I have a question regarding hiding elements on a webpage. When I set a div to display: none, the other elements in the DOM will abruptly move up to fill its space. Is there a way to animate this movement so that it transitions smoothly and gently instead ...

Issue with loading JS while trying to create and edit an element

I am seeking assistance with two issues I am facing in the execution of my JavaScript code. The first problem arises when working with the 'change' and 'select' events to detect selections and changes within a dropdown menu. Specificall ...

Maintaining User Sessions Securely using Httponly Cookies in React

I'm currently exploring the most effective approach to fetching user data and persisting user sessions on the client side using React, while utilizing HttpOnly cookies for session storage. One potential solution I am considering involves: useEffect( ...

Is there a way to implement a flex display in my react slider component?

Welcome to my custom slider design! <Slider {...customSettings}> <div style={{ 'display': 'flex !important' }}> <CustomToolComponent key={uniqueName} color={customColor} /> <UniqueTool key={uniqueName} co ...

Tips for creating a square HTML element

Looking to customize my react calendar with square tiles. Currently, the width is determined by the overall calendar width, but I want the height to match. https://i.sstatic.net/3vVrq.png Sample HTML: <button class="react-calendar__tile react-cal ...

React Native Bottom tab bar glitching with a sudden jump on every refresh

i am experiencing a similar issue as described in this question: React Native header / bottom tabbar jumping on first app load Every time the app loads, the bottom bar jumps up and down inexplicably. I have tried wrapping the root app in SafeAreaProvider ...

What is the best way to implement the onKeyPress event for a textfield in React using Material-UI

When using a TextField component from react material-ui, I encountered an issue in trying to detect whether the user had pressed Ctrl+Enter. Although I attempted to use the onKeyPress event, it did not yield any results. Is there another approach I can t ...

Emphasizing text by utilizing the information from a separate division

I am seeking a way to visually emphasize specific words within a paragraph by utilizing content from another div. For example, in the first div, there is the phrase "increase overall code" that I would like to highlight within the main paragraph. Thank you ...