Position the <a> to the right side of the div

Is there a way to right-align the <a> element, which contains a Button with the text Push Me, within the <div> (<Paper>)?

https://codesandbox.io/s/eager-noyce-j356qe

This scenario is found in the demo.tsx file.

Keep in mind that using position: absolute and setting right: 0px won't work because I need the height of the <div> (<Paper>) to adjust dynamically based on its content, including the height of the <Button>.

Answer №1

After reviewing your demonstration, I would recommend wrapping the text in a <div> element and applying the display: flex property to your <Paper>. You can then utilize flex-grow: 2 on that div

<Paper style={{ display: 'flex' }}>
  <div style={{ flexGrow: '2' }}>
    <p>This is some text </p>
    <p>This is even more text </p>
  </div>
  <Link
    component="button"
    variant="body2"
    onClick={() => {
      console.info("I'm a button.");
    }}
  >
    <Button
      variant='contained'>
      Push Me
    </Button>
  </Link>
</Paper>

You can view the modified version on Codesandbox

If you're unfamiliar with flexbox, you can learn more about it here

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

Increase or decrease the quantity of items by cloning with Jquery and dynamically changing the ID

Currently, I am working on a jQuery clone project where I need to dynamically add and delete rows. Despite searching extensively on Stack Overflow and Google, I only have a basic understanding of how jQuery clone works. Any suggestions would be greatly ap ...

The spacing in MUI Grid results in the grid having extra left padding

I'm having trouble creating a grid with a group of elements, specifically when I try to add spacing between them. Take a look at the image below with spacing={0} set on the Grid container: No spacing in Grid container Now, here's what happens wh ...

Improper Alignment of Bootstrap 4 Navbar Link: Troubleshooting Required

Take a look at the image for the issue: https://i.stack.imgur.com/u9aCy.png As shown in the image, the NavBar links are stacked instead of being displayed in one row. This is the HTML code I have used: <!doctype html> <html> <head> ...

Using JQuery to automatically scroll and anchor to the bottom of a dynamically populated div, but only if the user doesn't

I am attempting to achieve the functionality of automatically scrolling to the bottom of a div with the ID #chat-feed. The overflow for this div is set to auto, and I want it to remain at the bottom unless a user manually scrolls up. If they do scroll up, ...

Error encountered on Windows 10 version 10.0.19044 during library installation with npm

I've encountered an error while trying to run or install libraries for a project within our organization. E:\GIT\bookshelf>npm install npm WARN deprecated <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail= ...

Error encountered when trying to map components in React

My goal is to build an app with multiple pages, and I thought a good approach would be to store all the page names and paths in a separate file. This way, I can map out each page instead of having a long list of components in the render method. However, I ...

Changing Text in React Native is Customizable

As a newcomer to react native, I find myself in need of some guidance. I am currently working on implementing a TextInput feature where users can update the text value as they please. For instance, if a user initially creates a folder named "Bar" but later ...

Efficiently Fill JQUERY Mobile Multi-Pages with Dynamic Content

A Question for JQUERY Mobile Beginners: In my basic JQUERY Mobile application, I have a simple setup with two pages. When the user navigates to PAGE2, I need to make an AJAX call to retrieve a JSON object that contains a list of people along with their DB ...

Navigating Three.js coordinate systems

While working with vectors in three.js, I noticed that the axes seem to be mixed up. It's confusing because Y is the vertical axis, but X and Z appear "mirrored" causing objects to only look right when viewed upside-down. How can this issue be resolv ...

Display a featherlightbox popup when the page loads

Well, here's the deal. I don't have any experience with wordpress php coding at all, but I can make basic adjustments using the wordpress admin. Now I've run into an issue. I tried to use the feather lightbox js, and below is a snippet of co ...

Error: The requested collection# cannot be found in the Node.js Express routing system

Recently, I have started learning nodejs and implemented a simple API that allows users to log in with passport and then redirects them to the /collections route. While this part is functioning correctly, I am encountering issues with POST requests which a ...

Issues arise when using Jquery events in conjunction with AngularJS causing them to function

I have encountered an issue with my AngularJS menu code. I am sending an array to prepare the menu when the document loads. In this sequence, I have also added a click event to the generated menu. However, the click event does not fire if it is placed befo ...

Correctly define the vm function within the Controller As scope

I am a newcomer to javascript and AngularJS. So... Maybe it's a simple question, but I've noticed two ways to define functions in javascript. In the following controllers, pay attention to "grupoCancha" and "grupoVisible" (I included the entire ...

How can I implement a toggle button to display additional details for a specific row within a table created using React.js?

I'm currently working on a project using Next.js and have come across an unexpected issue. Upon reading a JSON file, I populate a table with the data retrieved from it. Each piece of information in the table has hidden details that should only be reve ...

What is the best way to prevent all dropdowns from opening simultaneously?

I need some assistance with a basic issue: whenever I try to open one menu, it ends up opening all menus at once. import React from "react"; export default function App() { const [active, setActive] = React.useState(false); function handleCl ...

Is it possible that binding a ref is not functional in vue.js?

Whenever I use v-bind to bind an element reference with :ref="testThis", it appears to stop functioning. Take a look at this working version: <template> <div> <q-btn round big color='red' @click="IconClick"> ...

Choosing an HTML element within a useEffect Hook

Having an issue with selecting an element inside another element in the DOM that was selected using the useRef hook. const editorRef = useRef(null); Trying to access the child element on the editorRef within a useEffect hook. useEffect(() => { edito ...

Save the file to a specific folder and compress the entire folder into a

I have encountered an issue while attempting to write a file to a directory named templates and then stream a zip file with the content that was just written. The problem arises when the zip file is returned, displaying an error message "Failed - Network E ...

Ways to loop through an array in a JSON object

Exploring methods of iterating through an array in json: $(document).ready(function(){ $('#wardno').change(function(){ //this code will execute whenever there is a change in the select with id country $("#wardname > ...

The onChanged attribute of TextField disappears when the done button is pressed on the keyboard after typing in Flutter

class AddTaskScreen extends StatelessWidget { const AddTaskScreen({Key? key}) : super(key: key); @override Widget build(BuildContext context) { String newTask = ''; return Container( color: const Color.fromARGB(255, 117, 117, ...