What is the best way to position my menu icon and header text in alignment?

I’m having trouble aligning the menu hamburger icon and title on my website. I’ve tried various methods like wrapping them in a div and using display:inline-block, but they still won’t align properly. Can anyone provide guidance on how to achieve this alignment?

@import url(http://fonts.googleapis.com/css?family=Raleway:500);
 *,
*:before,
*:after {
  box-sizing: border-box;
}
.menu-wrapper {
  position: relative;
  width: 250px;
  height: 250px;
  margin-top: 60px;
  margin-left: 30px;
}
.menu {
  position: relative;
  width: 36px;
  height: 6px;
  background-color: #707070;
  user-select: none;
  transition: all 0.25s ease-in-out;
  cursor: pointer;
  margin: 5px;
  color: #707070;
  -webkit-perspective: 1000;
  -webkit-backface-visibility: hidden;
  -webkit-transform: translate3d(0, 0, 0);
  -webkit-tap-highlight-color: transparent;
}
.menu label {
  cursor: pointer;
  position: absolute;
  font-family: 'Raleway', sans-serif;
  font-size: 40px;
  line-height: 30px;
  top: -12px;
  left: 48px;
}
.menu:hover > ul.nav-links,
.menu.open > ul.nav-links {
  transition: all 0.25s ease-in-out;
  opacity: 1;
  width: 180px;
  transform: translateX(15px);
  pointer-events: auto;
}
.menu:after,
.menu:before {
  content: "";
  position: absolute;
  width: 36px;
  height: 6px;
  background-color: #707070;
  transition: all 0.25s ease-in-out;
}
.menu:after {
  top: 12px;
}
.menu:before {
  top: -12px;
}
.menu:hover,
.menu.open {
  background-color: transparent;
}
.menu:hover::after,
.menu:hover::before,
.menu.open::after,
.menu.open::before {
  transition: all 0.3s ease-in-out;
  width: 18px;
}
.menu:hover::after,
.menu.open::after {
  transform: translate(3px, -7px) rotate(405deg);
}
.menu:hover::before,
.menu.open::before {
  transform: translate(12px, 17px) rotate(-405deg);
}
.menu ul.nav-links {
  margin: 0;
  padding: 36px 0 0 0;
  opacity: 0;
  transform: translateX(-15px);
  transition: all 0.25s ease-in-out;
  position: absolute;
  width: 0;
  height: 0;
  pointer-events: none;
}
.menu ul.nav-links li {
  width: 100%;
  padding: 4px 8px;
  list-style-type: none;
  font-family: 'Raleway', sans-serif;
  font-size: 25px;
  text-transform: uppercase;
  transition: all 0.25s ease-in-out;
  border-left: 2px solid #707070;
}
.menu ul.nav-links li:hover,
.menu ul.nav-links li.active {
  color: #707070;
  border-left: 2px solid #707070;
}
@import url('https://fonts.googleapis.com/css?family=...')
...
<header class="nav-down">

  <!-- Open on hover menú -->
  <div class="menu-wrapper">
    <div class="menu">

      <ul class="nav-links">
        <li><a href="index.html">Home</a>
        </li>
        <li><a href="about.html">About</a>
        </li>
        <li><a href="#">Portfolio</a>
        </li>
        <li class="active"><a href="#">Projects</a>
        </li>
        <li><a href="#">Contact</a>
        </li>
      </ul>
    </div>
  </div>
  <div class="">
    <h1>William Chen</h1>
    <ul class="social">
      <li class="dribble"><a href="https://..." target="_blank"><i class="fa fa-d... fa-3x"></i></a>
      ...
    </ul>
  </div>
</header>

Answer №1

Check out this updated JsFiddle link: https://jsfiddle.net/xy7n3j9p/1/

I made a tweak to the .menu margin and introduced a new ID called "william" to adjust the margin to the left.

.menu {
  position: relative;
  width: 40px;
  height: 10px;
  background-color: #808080;
  user-select: none;
  transition: all 0.25s ease-in-out;
  cursor: pointer;
  margin: 25px;
  color: #808080;
  -webkit-perspective: 1200;
  -webkit-backface-visibility: visible;
  -webkit-transform: translate3d(5px, 0, 0);
  -webkit-tap-highlight-color: transparent;

}

#william {  
margin-left: 200px; 
}

