Customizing the React Bootstrap Button by adding a unique icon and button label

Looking for a way to dynamically adjust button height based on the button name length?

https://i.sstatic.net/156kO.png

The current issue is that the button names are getting cropped. Here's what has been achieved so far:

index.css

.btn-product {
    background-color: white;
    color: black;
    border-radius: 25px;
    border: 2px solid black;
    text-align: left;
    position: relative;
    display: inline-block;
    overflow: hidden;
    text-overflow:ellipsis;
    margin-top: 4px;
    width: 200px;
    height: 50px;
}

index.js

return (
    <div>
        <Button target="_blank" className='btn-product' block variant="secondary" href='/sign-up'>
            <span style={{position: 'absolute', width:'80%'}} >Button 1 with a long name</span>
            <BiChevronRight size={30} style={{color: 'orange', float: 'right'}} />
        </Button>
        <Button target="_blank" className='btn-product' block variant="secondary" href='/login'>
            <span style={{position: 'absolute', width:'80%'}} >Button 2 with a long name</span>
            <BiChevronRight size={30} style={{color: 'orange', float: 'right'}} />
        </Button>
    </div>
)

The requirements are as follows:

  1. The button name should be left aligned.
  2. '>' icon should be right aligned.
  3. On button click, a new browser tab should open with the link.
  4. Button should be rounded like the image.
  5. If the name is too long, it shouldn't be cropped but the button height should adjust accordingly.

Only requirement number 5 remains unresolved. Any suggestions on how to dynamically adjust the button height?

Answer №1

  1. Modify the display property to inline-flex and adjust the height to min-height
  2. Delete absolute from the span and float from the Chevron
  3. Include flex-flow: row nowrap, align-items: center along with justify-content: space-between in the button element.
.button { 
    display: inline-flex; 
    flex-flow: row nowrap; 
    min-height: 50px; // allows it to expand if the name is longer.
    align-items: center; 
    justify-content: space-between; 
}

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

How to show an image using React in collaboration with Strapi

I've been struggling to fetch images from my strapi server. No matter what I try, the images just won't show up. Even when I add them in rich text posts, nothing seems to work. Can anyone lend a hand? const ApiUrl = ('http://localhost:1337&a ...

I am eager to run the code that I retrieved from the server. I have access to the code in my console and I desire for it to execute on the main browser page

Currently, I have a simple Google Chrome Extension that includes a button. By using AJAX, I am fetching a script from a server in my browser's console. Essentially, clicking on the extension reveals a button which, when clicked, fetches the script fro ...

Executing Scripts inside an iFrame in Angular

Upon receiving an API response, I am presented with HTML as a string. Inside this HTML are internal script tags that contain functions called under $(window).load(). How can I successfully load this HTML within my Angular app? I attempted to append the HT ...

Is there a way to show uppercase values in Angular's tooltip as capital letters?

Here is my HTML code: <i [class]="item.icon" [pTooltip]="item.item" tooltipPosition="bottom" ></i> The value inside item.item is 'ATTACHMENT' and I am unable to modify it from the ts file. Is there a way ...

Implementing Autocomplete Feature with React and API Integration

I am currently working with the Material UI Autocomplete component to implement an API call within a method that will return JSON data. The goal is for the autocomplete component to fetch results matching the user's input as they type. However, I&apo ...

Tips on creating a unit test for validating errors with checkboxes in your code base

In a certain scenario, I need to display an error message when a user clicks on the Next button without agreeing to the terms. To achieve this, I am looking to write a unit test case using Jest and React Testing Library. How can I go about doing this? im ...

What is the best way to recreate this grid-like design using CSS?

By utilizing clever techniques such as margins and outlines, I was able to design the following. If you'd like to take a look at the live website, it can be found at https://i.sstatic.net/kl0an.jpg The CSS code that I used is as follows: body { ma ...

Adaptable design tailored for smartphones

When it comes to developing mobile websites for various platforms such as iPhone 3 and 4, Android, Blackberry Torch, etc., I usually find myself needing to slice images based on the specific platform. The challenge arises from constantly having to slice im ...

Link only the dist folder using npm

Is there a method to confine the npm link command to create a symbolic link exclusively directed to ./dist? I am facing difficulties as I wish to locally test my library (a react component) before making it publicly available. Within my package.json, I h ...

Issue with content not moving downward when the drop-down menu collapses

I'm facing an issue with adjusting the layout of my pages when the main Menu collapses. The links that drop down from the Menu are staying on top of the content, and I want them to move down as well. Unfortunately, since some of my pages are integrate ...

Analyzing CSS transform values for rotate3d utilizing regular expressions

I want to split css transform values into an array, while keeping rotate values grouped together. For instance: 'translate3d(20px, 5px, 10px) rotateX(20deg) rotateY(10deg) rotateZ(0deg) skew3d(20deg, 10deg) rotateX(-20deg) rotateY(100deg) rotateZ(-3 ...

Deactivate Firestore listener in useEffect to cease updates

Looking for a solution with useEffect to stop listening to Firebase Firestore collection changes? Data from Firebase can be retrieved successfully, but encountering issues accessing the unsubscribe function. Any ideas on how to resolve this problem? l ...

Updating MySQL database with new values from HTML checkboxes

How can I use Ajax to update a MySQL Table value to "yes" when a checkbox is checked and to "no" when it is unchecked? ...

Rotate images every 5 seconds, pulling them directly from the server

I am looking to update the users every seven seconds on my website. To do this, I need to retrieve all user information from the server using JavaScript. What is the most efficient way to accomplish this task? My initial thought is to send an HTTP request ...

Tips for Presenting Json Information in Bootstrap Columns

I am working on a React App that showcases Json Data on a webpage Displayed below is the JSON file: [ { "name":"Apple", "price":"3,99", "description":"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod te ...

Assign and retrieve unique identifiers for checkboxes

One of the challenges I'm facing is working with an array of ID's from a database in combination with a table layout: The ID array includes specific record identifiers, for example: Array ( [0] => Array ( [id] => 1 [code] => GHY87 [de ...

Enhancing Your NextJS Website: Implementing a Full Page Background Image

I am facing an issue with adding a background image to my welcome page in NextJS. The problem seems to be related to how NextJS renders components inside a master component with a class of "__next". As a result, when I try to add a full-page background i ...

ngAnimate removeClass behaving unexpectedly

Recently, I've been delving into the ngAnimate module for AngularJS version 1.2.14 When employing $animate.addClass, everything seems to function as expected with the ng-animate, -add, and -add-active classes seamlessly added. However, my struggle a ...

problem specifically occurring on tablets with fixed positioning

Have you checked out the site I'm referring to here? An unusual issue seems to be occurring specifically on tablets. We implemented the scroll to fixed jQuery plugin to fix the position of the sidebar after scrolling, which works perfectly on all de ...

Disable logging output from both the Console.log and Logger tools as well as the Redux store when running ReactJs in

I'm currently working on deploying my very first ReactJS application and I'd like to prevent any data from my app showing up in the browser console. This includes the Redux store Logger, console.logs code, etc. I've experimented with variou ...