How can I fix the alignment issue with my centered div?

My attempt to vertically align a centered inner DIV is not working as expected...

What could be causing this issue?

CSS Code:

#page_bar
{
    width: 100%;
    height: 30px;
    background-color: white
}

.page_bar
{
    width: 800px;
    height: 30px;
    display: table-cell;
    vertical-align: middle
}

HTML Code:

<div id="page_bar">
    <div class="page_bar">
        Mapa Strony
    </div>
</div>

EDIT: I am aiming to center the inner DIV itself, not just the text inside of it...

EDIT: Take a look at: - the silver area should be centered, meaning the inner div needs to be centered, not just the text within it.

Answer №1

If you're looking to center the .page_bar class horizontally with the table-cell display, it seems like wrapping it may be necessary.

#wrap{
    margin: 0px auto;
    display:table;
}

#page_bar
{
    width: 100%;
    height: 30px;
    background-color: white
}

.page_bar
{
    width: 800px;
    height: 30px;
    display: table-cell;
    text-align: left;
    vertical-align: middle;
    margin: 0px auto;
}

<div id="page_bar">
    <div id="wrap">
        <div class="page_bar">
            Mapa Strony
        </div>
    </div>
</div>          

Answer №2

This content will be both horizontally and vertically centered:

#content_container
{
    width: 100%;
    height: 200px;
    background-color: blue;
    text-align: center;
}

.content_item
{
    width: 600px;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}​

jsfiddle: http://jsfiddle.net/AbCdE/4/

Answer №3

What happens when you apply the style text-align:center; to the element with ID #page_bar ?

Answer №4

Set the vertical alignment to middle.

You may have missed adding a semicolon here. Also, please ensure there is a 2-3px space between 30-27 or 33-30.

Answer №5

After spending a considerable amount of time trying different solutions, I was able to identify a straightforward fix for this issue.

Simply adding 'display:table-cell' to an element and applying 'display:table' to the parent will ensure that vertical alignment behaves as intended.

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

Combine the text of the button onto a single line

It seems like my button text appears fine on Safari, but in Google Chrome the issue arises. When you first arrive at the button, everything looks okay. However, after navigating through more posts and encountering the load more button again, the text gets ...

Different ways to rearrange the placement of Export buttons in a personalized div or outside the table using Datatable

I would like to display the export buttons outside of the table. While searching on stackoverflow, I came across an example that uses the Select options method. You can find the example here. If anyone knows how to achieve this, please modify it and shar ...

Steps to make a pop-up window for text copying by users

On my website, I have a link that users need to copy for various purposes. I want to provide an easy way for them to see the link and then manually copy it to their clipboard. Instead of using code to copy to the clipboard, I am looking for a solution whe ...

Reading complex table structures with Selenium

Incorporating Selenium into my Java project, I am on a mission to purchase coupons during a test and subsequently display them in the coupon overview. Multiple coupon packages can appear in this area if the user has previously made purchases. The structur ...

Implementing a Custom CSS Theme in JavaFX

Hey everyone, I stumbled upon this amazing JavaFX theme called Flatter on . I've been attempting to implement it for a couple of hours now, but I'm struggling with the process. Can someone provide me with a detailed guide on how to activate thi ...

Our website features a dynamic functionality where users can select from two dropdown lists with identical values. Upon selecting multiple values from the first dropdown, the corresponding values in

When selecting multiple values from the first dropdown list, the second dropdown list will automatically have the same value selected as the first dropdown. ...

The execution of jQuery was hindered due to the implementation of PHP include

Having an issue with jQuery not working in index.php when including the file header.php. The nav sidebar is included, but clicking the chevron does not trigger anything. It only works when I directly include header_user.php without checking the UserType in ...

Stopping the Game Loop in Windows Phone 8.1 with WinJS

Despite everything working smoothly, I am facing an issue with stopping the game loop when the Start button is pressed and the app is moved to the background. The event handler for suspend, app.oncheckpoint = function(args) {}, does not seem to fire for t ...

Arranging elements in a row and column to ensure proper alignment

https://i.stack.imgur.com/LMsTg.png I'm having trouble aligning the UI elements in my Bootstrap 5 project. I can't seem to pinpoint the issue despite trying various solutions. Here's the code snippet: <div class="container"> ...

Add fresh inline designs to a React high-order component creation

Applying a common HOC pattern like this can be quite effective. However, there are instances where you may not want a component to be wrapped, but rather just extended. This is the challenge I am facing here. Wrapper HOC const flexboxContainerStyles = { ...

Fixed top bar and navigation menu, with a body that can be scrolled

My current goal is to achieve the following layout: <div style="position:absolute; background-color:Transparent; left:0px; right:0px; height:100px; z-index:2;"> <div style="background-color:Silver; width:1000px; height:100px; margin:0 auto;"& ...

When pressed, the button changes color to a vibrant shade of blue, and not just a simple outline

I'm experiencing an issue with a button that turns blue when the user holds onto it for a while on mobile. You can see an example in the image below: https://i.sstatic.net/VmnZ8.png Adding ::selected or outline did not resolve the problem as the ent ...

Hover effects in CSS animations can be hit or miss, with some working smoothly while others may

Below is the HTML content: <div class="wrapper"> <figure align="center"><img src="http://www.felipegrin.com/port/or-site.jpg" alt=""><br><span>RESPONSIVE HTML5 WEBSITE FOR <br> OR LEDS COMPANY</span></fig ...

Combining classes within LessCSS for nested functions

I'm struggling to get LessCSS to process a file with a series of nested rules using the "&" concatenation selectors. For instance, the code below works fine: .grey-table { background: #EDEDED; tr { th { background: #D ...

Validating the similarity of classes with JQuery

Currently, I am working on creating a quiz game using HTML, CSS, JQuery, and potentially JavaScript. I am looking to implement an if statement to check if a dropped element is placed in the correct div (city). My approach involves utilizing classes to comp ...

Switching between various quantities of inputs in each row using Bootstrap V3

My Bootstrap V3 form has a mix of rows with two inputs and rows with one input, as per the designer's request. Check out my fiddle here: https://jsfiddle.net/06qk4wh4/ <div class="form-group col-sm-12"> <label class="control-label col- ...

Automatic switching between Bootstrap 5 tab panes at precise time intervals

Is there a way to have the Bootstrap 5 tab-pane automatically switch between tabs at set intervals, similar to a Carousel? I found a code snippet on this link, but it appears to be outdated and only works for Bootstrap 3. Could someone assist me in updati ...

Issues with SQL query execution in PHP with mySQL causing no results to be returned

$sql="SELECT * FROM Users WHERE '$searchType' = '$search'"; searchType represents the column and search is the specific value I am looking for. After confirming that my form is correctly submitting the values, I encountered an issue w ...

LinkedIn's website consistently displays a "1 min read" indicator when sharing articles or

I am currently attempting to remove the '1 min read' text from the description when sharing content on LinkedIn. Example of '1 min read' Although I have added open graph tags to the page and confirmed that they do not contain '1 ...

The combination of using p:inputText within p:layoutUnit does not function properly when placed inside p

Recently, I encountered a problem with a modal dialog that contains some input components. The issue arose when I implemented a p:layout within the dialog. Initially, the p:inputText component within a p:layoutUnit functioned properly and gained focus. Ho ...