Tips for moving the h1 tag beneath the navigation bar or adjusting its position for a better layout

I am attempting to move this h1 element below my navigation section. Here is how I have structured it: there is a header tag, within the header tag there is a container tag, inside the container tag is the h1 tag, and after the h1 tag there is a nav tag which contains a ul with li elements.

.container {
  width: 50%;
  margin: auto;
}


/* Header */

header {
  height: 100vh;
}

header h1 {}


/* An unordered list is basically an array of items*/

ul {
  list-style-type: none;
  float: right;
  /* Top bottom right left*/
  /* Margin-top pushes it down.*/
}


/* List item specifies how it should be aka 1 item of the array */

li {
  display: inline-block;
  /* Top bottom right left*/
}


/* A means all the links */

a {
  text-decoration: none;
  text-transform: uppercase;
  color: black;
  padding: 5px 20px;
  /* Separates them */
  border: 1px solid transparent;
}
<div class="container">
  <h1>Random Number Generator</h1>
  <nav>
    <ul>
      <li class="active"><a href="#Home">Home</a></li>
      <li><a href="#About">About</a></li>
      <li><a href="#Contact">Contact</a></li>
    </ul>
  </nav>
</div>

Answer №1

Insert the h1 element right after the nav

 <div class="container"> 
   <nav> 
      <ul> 
         <li class="active"><a href="#Home">Home</a></li> 
         <li><a href="#About">About</a></li> 
         <li><a href="#Contact">Contact</a></li> 
       </ul> 
   </nav>
   <h1>Random Number Generator</h1>
 </div>

Answer №2

By repositioning the <h1> tag after your <nav> element, you are essentially placing the header below the navigation within the DOM (document object model).

.container {
  width: 50%;
  margin: auto;
}


/* Header */

header {
  height: 100vh;
}

header h1 {}


/* An unordered list is basically an array of items*/

ul {
  list-style-type: none;
  float: right;
  /* Top bottom right left*/
  /* Margin-top pushes it down.*/
}


/* List item specifies how it should be aka 1 item of the array */

li {
  display: inline-block;
  /* Top bottom right left*/
}


/* A means all the links */

a {
  text-decoration: none;
  text-transform: uppercase;
  color: black;
  padding: 5px 20px;
  /* Seperates them*/
  border: 1px solid transparent;
}
<div class="container">
  <nav>
    <ul>
      <li class="active"><a href="#Home">Home</a></li>
      <li><a href="#About">About</a></li>
      <li><a href="#Contact">Contact</a></li>
    </ul>
  </nav>
  <h1>Random Number Generator</h1>
</div>

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

Transform CSS into JavaFx CSS

Currently, I am working on migrating a web application to JavaFX and need to style it in the same way as the original CSS. However, when attempting to load the CSS from the web project into JavaFX, I realized that the styles were not being reflected. Upon ...

Prevent images from displaying on smaller screens by utilizing Bootstrap's responsive design

Here is a snippet of code that utilizes Bootstrap 4 to display text and images: <div class="container"> <div class="row"> <div class="col-xl-12"> <img src="~/img/img1.png" style="height:60.3px;width:750px" clas ...

After making an Ajax call using AngularJS in a PHP file, I expected to receive only a success or fail message. Instead, I received the entire HTML page code along

