Unable to shift the header menus upwards for proper alignment with the logo

Header with logo

  1. I'm trying to align the menu items like Home, etc with the logo, but it seems like the logo is taking up too much space above the menu headers and I'm not sure how to reduce it. I've already attempted using margin-left or right and padding, but it's not working. Also, I'd like to know if using negative CSS rules is considered bad practice, or if there are any other mistakes in my code. Apologies for any grammatical errors, English is not my first language.
<!DOCTYPE html>
<html>
<head>
    <title>Heloisa Antoniely │ Makeup</title>
    <link rel="stylesheet" type="text/css" href="Makeup.css">
    <meta charset="UTF-8">
    <meta name="author" content="Thiago Marvin">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=STIX+Two+Math&display=swap" rel="stylesheet">
</head>
<body>
    <header>
        <div class="main-header">
            <div class="Logo">
                <img src="photos/Logo.png.png" alt="Makeup" class="center">
            </div>
            <div class="social">

            </div>
            <div class="header-menus">
            <ul>
                <li>
                    <a href="">Home</a>
                    <a href="">Contato</a>
                    <a href="">Portfólio</a>
                    <a href="">Localização</a>
                </li>
            </ul>   
        </div>
    </header>
    <section>
        
    </section>

</body>
</html>
body{
    background-color: #137B77;
    margin: 0;
    padding: 0;
}
header{
    background-color: #45a29e;
    margin: 0;
    padding:0;
    justify-content: baseline;
}
.center{
    display: block;
    margin-left: auto;
    margin-right: auto;
    width: 15%;
    vertical-align: middle;
    margin-bottom: -124px;
    margin-top: -65px;
}
.main-header{
    margin-top: 0px;
    margin-bottom: 62px;
}
.header-menus{
    padding-top: 0;
}
.header-menus ul li {
    list-style: none;
    color: #000000;
}
.header-menus ul li a{
    color: #000000;
    text-decoration:none;
    padding-left: 30px;
    font-size: 15px;
    line-height: 2.0;
    font-family: 'STIX Two Math', serif;
}

Answer №1

When dealing with div elements, it's important to remember that they are block elements and will take up all available horizontal space within the parent element.

To learn more about block-level elements, check out this link: https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements

If you want to control the layout of your elements, consider using the CSS property display: flex on the .main-header class. This will default to arranging child elements in a row (flex-direction: row).

You can also use the align-items property to adjust the vertical alignment of elements.

For a detailed guide on using flexbox, visit: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

.main-header {
    display: flex;
    align-items: center;
}

For a live demonstration, check out this link: https://jsfiddle.net/u3gv6s7f/

Answer №2

Specify the logo width as x pixels to give it a fixed size. Alternatively, you can set the width to 100% and ensure that you style the container div as an inline-block or utilize flex-box to establish its dimensions effectively.

.main-header {
    display: flex;
}
img {
    width: 100%;
}

This should arrange all elements within the header in a row. For a deeper understanding of flex-box, consider exploring resources like .

Answer №3

To align the logo and links properly, utilize flexbox in the main div.

.main-wrapper{
    margin-top: 0px;
    margin-bottom: 72px;
    display: flex;
    justify-content: center; //try using space-around or space-evenly as well
    align-items: center;
}

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

Concealing axis lines within the initial circular grid or opting not to include them

Is there a way to incorporate some whitespace within the center circle of the radar chart? I'm aiming for the axis to commence at 1 radius (the initial circular line) or perhaps have the stoke set to 0 for the primary radius. Any assistance would be g ...

Utilizing HTML and JavaScript to add grayscale effect to images within a table, with the ability to revert to the colored version upon mouseover

Seeking advice on utilizing the mouseover / mouseout event in javascript to implement grayscale on a table. The challenge requires creating a gray image grid (table) using HTML and then incorporating Javascript so that hovering over an image triggers it to ...

Attempting to style text during extraction from webpage source code

I'm facing some challenges with formatting the album title and artist name from a lyrics website while working on counting words in a song. An example of what's been troubling me is shown below: https://i.sstatic.net/oarOI.png The desired forma ...

What is the best way to incorporate three divs into a single line while maintaining a responsive design

