Struggling to line up the header perfectly with the button

I am brand new to CSS and I have set up a header and a navbar. However, when attempting to position the button next to the header, it is appearing in the navbar line instead. I have tried using the float property, but the issue remains. Here is a snippet of the code:

Sample Code

.wrapper {
  margin: 0;
  background-color: #fff;
}

header {
  height: 120px;
  padding: 4px;
}

header h1 {
  font-family: "Amatic Sc";
  text-transform: uppercase;
  font-size: 50px;
  text-align: center;
  color: #000;
}

.btn {
  width: 10;
  height: 2px;
  padding: 1.375rem 2.625rem 1.375rem 2.625rem;
  border: 0.125rem solid #B49DF1;
  border-radius: 2rem;
  background-color: #B49DF1;
  color: #fff;
  font: 700 0.75rem/0 'Open Sans', arial, sans-serif;
  text-decoration: none;
  transition: all 0.2s;
}

.btn:hover {
  background-color: #9876F3;
  border: 0.125rem solid #9876F3;
}
<div class="wrapper">
  <header>
    <h1>Novaturient</h1>
    <---- Button should be placed next to this </header>
      <nav>
        <ul>
          <li class="one"><a href="#home">Home</a></li>
          <li class="two"><a href="#content">Content</a></li>
          <li class="three"><a href="#features">Features</a></li>
          <li class="four"><a href="#about">About</a></li>
          <li class="fice"><a href="#contact">Contact</a></li>

        </ul>
      </nav>
</div>

Answer №1

Technique 1:
Placing the button within the header and setting its position: absolute. The header is styled with position: relative;, enabling the button to move freely within the header. We position the button at the bottom of the header by styling it with bottom: 0;.

.wrapper {
  margin: 0;
  background-color: #fff;
}

header {
  position: relative;
  height: 120px;
  padding: 4px;
}

header h1 {
  font-family: "Amatic Sc";
  text-transform: uppercase;
  font-size: 50px;
  text-align: center;
  color: #000;
}

nav ul{
  list-style: none;
  display: flex;
  justify-eontent: center;
}

nav ul li {
  margin: 0 10px;
}

.btn {
  width: 10;
  height: 2px;
  padding: 1.375rem 2.625rem 1.375rem 2.625rem;
  border: 0.125rem solid #B49DF1;
  border-radius: 2rem;
  background-color: #B49DF1;
  color: #fff;
  font: 700 0.75rem/0 'Open Sans', arial, sans-serif;
  text-decoration: none;
  transition: all 0.2s;
  position: absolute;
  bottom: 0;
}

.btn:hover {
  background-color: #9876F3;
  border: 0.125rem solid #9876F3;
}
<header>
  <h1>Novaturient</h1>
  <!--Here-->
    <nav>
      <ul>
        <li class="one"><a href="#home">Home</a></li>
        <li class="two"><a href="#content">Content</a></li>
        <li class="three"><a href="#features">Features</a></li>
        <li class="four"><a href="#about">About</a></li>
        <li class="fice"><a href="#contact">Contact</a></li>
      </ul>
    </nav>
    <button class="btn">Learn More</button>
</header>

Method2:
The button is placed outside the header, also styled with position: absolute;, but this time positioned using top set to 120px (equal to the header height).

.wrapper {
  margin: 0;
  background-color: #fff;
}

header {
  position: relative;
  height: 120px;
  padding: 4px;
}

header h1 {
  font-family: "Amatic Sc";
  text-transform: uppercase;
  font-size: 50px;
  text-align: center;
  color: #000;
}

nav ul{
  list-style: none;
  display: flex;
  justify-content: center;
}

nav ul li {
  margin: 0 10px;
}

.btn {
  width: 10;
  height: 2px;
  padding: 1.375rem 2.625rem 1.375rem 2.625rem;
  border: 0.125rem solid #B49DF1;
  border-radius: 2rem;
  background-color: #B49DF1;
  color: #fff;
  font: 700 0.75rem/0 'Open Sans', arial, sans-serif;
  text-decoration: none;
  transition: all 0.2s;
  position: absolute;
  top: 120px;
}

.btn:hover {
  background-color: #9876F3;
  border: 0.125rem solid #9876F3;
}
<header>
  <h1>Novaturient</h1>
  <!--Here-->
    <nav>
      <ul>
        <li class="one"><a href="#home">Home</a></li>
        <li class="two"><a href="#content">Content</a></li>
        <li class="three"><a href="#features">Features</a></li>
        <li class="four"><a href="#about">About</a></li>
        <li class="fice"><a href="#contact">Contact</a></li>
      </ul>
    </nav>
</header>

<button class="btn">Learn More</button>

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

Break down the string and iterate through using AngularJS

