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

Gain command over the underline style of text without relying on the border property

Ingredients: just a simple text input field. Question: Is there a way to customize the size, color, and position of the underline styling on an input tag? I noticed that the property text-decoration-color is supported in the moz browser engine, but I&apos ...

Tips for aligning two divs of varying sizes side by side

Imagine having two div elements: <div id="container"> <div id="left">line one</div> <div id="right">line one<br/>line two</div> </div> Is there a way to have the left and right divs align at the bottom li ...

What is the best way to implement CSS Float in typescript programming?

For a specific purpose, I am passing CSS Float as props. To achieve this, I have to define it in the following way: type Props = { float: ???? } const Component = ({ float }: Props) => {......} What is the most effective approach to accomplish this? ...

What precautions should I take to safeguard my HTML/CSS/JS projects when sharing a link with my employer?

Picture this scenario: you need to share a link for your work, but you want to protect it from being easily copied or developed further by someone else. However, since it's a document, any browser can still view it. Can anyone recommend a tool that wi ...

What are the steps to create two adaptable blocks and one immovable block?

Check out this HTML code snippet: <div style="border: 1px solid #000; width: 700px; line-height: 38px; display: block"> <div style="margin-left:10px;width: 222px; float: left; margin-right: 10px;"> Enter your question </div& ...

Is it possible to place Angular Material components using code?

Currently, I'm in the process of creating a responsive Angular application. Is there any way to adjust the height and position of the <mat-sidenav-content></mat-sidenav-content> component in Angular Material programmatically without relyi ...

Is it possible to manipulate CSS on a webpage using javascript?

I have incorporated this piece of JavaScript to integrate a chat box onto my website: window.HFCHAT_CONFIG = { EMBED_TOKEN: "XXXXX", ACCESS_TOKEN: "XXXXX", HOST_URL: "https://happyfoxchat.com", ASSETS_URL: "https://XXXXX.cloudfront.ne ...

Guide on creating uniform heights and widths for images with varying dimensions utilizing CSS (and percentage values)

Is there a way to ensure that all images maintain the same height and width using CSS percentages, rather than set pixel values? I'm working on displaying images in circles, where most are uniform in size but a few outliers distort the shape. The wide ...

endless cycle of scrolling for div tags

My goal is to incorporate a tweet scroller on I believe it uses the tweet-scroller from Unfortunately, this link seems broken as the demo is not functioning. I searched for an alternative solution and came across http://jsfiddle.net/doktormolle/4c5tt/ ...

Steps to turn off Bootstrap's fixed navigation on mobile devices

When a user visits the mobile version of the website or scales the webpage, the Bootstrap navbar will no longer remain fixed at the top. I am looking to set it as a normally scrolling view in the navbar. The Bootstrap class is "navbar-fixed-top" Click he ...

How to centrally align tabs in Material-UI AppBar using ReactJS

I'm developing a React Application using Material-UI and facing difficulty in centering the 3 tabs within the blue AppBar. Currently, they are aligned to the left like this: (unable to embed images at the moment, apologies) This is the code snippet ...

Navigating pages in tinymce editor

Currently, I have implemented TinyMCE as the editor for my PHP-based website. However, I am facing a challenge in integrating pagination within the editor. My goal is to allow users to input long content that will be displayed across multiple pages inste ...

implementing dynamic navigation bar, when transforming into a dropdown menu using ReactJS

I am currently utilizing a navigation bar from a Bootstrap theme within my React project. The navigation bar includes an in-built media query that determines whether it should display as a dropdown menu or not, with a toggler to handle the dropdown functi ...

Adding hyperlinks that do not redirect

I have 2 separate divs displayed on a website: <button class="form-control margin btn btn-warning hide_all" id="addLinks">Link Pages</button> <button style="display: none" class="form-control margin btn btn-primary hide_all" id="hideLinks"& ...

By increasing the background-color to 100%, the list item obstructs the background image of its parent div

In cases where an element is set to display:block, the background-color of that element typically extends to 100% of the width of its parent element. However, I am seeking a solution where the background-color only reaches the edge of the text, allowing th ...

Issue with converting form data to JSON format

Having an issue converting a filled form in HTML to a JSON request for sending to the server via HTTP POST. Despite having a filled form, the JSON request only shows an empty array. Here is the JavaScript snippet: $("#submitSurveyBtn").on("click", functi ...

Troubleshooting the Full Height Feature for Sidebar (Panel) in Twitter Bootstrap

I'm having issues with the Sidebar (Panel) in Twitter Bootstrap. I'm encountering some trouble with how it is displayed. Below is the CSS code I am using for the sidebar: .sharecartside .content { height: 100% !important; min-height: 10 ...

When adjusting the window size with the <ion-split-pane>, both the menu and router outlet disappear

When I have two ion menus and one main content (router outlet) and resize the page or switch to mobile view, the page appears blank as if the content is missing. Here is the code: <ion-app> <ion-split-pane> <ion-menu side="start" me ...

Using HTML and C# to Deliver Emails

I've encountered a challenge with my HTML page that includes a textbox for users to input their email. When the submit button is clicked, an email should be sent to a specific email address defined in the code, and a pop-up box indicating "Email Sent" ...

Tables that are not only responsive but also friendly to mobile

For the past week or so, I've been working on finishing up the layout for a single page. While I have managed to get the page somewhat functional, I am in need of assistance with both the original layout and ensuring it is mobile-friendly. The issue w ...