Struggling with adding a logo above a login form? As a PHP developer without design expertise, achieving a responsive layout like the image below may seem daunting. To create this layout, consider using the following code: <style> .container { ...

Interactive HTML5 map featuring geo tagged points

Seeking an HTML5-based tool to efficiently display a zoomable, panable map (similar to Google Maps) and incorporate a circle at a specific location upon clicking a button on a webpage. Any suggestions for HTML5-compatible frameworks or would JQuery be the ...

Tips for managing an event using the bxSlider callback API

I am currently using bxSlider to create a slideshow on my website. However, I now want to implement a manually controlled slideshow that also displays text content related to each image below the slideshow: Here is the code I have so far: <!--SlideSho ...

Issue with CSS 3 gradient compatibility in Internet Explorer 8

My CSS3 gradient button is working perfectly on all browsers except for IE8. To make it work on IE8, I am utilizing CSS3 Pie. You can see the search button in action by visiting: Upon inspecting my console, I noticed an error on this line: PIE.htc, lin ...

Send an AJAX parameter and retrieve it on the expressjs server side of the application

It seems like there's a crucial piece missing here. Let's begin with an AJAX call that can be executed in the <script> tag to send data to the backend. It might look something like this: function changeDom(){ console.log('connectin ...

Encountering issues with implementing useStyles in Material-UI components

Currently, I am working on a project utilizing Material-UI's library and encountering styling issues. This project marks my initial venture into ReactJS and JavaScript in general. Therefore, any assistance would be greatly appreciated! I am struggli ...

Utilizing special symbols using the Net::Twitter::Lite library

When I attempt to send characters like ü, ä, ß, à, and others to Twitter, they appear incorrectly. Using unicode characters in my scripts results in the characters displaying wrong on Twitter. Even when utilizing HTML (which has previously worked in Tw ...

MS Edge modifies the attribute's empty value to 1

I have written a JavaScript code to extract values from a list, but in the Windows Edge browser, it returns a value of 1 even when the actual value of the <li> tag is blank. For example: HTML Code <ul> <li value="">Test 1</li&g ...

What steps can be taken to deter users from bookmarking URLs?

On my website, the webpages are dynamically generated using the GET method to fetch variables from a specified URL. For instance, consider the code on the main page: index.php <p><a href="/dynamic.php?name1=value1&amp;name2=value2">next p ...

"Utilize Bootstrap's responsive 3-column grid layout for a sleek design, complete with hidden col-12 elements below each grid

Looking to create a 100% width column below an element within a column of a bootstrap grid. For better understanding, here is what I'm aiming for: https://i.stack.imgur.com/pl1Fi.png On selecting one of the images (from 1 to x), a hidden div with di ...

Tips for ensuring compatibility of CSS in IE7 and IE8

Despite using the following styles to dynamically display alternative colors in my HTML code, I am facing compatibility issues with IE7 and IE8. Surprisingly, everything works perfectly fine on IE9 and above. It seems these styles are not supported by IE7 ...

Is it acceptable to duplicate and replace content directly from the Google Inspector tool?

As I work on creating a new woocommerce checkout page, I encountered some issues. My approach to extracting code from woocommerce involved inspecting the Code and copying it directly into my checkout file at /woocommerce/checkout/checkout.php. Is this met ...

Hovering over a class list will modify various element IDs

Is there a way to change the height of an element with id = "header_nav" when hovering over the class "header_nav" li element? Here is the HTML Code: <div class="header_nav" id="header_nav"> <ul id="header_nav_mainmenu"> & ...

Enhancing user experience with Bootstrap's body padding and customizable scrollbars

Recently, I encountered an issue with the footer color in bootstrap. To fix this problem, I created a div and removed the extra padding from the body element. You can view the code snippet here: jsfiddle.net/wctGM/9/ However, when viewing the mobile ver ...

What causes the difference in CSS border-bottom-width rendering between IE and Chrome?

My ASP:MENU is styled with some CSS properties, such as setting the 'height' and 'line-height' of each element to 15px. This design appears fine in Internet Explorer but seems too cramped in Chrome. Additionally, a 'border-bottom-s ...

Is it achievable to have a background image cover size with a responsive rollover effect?

I’m currently facing a unique challenge where I want to have an image as the background of my website, with the size set to cover the entire screen. On this background image, there are elements like buildings that I want to interact with when hovered ove ...

It is not possible to highlight the text that appears in the title of the tooltip in React MUI

Within my react application, there is a component that utilizes the code snippet below: <FormControlLabel labelPlacement="top" control={ comp?.manualInput ? ( <TextField name="price" type= ...