Positioning elements in a header using CSS techniques

I am currently working on designing a navigation menu header that includes a logo, along with some buttons aligned to the left side of the logo. However, I am facing an issue where these buttons appear at the bottom of the logo instead of aligning to the top of the container. I'm not sure if this has to do with the CSS styling or if the container's positioning is causing this problem?

import React from 'react';
import {Link} from 'react-router-dom';
import { AuthService } from './backend/client/auth';
import { Paper, Button } from '@material-ui/core';
import { withStyles } from '@material-ui/core/styles';

const styles = theme => ({
container: {
    'height': 128,
},
leftnav: {
    'display': 'inline-block',
},
rightnav: {
    'float': 'right',

},
button: {
    'display': 'inline-block',
}
});


class Header extends React.Component {
render() {
    const { classes } = this.props;
    return (
        <Paper className={classes.container}>
            <div className={classes.leftnav}>
                <Link to="/" className={classes.button}>
                    <img src="https://imageserver.eveonline.com/Corporation/98523546_128.png" alt="Hole Puncher's Logo"></img>
                </Link>
                <Button component={Link} to="/">
                    Home
                </Button>
                <Button component={Link} to="/store">
                    Browse
                </Button>
                <Button component={Link} to="/contact-us">
                    Contact Us
                </Button>
            </div>
            <div className={classes.rightnav}>
                {AuthService.isAuthed()
                    ? <Button component={Link} to="/account/orders">Account</Button>
                    : ''}
                {AuthService.isAuthed()
                    ? <Button component={Link} to="/login">Login</Button>
                    : <Button onClick={AuthService.logout} component={Link} to="/login"></Button>}
            </div>
        </Paper>
    )
}
}

export default withStyles(styles)(Header);

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

Answer №1

To tackle this CSS issue, there are various methods available. The simplest approach involves utilizing the vertical-align: top property in your button class. Alternatively, I recommend exploring the advantages of using display: flex for more straightforward vertical alignment.

You can view a functional JSFiddle demo here: http://jsfiddle.net/Lhefbudx/

I trust this information proves to be beneficial.

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

Having trouble with the placeholder blur feature on images in Next.js?

Within my website, I have a dynamic route set up as /titles/[slug].js. Upon initially navigating to this route, everything functions as expected - the placeholder blur effect displays on all images and animations triggered by react-intersection-observer wo ...

Unable to apply styling to table cells that are dynamically added using JQuery within an Angular

Currently working on setting up a form using Angular. Within the hotel.view.html file, there is a table that looks like this: <table id="rooms"> <tr> <td>Room Type</td><td>Beds</td><td>Q.ty</td ...

Expect a reply within the loop

One of my endpoints takes some time to generate data, and I have another endpoint to retrieve that generated data. I make the initial call using await, extract the ID from the response, and then keep calling the second endpoint until the status is not "Suc ...

What are some ways to create a responsive Grid in React JS with the help of Bootstrap?

Utilizing bootstrap in my react js project, I am implementing css grid to showcase some cards. However, I am encountering responsiveness issues. import React from "react"; import "./Project.css"; export const Project = () => { return ( <div& ...

How to Incorporate Custom Colors into Material UI Themes

I'm currently working on developing a unique theme with custom colors using Material UI in React. The issue I am facing is that while I can successfully create the custom theme and view it in the console with the new color values, I encounter an error ...

I am trying to display my progress bar in a col-sm-6 format on screens larger than 546px, however, despite my attempts, I am not seeing any changes on the screen

Is there an alternative method if bootstrap is unable to handle this? I have used col-xs-6, but all I want is to display my progress bar in the image shown on small screens. Here is how I want to display my image on small screens. <div class="cont ...

Eliminate any excess space to the right of the image

Utilizing Bootstrap alongside React, I've encountered an issue with images causing unwanted whitespace to the right. I've thoroughly examined the elements but have been unable to resolve this issue. Despite researching Bootstrap Col online, the ...

Yet again faced with an annoying gap between table rows and cells, for the 532nd instance

Once again, tables have defeated me. I am struggling with a simple table: <table style="width: 200px; margin: 20px auto; border-collapse: collapse; border-spacing: 0; border: none;"> <tr style="margin: 0; padding: 0; border: none; border-colla ...

Issue with specific selectors causing React CSS module malfunction

Currently, I am a beginner in learning React and have been experimenting with CSS modules. Even though Menu.module.css is mostly functioning correctly, it seems to be having an issue applying styles to the .menu a.last selector for some reason (although i ...

Display the current position of the caret in a field that cannot be edited

Can a virtual caret be displayed between two letter boundaries in HTML/CSS/JavaScript, for example in a regular div without using contenteditable=true? Imagine having the following: <div>Hello world</div> If I were to click between the "w" a ...

The functionality of Material UI Slider components becomes less responsive when enclosed and rendered in JSX

Why is the Material UI's Slider not working smoothly when called in JSX as shown below? SliderAndValue.js import { Slider } from "@material-ui/core"; import { useState } from "react"; import "./styles.css"; export const ...

Shifting and implementing various styles across numerous elements at the same time

There is an anchor tag containing two spans... <a class="banner-logo" href="/search"><span id="banner-logo-hello">Hello</span><span id="banner-logo-world">World</span></a> When hovering over the anchor tag, I want to c ...

What is the best way to constrain the ratio of a full-width image display?

I am in need of a solution for displaying an image at full width inside a frame with a 16:9 aspect ratio. The image needs to be centered within the frame and adjust responsively when resizing the screen. My preference is to achieve this using just CSS. ...

The utilization of CSS variables within intricate properties

Imagine having a CSS property called box-shadow: box-shadow: 5px 5px 0 #ccc; What if there is a need to create a variable from the color #ccc? While in SCSS, you could accomplish this with code like: $grey: #ccc; .element { box-shadow: 5px 5px 0 $gre ...

The issue with HTML where the header and footer elements are continuously repeating when

I'm struggling with the title header and footer repeating on every printed page. I just want to show the title at the top of the page and display the footer at the end of the print page. Can anyone provide a solution or suggestion? You can view my fid ...

Setting the Height of a Fixed Element to Extend to the Bottom of the Browser Window

I currently have a webpage layout featuring a header at the top, a fixed sidebar on the left side, and main content displayed on the right. A demo version of this layout can be viewed at http://jsbin.com/iqibew/3. The challenge I'm facing is ensuring ...

Why do certain list items on my page have a gap between their border and content?

I recently encountered an issue with my list of items and their styling. Each list item contains an anchor element with a gray background, while the item itself has a gradient bottom border. However, I noticed that in some cases, there was a white line ap ...

Steps for wrapping a class with a higher order component

Is it feasible to encapsulate a class component within a higher order component (HOC) that is also a class? import React, { Component } from "react"; import { View } from "react-native"; import { Toast } from "react-native-easy-toast"; const withToast = ...

Enhancing Your NextJS Website: Implementing a Full Page Background Image

I am facing an issue with adding a background image to my welcome page in NextJS. The problem seems to be related to how NextJS renders components inside a master component with a class of "__next". As a result, when I try to add a full-page background i ...

Image in an Outlook email surrounded by padding and enclosed in a paragraph

I am facing an issue with my email signature setup in Outlook Live where there is a white space below the image. After trying to add vertical-align:bottom to the CSS, it seems that Outlook Live does not accept it. The code for my HTML in Outlook 20xx is a ...