Aligning the tabs on my webpage to the center

I am currently working on a TV show page for my web design class and have incorporated tabs into the top menu of the webpage following a tutorial. However, I am struggling to center the tabs properly even after trying to use the center tag.

    body {
      font: 0.8em arial, helvetica, sans-serif;
    }
    #header ul {
      list-style: none;
      padding: 0;
      margin: 0;
    }
    #header li {
      float: right;
      border: 1px solid #bbb;
      border-bottom-width: 0;
      margin: 0;
      padding: 0;
    }
    #header a {
      text-decoration: none;
      display: block;
      background: #eee;
      padding: 0.24em 1em;
      color: #00c;
      width: 8em;
      text-align: center;
    }
    #header a:hover {
      background: #ddf;
    }
    #header #selected {
      border-color: black;
    }
    #header #selected a {
      position: relative;
      top: 1px;
      background: white;
      color: black;
      font-weight: bold;
    }
    #content {
      border: 1px solid black;
      clear: both;
      padding: 0 1em;
    }
    h1 {
      margin: 0;
      padding: 0 0 1em 0;
    }
<div id="header">
  <center>
    <ul>
      <li style="font-family: DFKai-SB;"><a href="#">Home</a>
      </li>
      <li style="font-family: DFKai-SB;"><a href="#">Shows</a>
      </li>
      <li style="font-family: DFKai-SB;"><a href="#">Classic</a>
      </li>
      <li style="font-family: DFKai-SB;"><a href="#">More</a>
      </li>
    </ul>
  </center>
</div>
<div id="content">
</div>

Answer №1

To improve the alignment of your tabs, insert this div with the class name .centeer instead of using <center>:

.centeer {
    display: table;
    margin: 0px auto 0px auto;
}

See Live Demo

Answer №2

The float property takes precedence, causing your content to float to one side instead of aligning properly. To prevent stacking in your CSS, consider using inline elements for the li elements.

        body {

          font: 0.8em arial, helvetica, sans-serif;

        }

       

        #header ul {

          list-style: none;

          padding: 0;

          margin: 0;

        }

        #header li {
          display: inline-flex;

          border: 1px solid #bbb;

          border-bottom-width: 0;

          margin: 0;

          padding: 0;

        }

        #header a {

          text-decoration: none;
          
          background: #eee;

          padding: 0.24em 1em;

          color: #00c;

          width: 8em;

          text-align: center;

        }

        #header a:hover {

          background: #ddf;

        }

        #header #selected {

          border-color: black;

        }

        #header #selected a {

          position: relative;

          top: 1px;

          background: white;

          color: black;

          font-weight: bold;

        }

        #content {

          border: 1px solid black;

          clear: both;

          padding: 0 1em;

        }

        h1 {

          margin: 0;

          padding: 0 0 1em 0;

        }
<div id="header">
  <center>
  <ul>
    <li style="font-family: DFKai-SB;"><a href="#">Home</a>
    </li>
    <li style="font-family: DFKai-SB;"><a href="#">Shows</a>
    </li>
    <li style="font-family: DFKai-SB;"><a href="#">Classic</a>
    </li>
    <li style="font-family: DFKai-SB;"><a href="#">More</a>
    </li>
  </ul>
    </center>
</div>
<div id="content">
</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

Element's vertical alignment adjustment

Here is the code snippet I am working with: <div style="height:[Variable]px"></div> <!-- or [one or several div and section elements, each with a variable height] --> <div class="Element" style="Position:relative"> <div cl ...

Modify <style> following jQuery scripts

