flexbox: Two vertical icons tightly aligned without any space

Hey everyone, I've been working on this layout:

https://i.sstatic.net/4Aye0.png

Here's what I tried so far:

Resetting padding and margin in the <a href> and in the <img src...>

HTML container

<div>
    <div className="percentage">
        {percentage}%
        <div className="buttonContainer">
            <HandlePercentageButton add onClick={() => this.handlePercentage('add')} />
                <HandlePercentageButton subtract onClick={() => this.handlePercentage('subtract')} />
        </div>
    </div>
    <span className="labelBudget">Budget allocato</span> 
</div>

HTML handlePercentageButton

<div>
    <a href="#" onClick={onClick}>
        {add ? <img src="https://image.flaticon.com/icons/svg/148/148790.svg" style={{ height: '15px' }} /> : null }
        {subtract ? <img src="https://image.flaticon.com/icons/svg/148/148791.svg" style={{ height: '15px' }} /> : null}
    </a>
</div>

And here is my current css:

This card layout has the following main container styling:

.container {
    display: inline-flex;
    background-color: #FAFAFA;
    border-radius: 10px;
    padding: 10px;
    border: 1px solid #E5E4E4
}

Below, we have the percentage number (the big blue number)

.percentage {
  display: flex;
  color: #33BBFF;
  font-size: 30px;
  font-weight: 700;
  padding-bottom: 5px;
}

How can I align the two buttons next to the percentage number vertically with no space between them?

Answer №1

One way to achieve a flexible layout is by using the flex property:

<Wrapper
  style={{
    display: 'flex',
    alignItems: 'center'
  }}>
  <LeftPanel>
    <Percentage />
  </LeftPanel>
  <RightPanel
    style={{
      display: 'flex',
      flexDirection: 'column',
      justifyContent: 'center',
      alignItems: 'center'
    }}>
    <Button type="inc" />
    <Button type="sub" />
  </RightPanel>
</Wrapper>;

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

Issue with ngStyle function in Internet Explorer

Within my Angular 4 application, I have defined styles as shown below: [ngStyle]="{'border': getInterleaveColor(i)}" The following function is also included: getInterleaveColor(auditNumber) { var borderProperties = '2px solid'; ...

Tips for managing REST API calls in separate files within a React JS project

Hey there, I'm currently diving into the world of react js and have been developing something that is working smoothly so far. However, I've noticed that my api calls are scattered throughout various components. This means that if I need to updat ...

Display the toggle button for expanding/collapsing text only when the length of the string exceeds 50 characters

Is there a way to only show a "read more/less" button in a table if the content exceeds 50 characters? The table contains a mix of content, some short announcements with about 10 characters and others with over 100. <div class="col"> <span ng-c ...

ReactJS Chatkit has not been initialized

I made some progress on a tutorial for creating an Instant Messenger application using React and Chatkit. The tutorial can be found in the link below: https://www.youtube.com/watch?v=6vcIW0CO07k However, I hit a roadblock around the 19-minute mark. In t ...

How can we make the Facebook like button display the fan count as the counter?

Can the Facebook like button be customized to display the fan count as the counter, and also update the fan count when clicked (like/unlike)? I've searched through forums and tutorials but haven't found a solution yet. It appears that the standar ...

What sets the /views folder apart from the /lib directory?

I'm currently developing an Express/React application and I'm in the process of understanding the foundational structure that needs to be set up. Within my root directory, I have a file named app.js which acts as the entry point for my app when ...

Issues with displaying calendar items on the React timeline are only resolved after pressing F12 or resizing the

I am encountering a problem while trying to plot the items array in the timeline calendar. Interestingly, the groups array is working fine. The items array also functions properly when values are provided manually. However, the items only render after pre ...

Troubleshooting: Border not showing up in Tailwind CSS (React JS)

Below is the code snippet from my JSX file: import { useState, useEffect } from "react"; import { PropTypes } from "prop-types"; import { HashtagIcon } from "@heroicons/react/24/outline"; // Function to fetch categories from the API (temporary replaced wi ...

Utilizing data attributes over classes for styling in CSS

Programming Languages <span data-bar> ... </span> JavaScript span[data-bar]{ ... } Do you agree with this coding practice? Are there any potential pitfalls? I believe implementing the data- attribute is beneficial when dealing with a large ...

I'm looking to incorporate XML data into table cells using JQuery. How can I go about creating this table?

I am currently working on creating a 16x4 table in JQuery for a "Meet the Staff" page that will feature information on 16 employees. Each row of the table will contain details such as the employee's name, image, position in the company, and a brief de ...

Is there a way in Ruby to extract the inner HTML of the <title> tag by loading the HTML source code of a webpage into a string and then parsing it?

Currently, I am trying to extract the inner HTML of the <body> tag from an HTML source string using Ruby. Does anyone know how this can be achieved? Despite my attempts to find a solution, I have been unsuccessful so far. Any guidance would be grea ...

Unable to execute action in Jest

Our React app includes a cart component: import { useDispatch, useSelector } from "react-redux"; import ItemList from "./ItemList"; import { clearCart } from "../slice/cartSlice"; const Cart = () => { const dispatch = useDispatch(); const cartItems ...

What are the reasons and methods for storing multiple images within a single image?

Lately, I've observed a trend where websites are consolidating multiple images into one large image, similar to Google's homepage. Although we see many small images on the left side, it is actually just one single image: I am curious about how ...

How to precisely navigate to a particular row in a GWT FlexTable

Is it possible to scroll a flextable to a specific selected row? I am attempting to implement functionality where I have two panes, LeftView and RightView. When an item is selected on the RightView, the FlexTable in the LeftView should automatically scrol ...

The <img> element is able to fill an entire div while maintaining its original aspect ratio

I am currently facing a challenge with implementing a responsive gallery slider in Bootstrap. In order to achieve responsiveness, I need to use properties like max-height. The issue arises from the fact that the images in the gallery can vary in size and ...

My website is experiencing issues loading data from mongoDB

I recently ventured into the world of web development and took on the challenge of creating an E-commerce website using MERN stack a few months ago. My first big project was a success initially, but now I am facing issues with loading product images, categ ...

Can a video or image be displayed in HTML using an absolute path from a disk named E: while the localhost files are located in C:?

I'm attempting to construct a basic webpage utilizing HTML and PHP to display various videos, each video within its own videoplayer. The issue arises when I try to find the videos (they are stored in a folder on my secondary hard drive labeled E:&bso ...

Tips for implementing themes in Material UI with React and Next.js

I have created three files which are displayed below. The color of Paper will change based on the value of palette.type that is defined in theme.js. Page with palette.type: 'dark' https://i.sstatic.net/d2LoB.png Page with palette.type: ' ...

Resetting jQuery after a click event is a useful technique that can help ensure

I am working on a survey using jQuery where based on user ratings, different div elements open up. If the user rates 3 stars or below, one div is displayed. However, if the user rates 4 or 5 stars, another div is shown. Everything functions as expected wh ...

Using jQuery to animate a div when clicked by the mouse

Here's the scenario: I have 3 block elements arranged in a specific order: Image Hidden Text Block (.hidden) Footer Block (.blockimage) When the page loads, the image is displayed over the hidden text block (which contains further infor ...