Firm emblem obstructs individual avatar

I have noticed a strange issue with my header layout. When I include the hamburger menu and user icon, they align perfectly in a row. However, as soon as I add the company logo, the user icon shifts downward and breaks the alignment.

I have tried adjusting padding-top, margins, and other properties to fix this issue, but nothing seems to work. It's almost like the layout is frozen in place.

Does anyone have any suggestions on what might be causing this problem and how I can resolve it?

$(document).on('click', function(e){
 if(e.target.type == "checkbox")
     return;
 else{
    var elem = $('#menuToggle').find('input[type=checkbox]');
    if($(elem).prop('checked')){
      $(elem).trigger('click');
    }
 }   
});
.headlogo {
display: block;
margin-left: auto; 
margin-right: auto;

}
.userlogo {
display: block;
float: right;
margin-right: 20px;
  margin-top: 10px;

}
/*
 * Made by Erik Terwan
 * 24th of November 2015
 * All rights reserved
 *
 *
 * If you are thinking of using this in
 * production code, beware of the browser
 * prefixes.
 */

body
{
  overflow-x: hidden;
  margin: 0;
  padding: 0;
  font-family: "Avenir Next", "Avenir", sans-serif;
}

a
{
  text-decoration: none;
  color: white;
  transition: color 0.1s ease;
}

a:hover
{
  color: black;
}
nav {
display: inline-block;
}
#menuToggle
{
  display: block;
  position: relative;
  top: 50px;
  left: 50px;
  
  z-index: 1;
  
  -webkit-user-select: none;
  user-select: none;
}

#menuToggle input
{
  display: block;
  width: 40px;
  height: 32px;
  position: absolute;
  top: -7px;
  left: -5px;
  
  cursor: pointer;
  
  opacity: 0; /* hide this */
  z-index: 2; /* and place it over the hamburger */
  
  -webkit-touch-callout: none;
}

/*
 * Just a quick hamburger
 */
#menuToggle span
{
  display: block;
  width: 33px;
  height: 4px;
  margin-bottom: 5px;
  position: relative;
  
  background: black;
  border-radius: 3px;
  
  z-index: 1;
  
  transform-origin: 4px 0px;
  
  transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
              background 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
              opacity 0.55s ease;
}

#menuToggle span:first-child
{
  transform-origin: 0% 0%;
}

#menuToggle span:nth-last-child(2)
{
  transform-origin: 0% 100%;
}

/* 
 * Transform all the slices of hamburger
 * into a crossmark.
 */
#menuToggle input:checked ~ span
{
  opacity: 1;
  transform: rotate(45deg) translate(-2px, -1px);
  background: white
}

/*
 * But let's hide the middle one.
 */
#menuToggle input:checked ~ span:nth-last-child(3)
{
  opacity: 0;
  transform: rotate(0deg) scale(0.2, 0.2);
}

/*
 * Ohyeah and the last one should go the other direction
 */
#menuToggle input:checked ~ span:nth-last-child(2)
{
  opacity: 1;
  transform: rotate(-45deg) translate(0, -1px);
}

/*
 * Make this absolute positioned
 * at the top left of the screen
 */
#menu
{
  position: absolute;
  width: 400px;
  margin: -100px 0 0 -50px;
  padding: 50px;
  padding-top: 125px;
  float: left;
  background: black;
  list-style-type: none;
  -webkit-font-smoothing: antialiased;
  /* to stop flickering of text in safari */
  
  transform-origin: 0% 0%;
  transform: translate(-100%, 0);
  
  transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0);
}

#menu li
{
  padding: 10px 0;
  font-size: 22px;
}

/*
 * And let's fade it in from the left
 */
#menuToggle input:checked ~ ul
{
  transform: scale(1.0, 1.0);
  opacity: 1;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header>
<nav role="navigation">
  <div id="menuToggle">
    <input type="checkbox" />
    <span></span>
    <span></span>
    <span></span>
    <ul id="menu">
      <a href="#"><li>Home</li></a>
      <a href="#"><li>About</li></a>
      <a href="#"><li>Info</li></a>
      <a href="#"><li>Contact</li></a>
      <a href="#"><li>Contact</li></a>
      <a href="#"><li>Contact</li></a>
      <a href="#"><li>Contact</li></a>
      <a href="#"><li>Contact</li></a>
      <a href="https://erikterwan.com/" target="_blank"><li>Show me more</li></a>
    </ul>
  </div>
</nav>
<img class="headlogo" src="http://www.bilder-upload.eu/upload/4483c1-1504701412.png">
<i class="fa fa-2x fa-user userlogo" aria-hidden="true"></i>

</header>

If you want to remove the logo, simply delete the 'src' from the image with the 'headlogo' class.

Thank you to everyone who can provide assistance. :)

Answer №1

Adjust the top and left styles to 0 on the #menuToggle element, then experiment with using flexbox within the header tag.

display: flex;
align-items: center;

To see the changes in action, visit this fiddle: https://jsfiddle.net/vxqzw8sz/2/

Answer №2

When block level elements lack a specified width or are floated or positioned differently, they will automatically occupy the entire width of the browser. This results in your icon being pushed down to the next level due to insufficient space.

For instance, try removing the display:block; property from your image and observe how the icon shifts upward.

I could provide more tips, but any changes made might impact the positioning of your menu, so it's something you'll need to address separately.

Answer №3