Answer №2

There are numerous comments on this topic, but none of them mention the most straightforward solution.

You can enclose both problematic elements in a div (or not, as long as the combined widths of menu-wrapper and head are <= 100%).

To achieve this, simply add the following to both the .menu-wrapper and .head classes:

.menu-wrapper, .head { 
   float:left;
}

By doing so, you can place them side by side on the same row, allowing you to use padding and line heights for a more aesthetically pleasing alignment.

Answer №3

Upon reviewing the code snippet, it appears that the desired outcome is achieved with the following implementation:

@import url(http://fonts.googleapis.com/css?family=Raleway:500);
 *,
*:before,
*:after {
  box-sizing: border-box;
}
.menu-wrapper {
  position: relative;
  width: 250px;
  height: 250px;
  margin-top: 60px;
  margin-left: 30px;
  text-align: justify;
}
.menu {
  position: relative;
  width: 36px;
  height: 6px;
  background-color: #707070;
  user-select: none;
  transition: all 0.25s ease-in-out;
  cursor: pointer;
  margin: 5px;
  color: #707070;
  -webkit-perspective: 1000;
  -webkit-backface-visibility: hidden;
  -webkit-transform: translate3d(0, 0, 0);
  -webkit-tap-highlight-color: transparent;
} (...)</answer3>
<exanswer3><div class="answer" i="42098210" l="3.0" c="1486484548" m="1486519641" a="VGhhbmFzaXMxMTAx" ai="7053344">
<p>After thorough analysis, I believe the provided code effectively accomplishes what you intended:</p>

<p><div>
<div>
<pre class="snippet-code-css lang-css"><code>@import url(http://fonts.googleapis.com/css?family=Raleway:500);
 *,
*:before,
*:after {
  box-sizing: border-box;
}
/* Other CSS styles from the snippet */
...
 <h1>William Chen</h1>
<div class="menu-wrapper">
  <div class="menu">

    <ul class="nav-links">
      <li><a href="index.html">Home</a>
      </li>
      <li><a href="about.html">About</a>
      </li>
      <li><a href="#">Portfolio</a>
      </li>
      <li class="active"><a href="#">Projects</a>
      </li>
      <li><a href="#">Contact</a>
      </li>
    </ul>
  </div>
</div>
<div class="head">

  <ul class="social">
    <li class="dribble"><a href="https://dribbble.com/WilliamC" target="_blank"><i class="fa fa-dribbble fa-3x"></i></a>
    </li>
    <li class="twitter"><a href="https://twitter.com/CookieWilliamC" target="_blank"><i class="fa fa-twitter fa-3x"></i></a>
    </li>
    <li class="behance"><a href="https://www.behance.net/WilliamC" target="_blank"><i class="fa fa-behance fa-3x"></i></a>
    </li>
    <li class="googleplus"><a href="https://plus.google.com/102927761095010198782" target="_blank"><i class="fa fa-google-plus fa-3x"></i></a>
    </li>
    <li class="github"><a href="https://github.com/monsterwill" target="_blank"><i class="fa fa-github fa-3x"></i></a>
    </li>
  </ul>
</div>

For further reference, you can access the code on JSFiddle here.

To make minor adjustments, I recommend moving the h1 element to the top and adding this line within the h1 CSS:

margin-bottom: -80px;

This tweak will ensure proper alignment and spacing for your design.

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

NextJS compilation sometimes results in undefined errors when using Sass styles

My peace lies in the sass code: .link display: inline-table text-align: center align-self: center margin: 5px 15px font-size: 20px color: black text-decoration: none transition: 0.1s ease-in-out .link:hover text-decoration: underline .l ...

The alignment of Material-UI Button and ButtonGroup is not consistent

I'm puzzled as to why the Button and ButtonGroup elements are not aligned on the baseline in the code snippet provided. Is there a specific property that can be adjusted on the ButtonGroup element to achieve alignment? <!DOCTYPE html> <htm ...

Text that is not aligned in the middle and has a colored background

After setting up a flexbox container with some flex-items, I encountered an issue: When clicking on either "Overview" or "Alerts", the white background border is not displayed. To highlight the selected item, a class called .selected is triggered which ad ...

Would like a modal to appear upon clicking a cell within a grid

I want to trigger a Bootstrap modal to appear when a cell in my grid is clicked. The modal has already been created, but I'm unsure how to make it pop up when a cell is clicked. <div class="container"> <div class="row"&g ...

What steps should I take to troubleshoot the issue when utilizing full HTML link paths in my links?

I have come across the recommendation to use full link paths between pages on my website for various reasons. However, I am concerned about how to debug and work on my local testing environment when all of the links are using full paths. (Manually replaci ...

Displaying the outcome of an HTML form submission on the current page

Within the navigation bar, I have included the following form code: <form id="form"> <p> <label for="textarea"></label> <textarea name="textarea" id="textarea" cols="100" rows="5"> ...

Media queries for min-width and max-width are being disregarded in inline CSS styling

I am currently designing a pricing page for my Django application, featuring three columns. The intended design is to display all three columns side-by-side when the screen size is more than 768 pixels, and switch to a single column layout with pricing opt ...

What is the method for creating a rectangle with text inside using HTML and CSS?

Hello, I need help with achieving this design using HTML and CSS. Can you assist me, please? https://i.stack.imgur.com/xOHVX.jpg This is what I have attempted so far: Below is my CSS code: .line-lg{ width:120%; text-align: center; border-bot ...

Expanding the Width of Bootstrap 4 Dropdown Button

Currently, I am utilizing Bootstrap 4's dropdown feature. Is there a way to modify the code below so that the dropdown menu that appears upon clicking the button matches the same width as the button itself? It's important to note that the button ...

Inserting HTML code directly after a full-screen height responsive div while utilizing Bootstrap 4

So, I have three main components in my design: a navbar, a content div with sections, and a footer. I've managed to make the design responsive for the navbar and content div, but not for the footer yet. The issue lies with the content container, whi ...

Is it possible to implement a delay period or prompt for user confirmation before the transition can be repeated?

When using CSS to code for an image or box to move when hovered over, there can be unexpected results. If the mouse is positioned within the click area at the beginning of the transition but not at the end, the effect may repeat indefinitely and stutter if ...

Even when columns are present within a Bootstrap row, there may still be a gap on the right

On my webpage, the main div is container-fluid followed by a nav. Next, I have a section where views load in with rows containing content divided into columns or offsets. However, whenever I use the row class on either the section or the div after it, it ...

Issue with sticky navbar in parallax design

I have been working on a website where all pages feature a header and a navbar located just below it. As the user scrolls down the page, I want the navbar to stick to the top of the screen once it reaches that position. However, on one specific page, I am ...

Update overall font size to be 62% for a consistent look across the website

Recently, I developed a browser extension that adds an overlay button to the LinkedIn website. Everything was running smoothly until I discovered that LinkedIn uses a global font-size: 62,5% that completely messes up my design.. https://i.stack.imgur.com ...

Concealing two div elements based on string content

I am working on a unique Wordpress blog post layout that showcases personnel profile cards, displaying 12 individuals at a time. Depending on whether or not a person has a Twitter handle entered in the backend, certain elements should either be shown or hi ...

The arrangement of CSS code is crucial for it to work properly; any deviation from the correct order

I am facing a problem where I am trying to display a circular div using CSS, but it only works if the background image property is set first. Typically, this wouldn't be an issue if the image wasn't being dynamically inserted using PHP code. I ...

What is the best way to ensure the logo remains aligned with the left side of the name and title?

I am looking to have the logo and name/title styled similar to the image below. Additionally, I want the logo to remain on the left side of the name/title when the display screen size is reduced (currently it moves above). Any suggestions would be greatly ...

Removing the "%20" code from URLs in your Django project

Currently, I am using Django 1.3 and implementing template inheritance. However, I have encountered an issue with the /static/ settings path once I navigate away from the home page. The problem arises when I load home.html, which inherits from base.html - ...

Is there a way to automatically load an entire Facebook profile in one go using a program?

Does anyone know a way to automatically download all photos from a Facebook profile, not just thumbnails? I'm thinking of using wget to fetch the page source code and then extract links to images from child a elements of all div with class="rq0e ...

The controller and node js request associated are invisible to my HTML page

Here is my HTML code. I have just created a unique controller for a specific part of the code. <div class="mdl-grid" ng-controller="ValueController"> <div class="mdl-card mdl-shadow--4dp mdl-cell--12-col"> <div class ...