Is there a way to place a button in the top-right corner next to my Bootstrap 5 card?

Can someone help me figure out how to position a button on the top right corner next to my bootstrap card? Here's the code I have so far:

<div className="row p-5 m-2">
          {savedEpisodes?.map((saved) => {
            return (
              <div className="col-md-2" key={saved.episode.id}>
                <div style={{ color: "white" }}>X</div>
                <div className="card">
                  <div style={{ color: "white" }}>X</div>
                  <img
                    src={saved.episode.images[1].url}
                    alt="podcastimg"
                    className="card-img-top"
                  />
                  <div className="card-body">
                    <h5 className="card-title" style={{ textAlign: "center" }}>
                      <Link to={`/episode/${saved.episode.id}`}>
                        <span style={{ fontWeight: "bold", color: "white" }}>
                          {saved.episode.name}
                        </span>
                      </Link>
                    </h5>
                  </div>
                </div>
                <div style={{ color: "white" }}>X</div>
              </div>
            );
          })}
        </div>

I've been experimenting with different positioning options, but I can only get the button to appear at the top and bottom. Ideally, I want it to be in the top right corner next to the bootstrap card, similar to this example where I marked the black X:

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

Any suggestions or solutions would be greatly appreciated. Thank you!

Answer №1

Make sure to set the card position as relative and the button position as absolute, experimenting with positioning it on the right and top side.

Answer №2

Feel free to use the following code snippet

HTML Code

<div className="row p-5 m-2">
    {savedEpisodes?.map((saved) => {
      return (
        <div className="col-md-2" key={saved.episode.id}>
          <div className="card">
            <div class="x-icon">X</div>
            <img
              src={saved.episode.images[1].url}
              alt="podcastimg"
              className="card-img-top"
            />
            <div className="card-body">
              <h5 className="card-title" style={{ textAlign: "center" }}>
                <Link to={`/episode/${saved.episode.id}`}>
                  <span style={{ fontWeight: "bold", color: "white" }}>
                    {saved.episode.name}
                  </span>
                </Link>
              </h5>
            </div>
          </div>
        </div>
      );
    })}
  </div>

CSS Styling

.x-icon{
  position: absolute;
  top: 0;
  right: 0;
}

To move the x icon more towards the top right corner, you can apply a negative value.

For instance

 .x-icon{
      position: absolute;
      top: -10px;
      right: -10px;
    }

Answer №3

Placing a button in the top-right corner of an element may not be a common practice in Bootstrap for those unfamiliar with CSS (myself included). However, using a badge with a pill shape can provide similar functionality and serve as an alternative solution. Check out this link for more information.

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

Convert a linear gradient into an object

