How to align several <p> elements in a div container

I'm struggling to center a set of tabs in different sections on my website. I've tried using an unordered list and <p> tags within a <div>, but nothing seems to be working. I've experimented with <position: absolute>, <display: inline>, and other CSS properties, but I can't seem to get it right. Any help would be appreciated!

For now, the tabs aren't functional; I just want them to look like tabs without worrying about jQuery. Here's a snippet of my HTML and CSS:

HTML

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="css/default.css" />
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/script.js"></script>
    <title>STARSHIP CHRONICLES</title>
</head>

<body>
    <div id="container">
        <div id="header">
            <h1>STARSHIP CHRONICLES</h1>
            <p id="topmenu">SEARCH - FAQ - FEEDBACK - ABOUT</p>
        </div>
        <div id="ships">
            <!--ships go here-->
        </div>
        <div id="tabs">
            <ul id="tabs">
                <li id="tabs">OVERVIEW</li>
                <li id="tabs">STATS</li>
                <li id="tabs">IMAGES</li>
                <li id="tabs">CONTEXT</li>
            </ul>
        </div>
        
        <div id="geninfo">
            <table>
                <tr>
                    <td><p class="info">SHIP NAME:</td>
                    <td><span class="text">Recursant-Class Star Destroyer</span></td>
                </tr>
                <tr>
                    <td><p class="info">ALLIANCE:</td>
                    <td><span class="text">Commerce Guild</span></td>
                </tr>
                <tr>
                    <td><p class="info">ORIGIN:</td>
                    <td><span class="text">Star Wars</span></td>
                </tr>
                <tr>
                    <td><p class="info">SIZE:</td>
                    <td><span class="text">1,187 meters</spam></td>
                </tr>
            </table>
        </div>

        <div id="bottommenu">
            <p id="length">0m-479m</p>
            <p id="length">480m-1299m</p>
            <p id="length">1300m-1999m</p>
            <p id="length">2000m-4999m</p>
            <p id="length">5000m+</p>
        </div>
    </div>
</body>
</html>

CSS

body {
background: url(../images/spacebg.jpg) no-repeat fixed ;
}
#container {
width: 100%;
height: 100%;
}

#header {
width: 50%;
height: 100px;
border: solid 1px #0071BC;
background-color: transparent;
margin-left: auto;
margin-right: auto;
text-align: center;
}

#info {
margin-left: auto;
margin-right: auto;
position: relative;
}

#geninfo {
margin-top: 100px;
width: 35%;
height: 200px;
background-color: #000000;
border: solid 1px #0071BC;
margin-left: auto;
margin-right: auto;
padding: 5px;
}

#tabs {
color: #000000;
font-family: DinBlack;
text-align: center;
background-color: #0071BC;
width: 100px;
text-decoration: none;
}
#tabs ul {
list-style-type: none;
padding: 0px;
margin: 0px;
}
#tabs li {
margin: 0 0.5em 0 0;
}

h1 {
color: white;
font-family: OratorSlant;
font-size: 50px;
margin-left: auto;
margin-right: auto;
}

#topmenu {
color: #ffffff;
font-family: DinBlack;
font-size: 15px;
}

table {
padding: 0px;
margin: 0px;
line-height: 1px;
}

.info {
color: #0071BC;
font-size: 25px;
font-family: Captain;
}

.text {
color: #0071Bc;
font-size: 18px;
font-family: DinReg;
}

#bottommenu {
position: absolute;
bottom: 5px;
display: inline-block;
}

#length {
color: #000000;
font-family: DinBlack;
text-align: center;
background-color: #0071BC;
display: inline-block;
margin: 5px;
width: 200px;
height: 20px;
}

Answer №1

If you want to center paragraphs horizontally within a div, you can set the parent div's style to text-align: center;, and give the inner paragraphs display: inline-block;

Instead of using absolute positioning in #bottommenu (there are more effective ways to position a footer), try adding text-align: center

There are numerous potential duplicates, like the one found at this link

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

Show or Hide a Div with Responsive Design

Exploring responsive layouts is a new adventure for me. Most things seem to be falling into place, except for one challenge: I am struggling to show divs with the property 'display: none;' when switching it to 'display: block;' in my me ...

Whenever I try to open my jQuery UI Dialog without first displaying an alert, it does not work

