What could be the reason for this code not displaying buttons on separate lines rather than next to each other?

I am struggling to get the Logo to print followed by all buttons lined up side-by-side. I have experimented with different display properties within the first <div> tag such as block, inline-block, and even removing the display property altogether. I also attempted removing the Box mui tag, but nothing seems to be working. It's possible that I am making a simple mistake due to my lack of experience in CSS. This is part of a Next.js project.

import {makeStyles} from '@material-ui/core/styles';
import DashboardIcon from '@material-ui/icons/DashboardOutlined';
import ListingsIcon from '@material-ui/icons/Reorder';
import ScheduleIcon from '@material-ui/icons/EventNote';
import ProfileIcon from '@material-ui/icons/AccountCircleOutlined';
import SalesIcon from '@material-ui/icons/TrendingUp';
import BookingsIcon from '../../public/images/bookingsIcon.svg';
import Logo from '../mainLogo';
import Box from '@material-ui/core/Box';


const useStyles = makeStyles((theme) => ({
  root: {
    '& > *': {
      margin: theme.spacing(1),
    },
  },
}));

export default function SideNav() {
  const classes = useStyles();
  return (
    <Box>
      <Logo />
      <div display="block">
        <Button
          variant="contained"
          color="primary"
          className={classes.root}
          startIcon={<DashboardIcon />}
        >
          Dashboard
        </Button>
        <Button
          variant="contained"
          color="primary"
          className={classes.root}
          startIcon={<ListingsIcon />}
        >
          Listings
        </Button>
        <Button
          variant="contained"
          color="primary"
          className={classes.root}
          startIcon={<ScheduleIcon />}
        >
          Schedule
        </Button>
        <Button
          variant="contained"
          color="primary"
          className={classes.root}
          startIcon={<BookingsIcon />}
        >
          Bookings
        </Button>
        <Button
          variant="contained"
          color="primary"
          className={classes.root}
          startIcon={<SalesIcon />}
        >
          Sales & Analytics
        </Button>
        <Button
          variant="contained"
          color="primary"
          className={classes.root}
          startIcon={<ProfileIcon />}
        >
          Profile
        </Button>
      </div>
    </Box>
  );
};

Answer №1

Try adding the flex property to the div with a direction of column as shown below:


      <div style={{display:'flex', flexDirection:'column'}}>
        <Button
          variant="contained"
          color="primary"
          className={classes.root}
          startIcon={<DashboardIcon />}
        >
          Dashboard
        </Button>
        ...
        ...
        ...
      </div>

Answer №2

To ensure the button displays as a block element, you can apply the "display: block;" property directly to the button itself.

Since buttons are typically inline-block elements by default and divs are usually block-level elements, it is important to specify the display block property for the button tag instead of the surrounding div.

button {
  display: block;
}
<button>Click Here</button>

Answer №3

attempt using

<div style={{flexDirection:"column"}}>

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

Polymer elements fail to adapt to varying screen sizes

I am currently working on creating a responsive website using polymer, but I have encountered an issue where certain elements (such as core-toolbar and paper-fab) are not scaling properly on smaller, denser screens like smartphones. After browsing through ...

Validating a particular value using Regex in React Formik

First, I need to ensure that the field is validated for any characters not included in this set: /[ùûüÿ€’“”«»–àâæçéèêëïîôœ]/. If a user enters a character outside of this set, I want Yup to trigger an error message. Secondly, I ...

Creating dynamic forms with JQuery and ReactJS

I have been tasked with creating a form-builder that will be integrated into an application. My role is to focus on designing the front-end using ReactJS. The client’s requirements are very similar to the features of the "jQuery Form-Builder," so I decid ...

The module 'FloatingLabel' cannot be found in the 'react-bootstrap' library

Struggling to import the FloatingLabel component from react-bootstrap as outlined in the official bootstrap documentation. Despite following the instructions, I keep receiving an error message indicating that FloatingLabel is not exported from react-bootst ...

Flex Item will only respect the margin or padding when both are set simultaneously