When looking at a string in the format "Something for example $takeThis $takeThisAlso", I need to parse it and extract all substrings that are enclosed within $ ($xxx). This means I want to achieve something like this: foreach($xxx in list) { var field ...

Creating an interactive table in HTML with dynamic content sourced from JSON data is made easy with Dat

I am in the process of constructing a table utilizing data from a php script which returns JSON, incorporating the datatables plugin. Provided below is the code I have written: HTML: <table id="patients" class="table table-striped table-hover"> & ...

Maintaining aspect ratio of canvas while ensuring responsiveness

Currently, I am working on a drawing app and have come across an issue that has been challenging for me to resolve. The dilemma lies in resizing the canvas of sketches from the original resolution of 1280 x 720 to the maximum size possible upon opening the ...

Obtain user input from a form and assign it to a variable in a jQuery AJAX

How can I pass the value of an HTML Input Form to a jQuery AJAX call's URL as `amt` in `url: "http://localhost:8080/orderNo?amount=" + amt,`? The input value logs to the console when calling getAmtValue(), but I'm struggling to access the `amt` ...

kit material for rtl radio input

Struggling to convert the radio button to RTL format. Can anyone assist me with this? <div class="form-check" style="width: 49%;text-align: right;position: inherit;display: inline-block;"> <label class="form-check-label"> <input class ...

What is the reason behind the addition of '.txt' by the Next.js `Link` Component when redirecting to `href='/'` on GitHub pages?

My website is hosted on github-pages, and I am using the Link Component from Next.js to navigate within it. However, when I click on a component with the href="/", it adds .txt to the end of the URL. My website follows the /app structure. I have ...

Change the first letter to uppercase in GTM Data Layer variable

Can someone help me with capitalizing the first character of a string inputted by a user? Here is the listener tag that gathers the firstname data: `<script> (function () { var element = document.querySelector('input[name="firstname" ...

Unable to set margin-right on a relatively positioned element

In my Vue project, I am creating a dynamic card display that scrolls horizontally on mobile screens. This section functions as a testimonial carousel where users can swipe left or right to view different testimonials. While I have successfully applied a l ...

Collapse the accordion item when a different one is selected

Check out this code snippet that's working on jsfiddle I'm attempting to add a function to close any open accordion items when another one is clicked. I've added a class "open", but I'm having trouble removing the class when a differen ...

Error encountered at /: Parsing error found for 'product.tk' in 'main-product-detail'product.tk'

I've encountered a persistent issue while trying to add links in my home.html files for the product detail page. An error keeps popping up: TemplateSyntaxError at / Unable to parse remaining: 'product.tk' of ''main-product-detail&a ...

Utilizing Kendo MVVM to Bind to an Self-Executing Anonymous Module Function

Currently, I am experimenting with the Kendo UI MVVM framework and attempting to bind it to a self-executing anonymous modular function. The situation is a bit complex, as the functionality is only somewhat working. Although the module is being updated whe ...

Utilizing a preset canvas for the renderer can lead to issues

As I dive into tutorials on three.js, I encounter a challenge when using my predefined canvas elements for the renderer. Everything works smoothly if I let three.js create the renderer DOM element. However, when I attempt to retrieve the canvas using getEl ...

Changing the font-family to 'Symbol' and using Windows-1252 character encoding

I have a collection of HTML documents that contain basic text encoded in Windows-1252, but scattered throughout the content are various instances of span elements styled with font-family: Symbol. For instance: <span style='font-family:Symbol& ...

Positioning a div towards the bottom right corner of another element

I have two divs nested inside another div. One of them is a table displaying a list of items that can be updated by entering text into a textbox positioned next to it. I am struggling to position the textbox in the bottom right corner despite trying variou ...

Extract data from a URL using PHP and JavaScript technologies

Upon receiving a json data from a URL, specifically through celery's flower plugin, the following sample is obtained: { "celery@s1": { "scheduled": [], "stats": { "clock": "2535550", "pid": 26002, "broker": { "tran ...

When the width of the element is set to 100vw, it disrupts the

I'm attempting to expand a sticky element to fit the size of the screen. Here is the HTML code I am using: .large { height: 200vw; width: 200vw; } .header { left: 0; top: 0; color:white; position: sticky; width: 100px; height: 10 ...

Is your URL getting cut off in jQuery?

How can I properly display a URL in an HTML table without it getting truncated? I'm attempting to show it within a table using jQuery, but it seems to be cutting off the URL. Here's a snippet of my code. Any suggestions on how to fix this? <! ...

Collection of numbers with decimal points

Can one use <li> numbers in this format?: 1.1 First Item 1.2 Second Item 2.1 Other item ...

What is the actual storage mechanism for HTML5 WebStorage data?

While utilizing the HTML5 WebStorage functionality, I am aware that certain browsers such as Chrome offer developer tools for users to navigate through their WebStorage contents for debugging and troubleshooting purposes. I am curious if it is feasible to ...

I struggle with generating a transition effect in the input box through label transformation

Why is the input box not using the specified CSS styles for the input and label tags? The transform property doesn't seem to be working as expected. I've highlighted the areas where I'm facing issues with bold text, and I've included bo ...