Position the Button in the Center between Borders using CSS and MUI

I'm trying to center a button just like the one shown in the image below. It needs to be perfectly aligned with the lines. What is the best way to achieve this?

Check out the example on Codesandbox

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

<MainContainer>
      <Stack spacing={1}>
        <Card sx={{ minWidth: 275 }}>
          <CardContent>
            <Typography
              sx={{ fontSize: 14 }}
              color="text.secondary"
              gutterBottom
            >
              Word of the Day
            </Typography>
            <Typography variant="h5" component="div">
              be{bull}nev{bull}o{bull}lent
            </Typography>
            <Typography sx={{ mb: 1.5 }} color="text.secondary">
              adjective
            </Typography>
            <Typography variant="body2">
              well meaning and kindly.
              <br />
              {'"a benevolent smile"'}
            </Typography>
          </CardContent>
        </Card>
      </Stack>
      <Stack justifyContent={"center"} alignItems={"center"}>
        <Button variant="contained" color="primary" sx={{ maxWidth: 50 }}>
          Hello
        </Button>
      </Stack>
    </MainContainer>

Answer â„–1

experiment

<Button variant="contained" color="primary" sx={{ maxWidth: 50, margin: '0 auto' }}>

Take note of the margin: '0 auto' CSS property. It functions effectively on the incredibly useful code sandbox platform.

Answer â„–2

To position it in the middle, use this: align-items: center

<Stack justifyContent={"center"}>
  <Button variant="contained" color="primary" sx={{ maxWidth: 50 }}>
    Hello
  </Button>
</Stack>

revise as follows:

<Stack alignItems={"center"}>
  <Button variant="contained" color="primary" sx={{ maxWidth: 50 }}>
    Hello
  </Button>
</Stack>

alternatively, you can utilize both: justifyContent, alignItems

Answer â„–3

To adjust the position of the button, consider giving it a negative marginTop (mt) value.

import { Stack, Card, CardContent, Typography, Button } from "@mui/material";
import "./styles.css";

export default function App() {
  const bull = "*";
  return (
    <div className="App">
      <Stack spacing={2}>
        <Card sx={{ minWidth: 275 }}>
          <CardContent>
            <Typography
              sx={{ fontSize: 14 }}
              color="text.secondary"
              gutterBottom
            >
              Word of the Day
            </Typography>
            <Typography variant="h5" component="div">
              be{bull}nev{bull}o{bull}lent
            </Typography>
            <Typography sx={{ mb: 1.5 }} color="text.secondary">
              adjective
            </Typography>
            <Typography variant="body2">
              well meaning and kindly.
              <br />
              {'"a benevolent smile"'}
            </Typography>
          </CardContent>
        </Card>
      </Stack>
      <Stack justifyContent={"center"} alignItems={"center"}>
        <Button
          variant="contained"
          color="primary"
          sx={{ maxWidth: 50, mt: -2.5 }}
        >
          Hello
        </Button>
      </Stack>
    </div>
  );
}

For a demonstration, check out this Codesandbox demo.

Source: How to overlap buttons in div tag using css

Answer â„–4

To incorporate the horizontal direction, include direction="row" within the stack element. In order to align it with the lower dotted line, you will need to tweak the padding in the root css by eliminating the bottom padding. For example, modify padding: 3 to paddingTop: 3, paddingX: 3,

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

What is the best way to customize the primary Button style in Bootstrap?