Beginning of my HTML page, initializing a dialog : <script type="text/javascript"> $(function() { $( "#dialog-confirm" ).dialog({ autoOpen: false, resizable: true, height:180, width:300, modal: true, buttons: { "Yes": ...

Setting the CSS property `position: absolute; bottom: 0`, will move the div to the bottom of the screen rather than the bottom of

I'm currently working on a website where I want to attach a menu-bar to the bottom of the header using #menu { position: absolute; bottom: 0; } Unfortunately, instead of sticking to the bottom of the parent div, the menu-bar is stuck to the ...

Tips for aligning a cluster of floating buttons at the center in Vuetify:

This is the code I am currently working with: <v-container height="0"> <v-row align="center" justify="center"> <v-hover v-slot:default="{ hover }" v-for="(option, index) in options" ...

Guide to making a segmented bottom border with html and css

I am working on styling a span for a restaurant name that requires a unique border-bottom design. I want to divide the border into two sections without overlapping the text below, similar to the image shown here: https://i.sstatic.net/bPvwQ.jpg Can anyone ...

Tips for Positioning Sidebar Elements Relative to Content IDs

My goal is to have sidebar elements align with specific id tags in the main content, rather than just stacking up one after another. I want the sidebar elements to align with certain id tags mentioned in the main post content. The image at shows the basic ...

Precise placement of images inside a div container

Could we can tweak the div structure below to center both the image and text horizontally within the container div? Currently, the image is aligned to the left while only the title is centered. Take a look at the code snippet provided: .QHe ...

Removing Shadow, Border, and Outline from Bootstrap v5.0.2 Navbar

I have been struggling to get rid of the shadow/outline/border on my navigation bar. Despite trying various CSS tweaks, I have not been successful. Below is the specific HTML code: <nav class="navbar navbar-expand-sm" id="site-navigation ...

Linked CSS Bullet Points

Typically, I focus on the backend of websites, but I am now attempting to add a new feature to my resume site. I want to connect bullet points with a vertical line that breaks at each point and does not overlap with the bullets themselves. I have created ...

Duplicating information within a row

Why am I seeing the same value in all rows of the table? Each row in the table can be clicked to reveal additional information, but every row displays the data from the last clicked row. This issue may be due to saving data in the same object. Unfortunatel ...

Adjusting an HTML table to fit within a designated space

I am currently in the process of constructing an HTML table that will showcase data retrieved from a MySQL database. This table will include functionalities to update or delete rows within the database. Here is a glimpse of my code: <table> <tr& ...

Execute Javascript after modification of the DOM

I have developed two custom directives known as app-content and app-content-item. These directives are intended to be utilized in upcoming projects to provide a basic structure with simple styling. They will be incorporated into a module and should be nest ...

The video.play() function encountered an unhandled rejection with a (notallowederror) on IOS

Using peer.js to stream video on a React app addVideoStream(videoElement: HTMLVideoElement, stream: MediaStream) { videoElement.srcObject = stream videoElement?.addEventListener('loadedmetadata', () => { videoElement.play() ...

After submitting the comment, you will be redirected to a different page

I am currently working on implementing a comment section for my website. I have created the comment box and successfully set up posting comments and updating them in the database. However, I am facing an issue where upon submitting a comment, the page auto ...

How can I ensure that Div and its contents are only responsive to changes in width?

Initially, I'm feeling a bit confused but I'll try my best to articulate my issue and what I need. Within a div element, there's another div that I want to move left and right only, following the same path as an image when resizing (refer t ...

Is it possible to send information via the URL while using jQuery Mobile?

My mobile application utilizes an in-app browser to send information, such as deviceID, to my server via a URL. For instance, the browser opens a web-page (jquery Mobile): www.myserver.com/doWork.html#deviceID Within the doWork.html file on the server si ...

Web font display problem: browsers appear to be experiencing difficulty with determining the correct size and placement

I recently encountered a unique issue while using two different webfonts in one of my projects. One font seems to be causing a rendering problem that I have never experienced before, while the other font displays correctly. It appears that the browser is ...

Directive containing tracking code script

I'm working on creating a directive to dynamically include tracking code scripts in my main page: <trackingcode trackingcodevalue="{{padCtrl.trackingnumber}}"></trackingcode> This is the directive I have set up: (function () { 'use ...

Preventing flickering when refreshing an AJAX HTML JavaScript page

I am working on a project where I need to constantly refresh a table on my HTML page without any flickering. To achieve this, I am utilizing javascript and ajax. Below is the script I am using: var table = $('#dt').DataTable( { ...

The Firefox browser is not fully displaying the button background

Having an issue with a button that doesn't completely fill up on Firefox only. Here's the problem in action: This is how it should actually look: Not quite sure what to do. Here's the CSS styling being used: .button-panel .button { -web ...