Upon loading a site, I utilized a jQuery script to capture the background color of the header. This action occurs when the page is loaded with the cue $(document).ready(function(global). My goal is to then insert this captured value into the background sty ...

Tips for showcasing the elements depending on the chosen category

Here is a Vue.js code with multiple templates associated with multiple components. The goal is to display each component based on the selected category. For example, if "single family homes" is selected from the dropdown menu, the "step2" component shoul ...

Using CSS to apply a gradient over an img element

Looking to add a gradient overlay to an <img> tag with the src attribute set to angular-item. Here's an example: <img src={{value.angitem.image}}> I attempted to create a CSS class: .pickgradient { background: -webkit-gradient(linear ...

Retrieve the stylesheet based on the presence of a specific class

Is there a way to dynamically add a CSS stylesheet based on the presence of a specific class on a page? For example, instead of checking the time and loading different stylesheets, I want to load different stylesheets depending on the class present in the ...

Utilize CSS to vertically align buttons

One of my current projects involves creating a panel with buttons organized in columns side by side, similar to the layout shown below: https://i.sstatic.net/ObAqw.png However, I am struggling to achieve this desired arrangement. Below is the code I hav ...

Adjust the page height when switching between two divs

Currently, I have two divs that are being displayed one at a time using the toggle method. Please refer to the screenshot below: In the image provided, when the user clicks on "show more", the div will toggle based on the first item in the list. If the u ...

What are some ways to keep text within the boundaries of a div element?

I have tried multiple solutions for this issue, but none seem to be working for me. When I append a paragraph to a div, the text extends beyond the element. Below is the code I am using. Any assistance would be greatly appreciated. CSS: .chat-h { margi ...

What is the best way to showcase the values linked to their corresponding ids in a table?

With the query below, I am joining two tables using the order_id and displaying all the values from the user_orders table. My goal is to only display the order_Id rows that match the order_manager table, as shown in the image below. public functio ...

Deselect a selected radio button by clicking on it

I am trying to create a radio button with an unchecked value, and I thought this code would work: $('form').on('click', 'input[type="radio"]:checked', function (event) { $(this).prop("checked", false); }); It seems simpl ...

Exploring the world of HTML and Javascript to enhance user search functionality

When I type in the search form, JavaScript is returning an error: "Uncaught TypeError: Cannot read property 'innerText' of null". I am working on a page with Bootstrap cards and trying to filter them by name. I attempted to access the "card-titl ...

The issue of the color CSS rule not being applied to the button element when transitioning from disabled to enabled on browsers like Safari 14+ is a common challenge

There seems to be an issue with frontend form validation code affecting the disabled attribute of a submit button within a form. Two different css rules are applied for the enabled and disabled states, including changes in the text color of the button ele ...

What are some ways to maintain the aspect ratio of an image with two dimensions?

Issue: The image is taller than the img-box container https://i.stack.imgur.com/zDBLM.png I have identified two potential solutions, but I am not satisfied with them: Removing the img-box wrapper Applying max-height and max-width properties to the img t ...

Tips for verifying on the click of a button

Having trouble solving my issue as a newbie to HTML and jQuery. The problem at hand is: In my website, I need to implement username validation. This validation involves checking the entered username against a MySQL database. If the database contains the ...

Creating a platform that allows users to build custom themes on a website using ASP.NET/C# programming language

I'm looking for a sophisticated approach to designing an ASP.NET website where users can easily create personalized themes for their sites using a user-friendly interface. Can ASP.NET themes assist with this? Should the interface enable users to gener ...

What is the best method for retrieving the chosen value from a <select> element?

Can you help me figure out why I am receiving an array of empty strings in my JavaScript code even though I have HTML select elements with values selected? <select id="col_1" name="col_1" class="columnMapping"> <opt ...

What is the best way to provide two unique versions of websites using one domain?

I've embarked on a project that requires a complete rewrite. Instead of opting for a big bang release, we've decided to utilize the Strangler Pattern as outlined here. The current application (details below) will continue to run unchanged under ...

Utilize AngularJS to Access Global JavaScript Variables

I recently encountered a situation where I needed to incorporate some dynamic functionality into a website I was building. This led me to AngularJS, which I decided to integrate into certain parts of the site rather than the entire thing. Within my JavaSc ...

Displaying a list of terms and their corresponding definitions side by side

I need to display multiple rows of data, with a title and corresponding data on the same line. While I have found answers on sites like SO (e.g. How to style dt and dd so they are on the same line?), the suggested solutions don't seem to work for my s ...

Identifying Flash content in a unique way

In my dynamic page (let's call it myFlashContainer.jsp), the Flash content changes based on the link that is clicked. The code responsible for rendering the Flash looks like this: <object height="100%" align="l" width="100%" id="player" codebase= ...