Title appears to be left aligned instead of centered

My H1 is having trouble centering as I increase the font size. It positions correctly with a smaller size (30px), but when I increase the font, it becomes too low from the center even though text-align:center; is not helping to solve the issue. What adjustments do I need to make in order to have my H1 centered within the banner div like this example? Link

If you want to view the code on Jfiddle, here's the link: Jfiddle

body {
  margin: 0;
  padding: 0;
  background-color: #ffffff;
  font-family: sans-serif;
}

.banner {
  width: 100%;
  background-color: #8F3144;
  height: 300px;
  top: 0px;
}


/* LOGO START*/

.banner>img {
  float: left;
  height: 103px;
  width: 140px;
  color: black;
}


/* LOGO END */

.mainh1 {
  font-weight: bolder;
  text-align: center;
  padding-top: 80px;
  color: #ffffff;
  font-size: 50px;
}

.nav {
  list-style: none;
  text-align: right;
  margin: 0;
}

.nav>li {
  display: inline-block;
  font-size: 20px;
  margin-right: 20px;
  padding-top: 20px;
  font-weight: bolder;
}

.nav>li>a {
  text-decoration: none;
  color: #ffffff;
}

.nav>li>a:hover {
  opacity: .5;
}
<div class="banner">
  <img src="logo.png" alt="logo" />
  <ul class="nav">
    <li class="meetsli"><a href="#">Meets</a></li>
    <li class="aboutli"><a href="">Gallery</a></li>
  </ul>
  <h1 class="mainh1">Harrison TEST TEST TEST TEST</h1>
</div>
</div>

Answer №1

float: none;

In my opinion, this solution looks correct. Implement this CSS rule for your h1 element.

Answer №2

The logo's size and position are the reasons behind this issue. To address it, you can utilize absolute positioning on the h1 element with a width of 100%, while also eliminating the padding. Here is an example snippet:

body {
  margin: 0;
  padding: 0;
  background-color: #ffffff;
  font-family: sans-serif;
}

.banner {
  width: 100%;
  background-color: #8F3144;
  height: 300px;
  top: 0px;
}


/* LOGO START*/

.banner>img {
  float: left;
  height: 103px;
  width: 140px;
  color: black;
}


/* LOGO END */

.mainh1 {
  font-weight: bolder;
  text-align: center;
  color: #ffffff;
  font-size: 50px;
  position: absolute;
  width: 100%;
}

.nav {
  list-style: none;
  text-align: right;
  margin: 0;
}

.nav>li {
  display: inline-block;
  font-size: 20px;
  margin-right: 20px;
  padding-top: 20px;
  font-weight: bolder;
}

.nav>li>a {
  text-decoration: none;
  color: #ffffff;
}

.nav>li>a:hover {
  opacity: .5;
}
<div class="banner">
  <img src="logo.png" alt="logo" />
  <ul class="nav">
    <li class="meetsli"><a href="#">Meets</a></li>
    <li class="aboutli"><a href="">Gallery</a></li>
  </ul>
  <h1 class="mainh1">Harrison TEST TEST TEST TEST</h1>
</div>
</div>

Answer №3

To center the main content, add these two properties:

  margin-top:auto;
  margin-botton:auto;

By adding these properties, you should be able to keep the content centered, despite it potentially going off screen with larger fonts.

Alternatively, you can try wrapping the content in a <center> tag

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

streaming an HTML5 video directly from memory source

After retrieving multiple encrypted data using ajax queries and performing necessary manipulations to turn them into a valid video, I find myself at a standstill. The binary of the video is now stored in memory, but I am unsure how to display it. To confi ...

The iteration count and stop code in CSS are failing to function correctly

Is there a way to make this loop once and then stay as is unless the page is refreshed? I've tried multiple methods I came across. Can you modify the code so I can see where the changes are being made? The goal is to have it display once and then per ...

Entering text into the input field with the string "Foo"<[email protected]> is not functioning correctly

The text in my input is initially filled with this string "foo foo"<<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4f2920200f29202061263b">[email protected]</a>>. However, after an insert, the string now l ...

I am experiencing difficulty getting my CSS styles to apply to my application that is being rendered using zappa, express, and node.js

