I am struggling to place the text within my <main> tag between my <header> and <footer> tags

I'm encountering an issue while developing a basic website. The text within the main tag is overlapping with the header tag. I've built simple webpages in the past without facing this problem. Isn't the text in the <main> tag supposed to automatically appear below the header? My understanding of the structure of an HTML page is:

Header
Main
Footer

.header-nav {
  float: right;
  list-style: none;
  margin-top: 10px;
}

.row {
  max-width: 1200px;
  margin: auto;
}

.header-nav li {
  display: inline-block;
}

.header-nav li a {
  color: black;
  text-decoration: none;
  padding: 25px;
  font-family: "Verdana", sans-serif;
  font-size: 14px;
}

.header-nav li.active a {
  border: 1px solid white;
}

.header-nav li a:hover {
  border: 1px solid white;
}

.dota2icon img {
  width: 150px;
  height: auto;
  float: left;
}

.bodytext {
  font-family: "Verdana", sans-serif;
  width: 1200px;
  margin-left: 0px;
  margin-top: 0px;
}

h1 {
  color: black;
  text-transform: uppercase;
  font-size: 24px;
  text-align: left;
}

.footer {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 1rem;
  background-color: #efefef;
  text-align: center;
}
<header>
  <!-- NAVIGATION BAR START -->

  <div class="dota2icon">
    <img src="dota2icon.png">
  </div>
  <div class="row">
    <ul class="header-nav">
      <li><a href="index.html">Home</a></li>
      <li><a href="categories.html">Categories</a></li>
      <li><a href="item.html">Services</a></li>
      <li><a href="myItems.html">Contact</a></li>
    </ul>
  </div>
  <!-- NAVIGATION BAR END -->
</header>


<main>
  <!-- DESCRIPTION -->
  <div class="bodytext">
    <h1>Dota 2 Guides</h1>
    <p>TEST TEST TEST TEST TEST </p>
  </div>

</main>



<div class="footer">

</div>

Answer №1

The class .header-nav is aligned to the right side, causing any content that comes after it and does not have a clear property set to align next to it.

Consider incorporating the clear property or explore alternative layout methods such as utilizing Flexbox or Grid instead of using float.

Answer №2

To resolve the issue, simply include "clear both" in your main CSS styling as shown below:

main{
    clear: both;
}

Example of Working Code

<style type="">
.header-nav {
    float: right;
    list-style: none;
    margin-top: 10px;
}

.row {
   max-width: 1200px;
    margin: auto;
}

.header-nav li {
    display: inline-block;
}

.header-nav li a {
    color: black;
    text-decoration: none;
    padding: 25px; 25px;
    font-family: "Verdana", sans-serif;
    font-size: 14px;
}

.header-nav li.active a {
    border: 1px solid white;
}

.header-nav li a:hover {
    border: 1px solid white;
}

.dota2icon img {
    width: 150px;
    height: auto;
    float: left;
}

.bodytext {
    font-family: "Verdana", sans-serif;
    width: 1200px;
    margin-left: 0px;
    margin-top: 0px;
}

main{
clear: both;
}

h1 {
    color: black;
    text-transform: uppercase;
    font-size: 24px;
    text-align: left;
}

.footer {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 1rem;
  background-color: #efefef;
  text-align: center;
}
</style>
   <!DOCTYPE html>
<html lang="en">    
<head>
<title>Dota 2 Guides</title>
<meta name="description" content="Project">
<meta charset="UTF-8">
<!-- DONT CHANGE, THIS IS THE LINK TO THE CSS STYLESHEET -->
<link rel="stylesheet" type="text/css" href="project.css">
    <script type="text/javascript" src="Project.js"></script>
</head>

<body>    
<header>
<!-- NAVIGATION BAR START -->

    <div class="dota2icon">
    <img src="dota2icon.png">
    </div>
<div class="row">    
<ul class = "header-nav">
<li><a href="index.html">Home</a></li>
<li><a href="categories.html">Categories</a></li>
<li><a href="item.html">Services</a></li>
<li><a href="myItems.html">Contact</a></li>
</ul>
</div>
<!-- NAVIGATION BAR END --> 
 </header>


<main>
    <!-- DESCRIPTION -->
<div class = "bodytext">
    <h1>Dota 2 Guides</h1>
    <p>TEST TEST TEST TEST TEST </p>
    </div>

</main>



    <div class = "footer">

    </div>
</body>
</html>

Answer №3

Setting a fixed height for the <header> element is an easy solution if you are okay with it being static.

header {
  height: 50px;
}

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

Modify the styling of the main webpage using the iframe

Can the CSS of a parent page be modified from an iframe when the parent page and iframe are hosted on separate domains? ...

Display additional information upon hovering without disrupting the neighboring elements

When I hover over a component, I want to display more details and scale it up. However, this action ends up displacing the surrounding components. Take a look at the screenshot for reference: https://i.sstatic.net/ElXvk.jpg Below is the code snippet wher ...

