What is the method for aligning a button label to the left and an icon to the right?

I have a list of items and I want to display label text on the left and a check icon on the right. This works fine when the text is short, but when I added the textOverflow property, the icon gets hidden along with the rest of the text. Here is my list

const allTags = (
  <Popover
    style={{ width: "auto" }}
    id="popover-basic"
    title={
      <h6
        style={{
          textAlign: "center",
          fontFamily: "verdana",
          color: "#8f9091",
          fontStyle: "bold",
          margin: "8px"
        }}
      >
        Create a Label
      </h6>
    }
  >
    <div>
      {this.state.allTagsList.map((tag, i) => {
        return (
          <div>
            <div style={{ display: "inline" }}>
              <Button
                className="btn btn-lg btn-fill"
                style={{
                  width: "210px",
                  maxWidth: "300px",
                  border: "none",
                  backgroundColor: tag.color,
                  fontStyle: "bold",
                  cursor: "pointer",
                  padding: "10px",
                  marginBottom: "3px",
                  paddingRight: "80px",
                  overflow: "hidden",
                  textOverflow: "ellipsis",
                  textAlign: "left"
                }}
                onClick={e => {
                  console.log("dd");
                }}
              >
                <span>{tag.text}</span>
                <span className="fas fa-check" />
              </Button>
            </div>
            <div style={{ display: "inline" }}>
              <Button
                className="btn btn-circle-micro"
                style={{
                  borderRadius: "30px",
                  border: "none",
                  width: "25px",
                  height: "25px",
                  textAlign: "center",
                  padding: "1px 0",
                  marginRight: "2px",
                  marginTop: "8px"
                }}
              >
                <i
                  className="fas fa-pen"
                  style={{ pointerEvents: "none", transform: "scale(1,1)" }}
                />
              </Button>
            </div>
          </div>
        );
      })}
    </div>
  </Popover>
);

Answer №1

If you're looking to achieve this layout, consider using flexbox:

.wrapper{
  width: 100px;
  position: relative;
  display: flex;
  flex-flow: row nowrap;
}

.text{
  flex-basis: 80%;
  background-color: red;
  overflow: hidden;
}

.icon{
flex-basis 20%;
  position: relative;
  width: 20px;
  height: 20px;
  background-color: yellow;
}
<div class="wrapper">
  <div class="text">
  Halloooooooooooooo
  </div>
  <div class="icon">
  </div>
</div>

Answer №2

The reason for this issue is because the icon is included in the text that is currently being hidden.

A workaround would be to incorporate your icon as a pseudo-element, which should resolve the problem and achieve the desired outcome.


button{
  width: 100px;
}

button span{
  width: 50px;
  overflow: hidden;
  white-space: nowrap;
  display: inline-block;
  text-overflow: ellipsis;
}

button::after {
    font-family: "Font Awesome 5 Brands"; content: "\f099";
  }
<button>
    <span>Some giant text</span>
</button>

For reference, you can view an example here: https://codepen.io/anon/pen/zQdOGm

Answer №3

One possible approach is to implement a solution like this:

 const allTags=(
          <Popover style={{width:"auto"}} id="popover-basic" title={<h6 style={{textAlign:"center",fontFamily:"verdana",color:"#8f9091",fontStyle:"bold",margin:"8px"}}>
          Create a tag
          </h6>}>
          <div>
          {this.state.allTagsList.map((tag,i)=>{
            return <div>
            <div style={{display:"inline"}}><Button id="Button1" className="btn btn-lg btn-fill"  onClick={(e)=>{console.log("dd")}}>
            <span id="Test">{tag.text}</span>
            <span className="fas fa-check"/>
            </Button>
            </div>
            <div style={{display:"inline"}}>
            <Button className="btn btn-circle-micro" style={{borderRadius: "30px",border:"none", width:"25px",height:"25px",textAlign:"center",padding: "1px 0",marginRight : '2px',marginTop:"8px"}}
            >
            <i className="fas fa-pen" style={{pointerEvents:"none",transform:"scale(1,1)"}}/></Button>
            </div>
            </div>
          })}
          </div>
          </Popover>
        );

Css:

  #Button1 {
       width:"210px",
            maxWidth:"300px";border:"none";
            backgroundColor:tag.color;fontStyle:"bold";
            cursor:"pointer";padding:"10px",marginBottom:"3px";
            paddingRight:"80px";overflow: "hidden";textAlign:"left";

    }
#Test{
  textOverflow:"ellipsis";
}

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

Incorporating photos within the layout of a Twitter Bootstrap grid

Looking to showcase images like the ones found here: https://i.stack.imgur.com/eD4GD.jpg These images are original and come in various sizes. I want a hover effect that includes blur, fogging effects, and text placed in the middle of the picture. Check ou ...

Tips for safeguarding user input data in the event of a Jeditable ajax post failure

Seeking a solution with Jeditable for retaining textarea data and keeping the form visible in case of failed ajax post due to issues like network problem or server error. Is there a way to achieve this with Jeditable? Thanks! ...