Here is a link to my code: http://pastebin.com/jcLRCrQr Although everything else seems to be working fine - CSS sheets loading correctly, JavaScript files functioning properly - I am facing an issue where the styles are not being applied. An odd thing I ...

Issue with CSS line height - Struggling to determine the precise number of lines

Despite finding an old post on this topic, the most popular answer and other solutions didn't work for many people. Even years later, I am still facing the same issue. My goal is to create a div that is precisely 19 lines tall (ideally aiming for 19. ...

Combining mouse interactions with animated bar transitions

I want to create a graph with dynamic bar height transitions whenever it is drawn or redrawn. Once the bars are displayed, I would like mouse events (mouseenter, mouseleave, and mousemove) to trigger a tooltip showing information about the specific bar bei ...

The margin property in jQuery does not seem to be functioning properly when trying to send

Within the view page, there is jQuery code that sets a margin on a div. Below is the code: <script type='text/javascript'> $('#someID').css('margin-left', '10px'); </script> This code functions proper ...

issue with JavaScript canvas

My task is to develop a Blackberry application, but I have limited knowledge in Java. Since the application requires drawing capabilities, I decided to use HTML5 and JavaScript instead. I started reading some JavaScript tutorials to prepare for this proj ...

Navigate through the contents of a table featuring intricate colspan and rowspan elements, while keeping both headers and left columns in

I am facing a challenge with a dynamically generated table that has complex structure including colspans and rowspans. My goal is to fix the headers and, if possible, even lock the first few rows on the left side while allowing the content of the table to ...

What is the best way to retrieve a table from an HTML page and convert it into a data frame using XML and Rcurl in R programming?

Can someone help me convert a table on the Forbes website into a data.frame? Click here to access the table ...

How do I use jQuery to animate a height increase where the added height is applied to the top of the element?

I am facing a simple issue that I need help resolving. The problem involves hidden content that, once expanded, needs to have a height of 99px. When collapsed, the container holding this content section#newsletter is set to be 65px in height. If you want ...

Modifying td background color according to values in a PHP array

Trying to update the background color of a td element with the code below. However, it seems that the code needs some adjustment as the color is not being applied. Any assistance or alternative solutions would be greatly appreciated. Snippet of PHP code: ...

Adjusting the size of div content without changing its dimensions

I'm in search of a solution for resizing the contents within a fixed width and height div. Currently, my div looks like this: <div id="editor_preview" style="width:360px !important; color:gray; ...

The find function within $(this) is malfunctioning

I'm having issues with displaying/hiding content when clicking on a table row. Here is the simplified code snippet: HTML: <table> <tr onclick="showDetails()"> <td>Some text <br> <span class="hiddenC ...

Steps for building a Bootstrap grid of thumbnails

I need to display an unknown number of thumbs. Below is a sample of the HTML rendered: <div class="row-fluid"> <ul class="thumbnails"> <li class="span3"> <a href="#" class="thumbnail"> &l ...

Tips on concealing unnecessary subdirectories in a Firebase website URL

Looking to shorten the URLs of my webpages hosted on Firebase. The HTML files are located within an "html" folder inside the public directory. Currently, the URL for the index page is: www.lstein-28b62.web.app/htmlfolder/index.html Is there a way to chan ...

I am unable to move HTML data to PHP

Here is my HTML code: <form action="test.php" method="get> <input type="text" name="text" /> </form> And this is my PHP code: <html> <head> <title>Result</title> </head> <body style="background: ...

What could be causing the issue preventing me from applying a border in the code below?

There seems to be an issue in the code below where I am struggling to apply a border Can anyone help identify what the problem might be? <!doctype html> <html> <head> <title> My first Navigation Page</title& ...

The reason the section's height is set to 0 is due to the absolute positioning of the div

Currently, I have a section tag with three divs inside that are positioned absolute (used for the isotope plugin). <section id="section1" class="cd-section"> // pos. static/relative has height 0px <div class="itemIso"> // pos. absolute, he ...

Creating an interactive time selection tool with two dropdown lists that are dependent on each other using HTML and JavaScript

Hi everyone, I am new to JavaScript. I am currently working on creating two dropdown lists, one for 'Start Time' and another for 'End Time'. These dropdown lists will display hours in a 24-hour format with intervals of 30 minutes. In t ...