The reason your logo is appearing as display: block is because by default, display: block elements take up the entire width of their container. This causes the next element (user icon) to drop down to the next line. To achieve the desired effect, it's better to use flexbox. You can refer to Ovidiu Unguru's explanation in this answer and check out the JSFiddle example for more details on implementing flexbox.

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

Tips for expanding the width of an image when employing position:relative

Below is the code snippet: <table border="1" cellpadding="2" cellspacing="2" height="250"> <tbody> <tr> <td> <div style="background: url('path to image'); width: 300px; height: 250px; position: ...

What steps can be taken to ensure a function operates even when the mouse is stationary?

$(document).ready(function() { var score = 0; $("body").mousemove(function() { score++; $("#result").val(score); console.log(score); }); }); As I move my mouse, the score keeps increasing. But, I'm wonde ...

Creating a scrollable div with a fixed background using HTML

Attempting to create a full-screen image background with a scrollable div in its center, I crafted the following code: <!doctype html> <html> <head> <meta charset="utf-8"> <title>Bio</title> <link href="../css/layout ...

ag-grid: Enable row dragging by allowing users to drag the entire row

Currently, I am utilizing the Vue version of ag-grid 21.2.1 (https://www.ag-grid.com/vue-getting-started/) and successfully integrated Row Dragging (https://www.ag-grid.com/javascript-grid-row-dragging/) feature on one of our tables. Everything is function ...

Enhance your form input-group in Bootstrap-4 by adding a stylish border and background-color through validation

I'm working on a form using Bootstrap 4 and I need to display validation errors. Specifically, I want the text field with an input-group for the password to have the same styling as the Username field when there is an error (i.e., red border and backg ...

Is it a universal rule for embedded css to take precedence over external css?

In my previous studies, I had learned that embedded CSS always takes precedence over external CSS. However, I have discovered that the styles that come last in the code actually prevail. Consider the following code snippet where I have used color:green; i ...

Tips for duplicating all data shown using v-for in Vue and saving it to the clipboard

I have a page that displays threaddump information using cards. The threaddump information is shown using v-for loops, but the issue is that when I copy it, only a single loop of data gets copied with my current copyThreadInfoToClipboard method. Therefor ...

What steps can I take to ensure that the browser prints out a PDF copy of a webpage?

Imagine you have a website page saved as example.html, and also a printable file named example.pdf. Is there a way to prompt the browser to open and print example.pdf instead of example.html when users attempt to print? If this isn't achievable, how ...

Column division shifting beneath the column division that has the greatest height above

I'm currently using a PHP loop to generate and showcase articles (as 'col' divs) from the MySQL database. However, when I use 3 "col-6" divs, the 3rd one ends up moving below the other two instead of staying right next to the first div. Any ...

Troubleshooting a problem with dynamic options in Materialize select set

I'm currently facing an issue with my two dependent dropdowns, country and state. When I select a country, I use JavaScript to populate the respective states in the state dropdown. However, even though the options are added correctly when I inspect th ...

Can someone provide instructions on how to make a header with Bootstrap?

As a react native developer, I am currently working on a project that involves exporting PDF files from mobile devices. The challenge lies in my lack of expertise in web development and the requirement for the file to be in HTML format. The design I am aim ...

What is the best way to pass the index value of a v-for loop as an argument to a computed property function in Vue?

I'm looking to pass the index value from a v-for loop (inside a path tag) as a parameter to a function stateData(index) defined in a computed property in Vue. I attempted to achieve this using v-model="stateData[index]", but an error is being displaye ...

Displaying PHP object in an HTML modal showcase

I'm attempting to display an object within an HTML modal. Since the structure is unknown beforehand, and child properties can also be objects or arrays, I thought a simple recursive function might be the solution, but I am uncertain. Here's what ...

Easily move elements using a jQuery click animation

Having trouble animating a div's top position by -130px to move it off screen? Can't figure out why it's not working? I'm fairly new to jQuery/Javascript. I have a button/hyperlink with the ID #NavShrink. When clicked, I want the div # ...

Ways to stop click propagation in the case of a parent anchor link containing a button among its children

Every time I click on the Link parent, it triggers a click event on the button as well. I want these events to be independent. <Link className="product-item__link" to={`/products/${product.category}/${product.id}`} > <div className ...

Sending a div class as a parameter to a JavaScript function

Wondering if it's possible to pass a div's class into a JavaScript function. I'm using SquareSpace so adding an id to the div is not an option, but it works fine with divs that have ids. JQuery is already loaded. This is my current train of ...

What is the best way to animate CSS elements using jQuery to slide in from the right, left, or bottom?

When the page is scrolled on my website, I want table_area-left to move from left to right to its current position, table_area-right to move from right to left to its current position, and morph button to move from down to up. I am struggling to find the j ...

The light slider feature is experiencing technical difficulties within the Bootstrap model

I am experiencing an issue with the Light Slider in a Bootstrap modal. Strangely, when I press F12 for inspect element, the Light Slider starts working. For more details and to see the link provided in the comment below, can anyone offer assistance, plea ...

Generate an image from HTML code

Is there a method to convert HTML into an image format such as PNG? I am aware this can be achieved using canvas, but I am interested in rendering regular HTML elements like divs. Could you suggest a way to accomplish this? ...

What is the best way to retrieve the date value from ngx-daterangepicker-material?

When utilizing ngx-daterangepicker-material for creating a range date, my goal is to obtain the startdate and enddate values in order to filter the table upon pressing the submit button! Here is the HTML code: <form [formGroup]="filtreForm" ( ...