After making an Ajax call using AngularJS in a PHP file, I expected to receive only a success/fail message. However, I ended up receiving the full HTML page code along with tags. Here is my AngularJS code: $http.post('ajax_Location.php',{ &apos ...

Developing a unique attribute using AngularJS

As a beginner in AngularJS, I am experimenting with creating directives to manipulate the background-color of a <div> based on specific conditions. I aim to write code like this within my view: <div effect-color="#2D2F2A">content here</div& ...

The getImageData function is returning undefined RGB values

I am trying to create a feature where by clicking on an image, I can retrieve the RGB values of that specific pixel. Below is the code snippet I have implemented: <html> <body> <canvas id="kartina" width="500" height="500"></canvas&g ...

Using JSON data to populate the jQuery UI Datepicker

Is it possible to populate this jQuery UI datepicker calendar with data from a JSON file containing all non-working days for the years 2017 and 2018? P.S. return [!(month == 8 && day == 27), 'highlight', highlight]; - This example demons ...

Should I import a CSS file into a JavaScript file or link it to an HTML file?

Upon joining a new project, I noticed an interesting method for importing stylesheets. Instead of the usual HTML linking method, the stylesheet is imported into each page's JS file like this: import "../../style.css"; Usually, CSS styleshe ...

The Bootstrap navbar collapse fails to expand in the appropriate location

Whenever I try to expand the navigation on mobile mode by clicking the button, it doesn't push the content downwards. Instead, it just opens a small menu next to the button. Did I make a mistake in my code? <div class = "container"> ...

Ways to manage the gap among flex items

I'm currently going through some educational material on Codeacademy, and I'm curious about how I can control the spacing between the "locations" text and the three divs below it. The task requires me to create a 15px gap between them, but I am u ...

Place <h1> and <span> side by side on the same line for proper alignment

I am currently utilizing Bootstrap 5 to construct a webpage. The html code I have written is displayed below: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA- ...

Ways to initiate a transition upon clicking a button, causing it to switch from being hidden (`display: none`) to visible (`display: block`)

I'm attempting to create a smooth transition effect when a button is clicked, similar to a toggle function, where the content below it seamlessly shifts instead of abruptly moving. The classic example of this is the Bootstrap navbar hamburger menu, wh ...

Fascinating CSS quandary: does the transparency of a parent element impact the transparency of a child element that is absolutely positioned, but not in relation

Check out this test case: https://jsbin.com/merujogudo/1/edit?html,css,output Should the element with .test class be transparent or not? Note: The current state is as follows: In Chrome and Firefox (latest versions): transparent In IE11: opaque It wou ...

Positioning the box at the exact middle of the screen

I'm trying to center an item on the screen using material ui, but it's appearing at the top instead of the middle. How can I fix this? import * as React from 'react'; import Box, { BoxProps } from '@mui/material/Box'; functio ...

When the screen size is decreased, the CSS borders drop shadow becomes visible

Currently, I am in the process of designing a header for a website. Everything seems to be going smoothly when viewed on my regular, full browser width, displaying exactly as intended, similar to this. However, upon resizing the screen to half its width, a ...

Show a brief description alongside multiple post thumbnails

I have successfully uploaded multiple featured images to my WordPress website using the multiple post thumbnail plugin. Now, I want to showcase them all below the content along with their descriptions. While I have managed to display the main featured imag ...

Cannot submit form data from HTML to PHP

I am having trouble passing data from an HTML form to a PHP page. The form data is not being submitted successfully. Can anyone point out what mistake I might be making? HTML FORM <div id="go"> <form method="get" action="client_authorized.ph ...

Is there a way to prevent the slide-out bar from automatically hiding when selecting an item from its list?

I am facing an issue with my dashboard that has a slideout sidebar. Whenever I press the toggle button, the sidebar slides out as expected. However, when I click on any tab within the sidebar, it hides again. I only want it to hide when toggled. My code is ...

`Using a PHP function parameter within an array: An essential guide`

I'm encountering an issue while declaring a function parameter within my array. Here is the simplified version of what I have: function taken_value($value, $table, $row, $desc) { $value = trim($value); $response = array(); if (!$value) ...

What is the best way to implement responsive html within the Avada theme?

Greetings! Is there a way to apply HTML/CSS code in the Avada theme on WordPress while ensuring it is responsive? Kindly refer to this image. https://i.sstatic.net/GMmg7.jpg ...

Issues with event firing when using the tag

I've been exploring the use tag within an svg element. I managed to get a simple example working on JSFiddle: https://jsfiddle.net/cneLLLqu/ When I click on the red square (outside of the defs and use tags), a message box pops up. However, clicking o ...