Would you like the background-color to change when clicking on the radioButton? .btn-primary:hover, .btn-primary:active, .btn-primary:visited, .btn-primary:focus { background-color: black !important; color: white !important; } .btn-primary { colo ...

React displaying an error indicating that the setTimeout function is undefined?

While attempting to integrate the XTK library with React, I encountered an issue where it kept throwing an error stating that the setTimeout function is not a valid function. Surprisingly, my code appears to be flawless and works perfectly fine when used d ...

When the page is resized for mobile, the Bootstrap modal shifts downwards

I am encountering an issue with a modal that pops up on my webpage when clicked. It is perfectly centered in a browser view and smaller views. However, when I resize the page for phones, the modal shifts down the page and requires scrolling to see it. How ...

Is there a way I can turn off the dragging functionality in my situation?

Is there a method to disable the dragging functionality within a draggable element? $('#dragitem').draggable({ scroll : false, drag: function(event, ui){ //check if condition is met if(†...

Erase periods from the text box

Is there a way to remove the dots in the right bottom corner of a textarea without disabling resizing? https://i.sstatic.net/N2zfh.jpg I have seen a solution using the css property resize:none, but I would like to keep the resizing functionality... Are ...

Is there a way to make a DIV's span equal in height to its inner H3

I am working with a layout that looks like this ... <div style="width: 99%; border: 1px dotted #0683DA; padding: 8px;"> <h3>Some Header</h3> <div class="d-dataGridBodyRow" style="padding: 0px"> <table style="vert ...

Align component within material-ui grid

Looking to center align the same cards but not just the grid component, I need the content itself to be equally distant from the borders and each other. I've searched and tried different solutions without luck. https://i.stack.imgur.com/aZj7H.png htt ...

Learn how to achieve a sleek animation similar to the famous "Ken Burns effect" by utilizing the CSS property "transform" instead of "object-position". Check out the demo to see it in action!

I am currently exploring how to create an animation similar to the "Ken Burns" effect using CSS transform properties. While I have been using object-position to animate, I am facing challenges with the fluidity of the movement. I am seeking help to achiev ...

What is the purpose of using a visually striking and prominent HTML tag?

After 15 years of working in html development and managing multiple websites, I have come to realize that bold and italic tags essentially serve the same purpose. I can apply CSS styles to both to achieve similar effects. I have even experimented with maki ...

Enhance Animation Fluidity with HTML/CSS

I am experimenting with creating a floating animation for my iceberg logo by adjusting the top margin. Below is the CSS code I have implemented: img { height: 60px; padding: 5px; -webkit-animation: logofloat 1s ease-in-out infinite alternate; -moz ...

Javascript code has been implemented to save changes and address resizing problems

Code Snippet: <script> function showMe(){ document.querySelector('#change').style.display = ''; document.querySelector('#keep').style.display = 'none' document.querySelector('#change1').style.d ...

access various paths to distinct iframes

<?php // Specify the directory path, can be either absolute or relative $dirPath = "C:/xampp/htdocs/statistics/pdf/"; // Open the specified directory and check if it's opened successfully if ($handle = opendir($dirPath)) { // Keep readin ...

Transitioning to EM-Based Media Queries

After the recent resolution of the WebKit page-zoom bug, what are the primary benefits of utilizing em-based media queries over pixel-based ones? Incentive I am offering a reward for my question as many prominent CSS frameworks and web developers use em- ...

As I work on compiling my React project, I am encountering a problem with a module that is not

Currently, I'm in the process of upgrading my React project to a newer version and encountering an issue. The error message reads as follows: ERROR in ./node_modules/react-dom/index.js Module not found: Error: Can't resolve 'react/lib/React ...

Unable to iterate through elements when utilizing an external library: Incompatible types, 'Element[]' cannot be assigned to type 'string'

I've encountered an issue while trying to use the react-responsive carousel. It seems to work fine when I manually add my images, but when I try to add them through photos.map, it throws an error: Type 'Element[]' is not assignable to type ...

The hover effect in CSS is not altering the entire background

I'm looking to change the background color of a div when hovering over it, but I'm running into an issue where only the content inside the div is changing color. The rest of the background remains the same. Here's the HTML code I have: < ...

When hovering over items in the navigation bar, the entire bar expands seamlessly

I've spent countless hours trying to troubleshoot an issue with my dropdown menu that expands whenever I hover over it. The bar stretches out to accommodate the list of dropdown contents and then reverts back to normal when I move my cursor away. My a ...

What methods can I use to prevent a number from becoming negative?

I am currently developing a game where players collect resources, spend them to create more resources, and engage in various activities. However, I'm facing an issue where the resource count goes into negative numbers when too much of a certain item i ...

The Media Queries in the Wordpress html5blank theme are failing to function properly

While using the html5blank theme to develop a WordPress site, I noticed that my media queries are functioning properly locally. However, when I add them to the WordPress style.css file, they seem to stop working. Even after stripping away all other media q ...

Modifying element size using jQuery causes issues with maintaining a 100% height

I am facing an issue with a sidebar that is styled using the following css properties: background:#164272; position:absolute; left:0px; top:70px; width:250px; height:100%; When I use jQuery to display a table that is initially hidden and on ...