Positioning two distinct Div elements using CSS

In an attempt to align two lists within a div, I have one list containing .jpg files and another with text files. <!DOCTYPE html> <html> <style> .left{height:auto; float:left;} .right{height:auto; float:right;} </style> &l ...

"Exploring the seamless integration of Next.js and Material UI for stunning web

I have encountered an issue while using Next.js and Material-UI(@mui/core) to build a website. Everything works perfectly when I run it with next dev, but the styles get messed up when using next build && next start. In addition to Material-UI, I ...

Having trouble with setting CSS style in <p> tags within Codeigniter framework

Why is the class mentioned in the p tag not applying in Chrome but working in IE and Firefox? <p class="p_error"><?php print $this->validation->errorValue;?></p> Here is the CSS -> .p_error{ color:red; text-align:left; font-size ...

The link button appears unselected without a border displayed

I am facing an issue with a link button in my code. Here is the snippet: <div class="col-2"> <a type="button" routerLink="auto-generate-schedules/generate" class="btn btn-primary mb-2">Generate Sche ...

Leveraging custom hooks within a callback function

When trying to make an API request for cities data using the provided input, I encountered an error stating React Hook "useData" is called in function "handleCityInput" that is neither a React function component //handling city input const handleCityIn ...

Issue with displaying decimal places in Nivo HeatMap

While utilizing Nivo HeatMap, I have observed that the y value always requires a number. Even if I attempt to include decimal places (.00), it will still trim the trailing zeros and display the value without them. The expected format of the data is as foll ...

Making an element sticky within a container while the parent element is set to overflow hidden

Here is a case where I have generated HTML and CSS code that includes classes for overflow, container height, and sticky positioning: .overflow-hidden { overflow: hidden; } .overflow-x-auto { overflow-x: auto; } .container { max-height: 100px; ...

I'm receiving an ENOENT error when trying to run npm start. Can someone explain why this error is occurring and why it seems to be searching for the "My Pictures

Currently, I am integrating MUI's Data Grid component into my React project. After successfully installing the package using $npm i @mui/x-data-grid, I faced an unexpected ENOENT error upon importing DataGrid and running $npm start. Can anyone shed li ...

Beginning the phone application using either HTML5 or Cordova

Is there a way to use either HTML5 or Cordova (PhoneGap) to initiate a call to a phone number? I am looking to create a button that says "Call 555-555-5555", and when clicked, it opens the phone app on the device with that specific number. ...

Material UI - Swipeable Drawer with Bleed Interaction Feature

Utilizing the SwipeableDrawer feature from Material UI has allowed me to create a swipeable bottom sheet. In order to give the appearance that the drawer cannot be completely closed, I have set the drawer bleed to 85px when it is closed or minimized. Withi ...

Implementing React with Tailwind and AOS to Enhance User Experience

I recently utilized the React Tailwind template to develop a website. It functions flawlessly in my browser with no issues when running npm start. However, I encountered errors while attempting to deploy it on Netlify or Heroku despite following the docume ...

Deactivate a div based on a Razor variable in ASP.NET MVC4

Is there a secure method to disable a div based on a Razor variable in ASP.NET MVC 4.0? I attempted using a CSS class, but it was easily bypassed with developer tools. .disableddiv { pointer-events: none; opacity: 0.4; } Any advice on how to effectively ...

illuminate selected row in datatable using a jquery plugin

My data is displayed using the jQuery plugin DataTable, and everything appears to be working well. I am retrieving my data from PHP using AJAX. However, I encountered an issue when trying to highlight the row that was hovered over while navigating around ...

Exploring Next.js nested dynamic routes: utilizing getStaticProps for data fetching and sharing data across routes

I am currently working on developing a next.js application with nested dynamic routes and the need for shared data among these routes. The directory structure I have set up is as follows: -pages -/level1 -/[level1_id].js -index.js -/level2 ...

What is the best way to apply a specific style based on the book ID or card ID when a click event occurs on a specific card in vue.js

My latest project involves creating a page that displays a variety of books, with the data being fetched from a backend API and presented as cards. Each book card features two button sections: the first section includes "ADD TO BAG" and "WISHLIST" buttons ...

Using jQuery to Generate an Automatically Updating Timer for Slideshow - Pausing on Mouse Click

My first slideshow with jQuery is up and running, but it's very basic and hard coded. I want to add an automatic scrolling effect every 8 seconds to the next item before looping back to the beginning. I have an idea on how to achieve this, but I want ...

Is it common for functions to be outlined in standard CSS practices?

I am curious if the CSS standard includes definitions for "functions"; I have not come across any information about them on w3schools or other sources. When I refer to "functions," I am talking about calls such as rgb(int, int, int) or url(string) that ar ...

Looking to connect information

I have written the following code and I am trying to bind data to ng-model. When I use ng-model = "value", I can see the value in the text field, but I want to update the value when the text input is changed. <tbody ng-repeat="action in model.editAct ...