I've been playing around with CSS and running into a problem where a flexbox item isn't respecting margin and padding correctly, causing the right side to have no margin. Here's a simplified example I came up with: <body> <div c ...

What steps can I take to ensure that AstroJS components do not conceal SVG elements when the SVG is incorporated into another file with client:load?

Currently, I am developing a weather application using Astro.js in conjunction with React. One of the features includes an SVG component that serves as the project logo and is implemented in the initial page loader. Upon the page loading, the SVG functions ...

System reboots upon socket message reception

I am currently working on developing a chat application using Next, Express, and Socket.io. I have encountered an issue where the state managing the messages in the chat resets every time a new message is sent from one browser to another. You can see an ex ...

Just starting out with React and Babelify; Steps to resolve the "PropTypes Access" warning

As a newbie to both React and Babelify, I am currently using Node to compile my web app. Here's what I have so far: browserify({debug: true}) .transform( babelify.configure({ comments : false, presets : [ "react", "babili", ...

Using axios to pass parameters in a URL with the GET method on a localhost server

I need help using Axios to consume my Go lang API in my React front-end. The route for the API is localhost:1323/profile/email/:email/password/:password, but I'm struggling to figure out how to pass the email and password parameters in the Axios GET r ...

Picture is not displaying properly post-rotation

Is there a way to rotate an image by 90 degrees and display it in a Card Component without it covering the text? Currently, I am utilizing Element.io, but encountering issues with the rotated image overlapping the text. The image currently has the followi ...

TreeView Filtering

I have encountered an issue while trying to utilize a treeview filter. Below is the method I have created: var tree = [{ id: "Tree", text: "Tree", children: [ { id: "Leaf_1", text: "Leaf 1", childre ...

Uncovering aesthetics in React alongside material-ui

In my React project using material-ui, I am interested in extracting the styles defined in each component into a shared file. When all styles are consolidated into one file, everything functions correctly: import { withStyles } from '@material-ui/co ...

Applying a Webkit Scroll Bar to a specific element on the webpage

I've been attempting to apply the Scroll Bar webkit styling to a particular element but haven't had any success. Despite searching extensively, I have come across 2 threads on Stack Overflow that do not provide a solution. Most of the available ...

Having trouble with updating label text in MUIDataTable in ReactJS?

Looking to implement multi-language support in MUI Datatables. I have been able to modify the translations, but when attempting to change languages by providing a different object with new translations (verified using console log), the label texts do not u ...

How to format numbers in JavaScript post calculations

Struggling to find a solution to format calculation results with commas for thousand separators (e.g., 10,000). After implementing the .toLocaleString('en-US', {maximumFractionDigits:1}); method to format numbers in the output, I encountered unex ...

Is there a way to apply the same class exclusively to the first child within a group?

How can I include specific classes for only the initial group of items in a nested ul li list? <ul> <li class="first-group"> <ul> <li></li> </ul> </li> <li class="first-group"></li> & ...

Tips for setting up a full-size image with nextJS and the <Image /> component

Upgrading NextJS to the latest version has resulted in some errors when using the Image component: // import Image from 'next/image' <div style={Object.assign({}, styles.slide, style)} key={key}> <Image src={src} alt="&quo ...

Improving the layout and size of text within input fields

How can we adjust the input text positioning to the right so it's not directly against the edge? Is there a way to move 'searching' 5px to the right? ...

Arrange a div within a list element to create a grid-like structure

My current structure is as follows: <ul class="wrap-accordionblk"> <li class="accordionblk-item"> <div class="accordionblk-header"> <div class="row-fluid"> <div class="infoblk"> <label>SESSION ID ...

Having trouble getting NextJS to work with jsmpeg/node-rtsp-stream for displaying an RTSP stream

Exploring: https://github.com/kyriesent/node-rtsp-stream and How to display IP camera feed from an RTSP url onto reactjs app page? I attempted to showcase the RTSP stream from a CCTV but encountered an error. ReferenceError: document is not defined at scri ...