jQuery UI Sortable - Eliminate placeholder once item is has been dropped

Trying to implement a nested sortable feature, and while it's mostly working, there's one little issue bothering me. I'd like the placeholder to only disappear after I release the dragged item (on mouseup), but I'm struggling to achiev ...

What could be causing this Ajax error I'm experiencing?

I am attempting to dynamically load pages on this website using JQuery and Ajax when a menu point is clicked. However, I am encountering errors during the loading process. What does the console message ""GET 'path to css file'" mean? (there ...

What is the best way to reduce the height of the navbar in Bootstrap 4?

Check out my code snippet for implementing Bootstrap 4: <nav class="navbar navbar-collapse navbar-toggleable-md navbar-light bg-faded "> <div class="collapse navbar-collapse" id="navbarText"> <ul class="navbar-nav mr-auto"> ...

What is the best way to replicate the orange outline when focused?

I am in the process of creating a series of divs that can be navigated by the user using the tab key. I would like to incorporate the standard orange focus outline for these elements. Is there anyone who can provide guidance on how to achieve this? I unde ...

The python parser extracts symbols from HTML instead of words

Currently attempting to extract data from a website's HTML using lxml and XPath. The process appears to be functioning correctly, however it is yielding results that are not expected : from lxml import html import requests page = requests.get(' ...

Gather information from every user and display their user ID in an HTML table, allowing for updates through a button

Can anyone help me create a table like the one shown here: https://i.sstatic.net/Hj4T9.png The table should fetch data from my firebase database. Here is the structure of my requests database: https://i.sstatic.net/0lJGa.png. I've been trying to mo ...

The display:block links are not properly positioned within the absolute div

I'm having trouble figuring out why my links are not working for the .pushMenu divs on the left and right side, html: <header class="header"> <div class="pushMenu" id="left"> <a href="" title=""><p>l</p>< ...

What is the best way to change the value of an input element (with type='month') to a string format "yyyy-MM"?

Need help converting the input value (type: month) to the format "yyyy-MM". HTML code snippet: <input class="bg-success btn btn-dark" type="month" id="timeCheckTimeSheets" ng-model="month"> AngularJS snippet: $http({ url: url + $scope.p ...

Solving the Dilemma of Ordering Table Rows by Value in JavaScript

I am currently working on a table and my goal is to display rows in an orderly manner based on the sum of their columns. Essentially, I want the rows with the highest values to be displayed first, followed by rows with second highest values, and so on. Des ...

Tips for establishing a fixed point at which divs cease to shrink as the browser size decreases

There are numerous dynamically designed websites where divs or images shrink as the browser size decreases. A great example of this is http://en.wikipedia.org/wiki/Main_Page The div containing the text shrinks proportionally to the browser size until it ...

Invoking a function using an identifier for modification

I am currently developing a solution, and here is my progress so far: http://jsfiddle.net/k5rh3du0/ My goal is to invoke a function using both the onLoad and onerror attributes with an image. <img src="http://www.etreeblog.com/favicon.ic0" alt="status ...

Vuetify's offset feature seems to be malfunctioning as it does not

I'm facing an issue with the <v-flex> element in my code, specifically with the offset property not responding as expected. Despite following the recommended layout from the vuetify docs, I can't seem to get it right. Below you can see the ...

Imported font is functioning correctly when viewed locally but fails to load when accessed from the web

After completing the main page of my website, I encountered an issue with the font imported from Google. Surprisingly, it displays perfectly when viewed locally but does not show up once uploaded to my web server. Could there be a compatibility issue? For ...

Ensuring File Size and Format Compliance in Angular's HTML and TypeScript

I'm currently tackling a file upload feature on an ASP.net webpage using Angular. I have a question: How can I verify if the uploaded file is either a PDF or JPG and does not exceed 2MB in size? If these conditions are not met, I would like to displa ...

Ways to customize the appearance of an iframe's content from a separate domain

I am facing a challenge with my widget and multiple websites. The widget is hosted on one domain, but the websites use an iframe to display it. Unfortunately, because of the Same Origin Policy, I cannot style the content of the iframe from the parent websi ...

Struggling to have PHP process and store form data in MySQL database

I am attempting to process HTML form data into a MySQL database using PHP for the first time, and I am feeling overwhelmed. The form is POSTed to the formSubmit.php file, where the variables are created for the SQL command to query. I have tried adjusting ...

How can I create editable text using typed.js?

How can I achieve the same text animation effect on my website as seen on the homepage of ? I want to utilize the library available at . Specifically, how do I stop the animation when the text is clicked, allowing users to input their own text? Below is ...

Blurring the background creates an "inset shadow" problem when transitioning

Problem: Strangely, when using Backdrop-filter: blur(Xpx); during a transition as shown below, unexpected "inset Shadows" mysteriously appear until the end of the transition. https://i.stack.imgur.com/uij7F.gif Illustration of the Issue Using jsfiddle Sp ...