Can someone help me convert the linear-gradient value into an object with keys and values? Here is the initial value: linear-gradient(10deg,#111,rgba(111,111,11,0.4),rgba(255,255,25,0.1)) I would like it to be structured like this: linear-gradient: { ...

Is it possible to customize the information displayed in a Mat-Dialog based on the object being

My current project involves the presentation of various boxes on a screen. Each box contains a button that, when clicked, redirects to another page. Here is the interface for the box object: export interface Allbox { image: string, link: string, ...

Modify the article category within the Ajax operation

My personal blog on GitHub Pages and Jekyll has a unique CSS styling for articles that changes randomly. Here's the code snippet: <section class="tiles"> {% for post in site.posts %} <article class="XXX" id="styleChanger"> & ...

The background video is not working on iPhones, even though it was functioning properly in the past

After extensive searching, I have been unable to find a solution to my issue. I used an html5 video element as a background with success on both web and mobile platforms, until recently. I have tried adding all necessary attributes for compatibility and I ...

Updating Cart Array in Angular 4 when Adding a New Item

I'm currently using angular 4 and I have encountered an issue in the code where adding a new product to the cart overwrites the existing item instead of appending it to the array. Here is a screenshot illustrating the problem cart.service.ts export ...

Async await function two is failing to execute

I am currently working on a process where I need to unzip a file first, wait for the unzipping process to complete, and then loop through each extracted file to upload it to an S3 bucket. The unzipPromise function is working as expected, successfully unz ...

Unable to Change Navbar Color

Presented here is the code snippet for the navbar located in app/assets/views/elements: <nav class="navbar navbar-default" role="navigation"> <!-- Brand and toggle get grouped for better mobile display --> <div class="navbar-header"> ...

Is it possible to manipulate videos embedded in an iframe using javascript?

It's common knowledge that JavaScript commands from Google can be used to control YouTube videos, while Vimeo provides its own JavaScript commands for their videos. Both videos are typically embedded within 'iframes' on websites. I'm ...

What is the best way to prevent input fields from wrapping onto a new line in a Bootstrap 4 inline form layout?

I am facing an issue with my inline form where the input fields are wider than the screen, causing some of them to fall onto a new line. <!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="u ...

Unable to reach other documents within Node.js

NOTE: Although similar questions may exist on Stack Overflow, this one is unique. Please read carefully. I'm diving into Socket.io on Node for the first time, and I'm facing an issue in my HTML file where I cannot access other files like images. ...

Is my website broken due to Internet Explorer?

The progress on my current website project has been smooth so far, but I'm encountering an issue when testing it in Internet Explorer. Whenever I try to view it in IE, the layout breaks completely. You can check it out at . I've attempted using C ...

Dealing with problems related to types in React and TypeScript createContext

Struggling to pass the todos (initial state) and addNewTodo (methods) using React Context hook and typescript. Despite trying multiple solutions, errors persist. Partial generics do not cause issues in the context component, but I encounter the error Cann ...

Interested in learning how to redirect to a different page using vanilla JavaScript after submitting an HTML form with a Django backend?

Recently delving into Django, I encountered a challenge of linking a js file to my HTML form page and saving the form data before moving on to the next screen. My aim was to incorporate a feature where users can click a picture and POST it along with their ...

Using ASP.NET MVC, pass a list of values separated by commas to an action method

Hey there, I'm facing an issue with an ajax call where I am trying to retrieve values from an html select multiple tag. The problem arises when I attempt to pass these values into my controller as I keep getting a null reference error in my controller ...

AngularJS checkbox feature to tally the number of items that are currently selected or unselected

How can I use angularjs to count the number of selected and unselected checkbox items? My HTML <label class="col-xs-5 pull-left" style="font-weight: bold; margin-left: 4px; margin-top: -17px;" >You have selected <font size="3" color="green" ...

"Guidance on jQuery syntax: Use a textbox to filter out and hide select options with each keystroke

Is there a way to modify my existing code so that it can show or hide elements based on a filter condition, specifically for Internet Explorer? I want to wrap the unmatched elements in a SPAN tag and hide them if the browser is IE, and vice versa by remo ...

Is it possible to align divs so that they touch when they wrap to a new line, creating a grid-like appearance?

My React board component consists of an array of divs that I want to arrange in a grid-like map. The issue is, when the div wraps to a new line, there is significant space between each row. I aim to have the divs close together with no gaps. GameMap state ...

Looking to combine cells within a table using the Exceljs library

Encountered an issue while generating a worksheet in the EXCELJS library. function save_export(){ var workbook = new ExcelJS.Workbook(); var worksheet = workbook.addWorksheet('sheet', { pageSetup:{paperSize: 9, orientation:' ...

utilizing javascript to compare the data in a gridview with the value entered in a

I am looking to compare the values entered in my textbox with the existing values in a gridview. I have achieved this on the server side using the following function: protected void isRecordAlreadyExist(TextBox txt_Value, int res) { ds_main = new Data ...

Error in tabs.onUpdated argument in Firefox WebExtensions

I am currently working on developing a straightforward webExtension for Firefox and I would like to implement tabs.onUpdated with a filter. I found an example on the Mozilla website that I decided to use: const pattern1 = "https://developer.mozilla.org/*" ...