What's the best way to align text at the center of this DIV?

I recently created a small offline website with a header that includes a logo, navigation bar, and notification bar. While I managed to align everything as intended, I encountered an issue with the text alignment within the notification bar (header-alert).

HTML:

<header class="header">
            <img style="float: left; padding-left: 20px" src="images/versace-logo.bmp" width="230" height="120" />
            <div class="bottom-header">
                <div class="navigation-bar" style="margin-top: 90px">
                    <ul>
                        <li>
                            <a href="#">Home</a>
                            <div class="dropdown-container dropdown-shadow">
                                <ul class="dropdown-column">
                                    <li><a href="#">First</a></li>
                                    <li><a href="#">Second</a></li>
                                </ul>
                            </div>
                        </li>
                    </ul>
                    <ul>
                        <li>
                            <a href="#">Video</a>
                        </li>
                    </ul>
                </div>
            </div>
            <div style="clear:left"></div>
            <div class="header-alert">
                This website is still under development!
            </div>
        </header>

CSS:

.header
{
    background-color: black;
    color: white;
    display: block;
    font-family: "GillSansStdRegular";
    margin-bottom: 20px;
    padding-top: 10px;
    position: relative;
}

.bottom-header
{
    display: block;
    position: relative;
    padding: 0 20px;
}

.navigation-bar
{
    clear: right;
    color: white;
    display: inline-block;
    font-size: 12px;
    float: right;
    text-transform: uppercase;
    margin-bottom: 0px;
}

.header-alert
{
    background-color: white;
    border-bottom: 2px solid black;
    color: black;
    font-family: "GillSansStdLightRegular";
    font-size: 110%;
    margin-top: 15px;
    text-align: center;
    text-transform: uppercase;
    width: 100%;
}

Despite attempting various fixes involving the display and margin attributes, I have been unable to find a solution without altering the current layout significantly. Perhaps the solution is simpler than I realize, but for now, I am refraining from making adjustments like adding spaces for even alignment.

Answer №1

Make a modification in the line right before your header-alert by changing "clear:left" to "clear:both"

<div style="clear:left"></div>
            <div class="header-alert">

so it becomes

<div style="clear:both"></div>
            <div class="header-alert">

Furthermore, eliminate margin-top: 15px; for .header-alert

Answer №2

Include height: 40px; within the .navigation-bar section

Answer №3

To prevent the .header-alert from being pushed away by the .navigation-bar, simply include position: absolute; in the .navigation-bar and adjust the spacing from the right side using right: 10px; (as an example).

Additionally, you may want to consider removing the float:right; from the .navigation-bar

Answer №4

The issue stems from the navigation bar extending too far downwards, causing interference with the header alert. Additionally, margins were used in combination with a float for positioning. My suggested corrections are influenced by the navigation menu on a recent website I developed for a client located at .

To address this problem:

.bottom-header {
    /*display: block;
    padding: 0 20px;
    position: relative;*/
}

Instead, use or modify the following code (adjusting bottom and right properties as needed to closely match the original position):

.navigation-bar {
    bottom: 0.75em;
    position: absolute;
    right: 1.65em;
}

You may also consider removing or commenting out the unnecessary code below to streamline the layout:

.navigation-bar {
    /*clear: right;
    color: white;
    display: inline-block;
    float: right;*/
}

Answer №5

Hopefully, this information proves helpful to you,

Here is the HTML code snippet:

<header class="header">
        <div class="img">
        <img src="images/versace-logo.bmp" width="230" height="120" />
</div>
        <div class="bottom-header">
            <div class="navigation-bar">
                <ul>
                    <li>
                        <a href="#">Home</a>
                        <div class="dropdown-container dropdown-shadow">
                            <ul class="dropdown-column">
                                <li><a href="#">First</a></li>
                                <li><a href="#">Second</a></li>
                            </ul>
                        </div>
                    </li>
                </ul>
                <ul>
                    <li>
                        <a href="#">Video</a>
                    </li>
                </ul>
            </div>
        </div>

        <div class="header-alert">
            This website is still under development!
        </div>
    </header>

This is the CSS styling applied:

.header
{
    background-color: black;
    display: block;
    font-family: "GillSansStdRegular";
    margin-bottom: 20px;
    padding-top: 10px;
    position: absolute;
    width: 100%;
}
.img {
    float: left; padding-left: 20px; position: relative;

}

.bottom-header
{
    position: relative;
    float: left;
    width: 100%;

}

.navigation-bar
{
    font-size: 12px;
    text-transform: uppercase;
    float: left;
    color: white;
}

.header-alert
{
    background-color: white;
    border-bottom: 2px solid black;
    color: black;
    font-family: "GillSansStdLightRegular";
    font-size: 110%;
    margin-top: 15px;
    text-align: center;
    text-transform: uppercase;
    width: 100%;
    position: relative;
    float: left;
}

To see a working demo, click here:
working demo

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

Set the DIV element to match the height of its container

I'm currently using this HTML code, and it's functioning correctly. However, I would like the height of the div to adjust dynamically based on the tab's content, rather than specifying a fixed height of 200px. Using a percentage value for th ...

"Enhancing user interaction with Vue.js through the stunning ripple effect on

Is there a way to customize the ripple effect from this source so that it doesn't always have to be a DIV? Here's an example: Currently, when I implement it like this: <ripple class="btn">send</ripple> It works as expected, but as ...

Should I create CSS rules for different screen sizes or should I dynamically render components based on the screen size?

As I delve into learning React, I find myself unsure about the most effective approach to make websites responsive. Currently, I am utilizing Semantic UI React as my CSS Library. While everything displays perfectly on desktop, I encounter some issues when ...

Make the div disappear after a specified time

Does anyone know of a code snippet that can make a couple of div elements fade out after a specific time period? Currently, I have the following example: <div id="CoverPop-cover" class="splash"> <div id="CoverPop-content" class="splash-center"> ...

What are the steps to sending HTML emails from the default mail client on Mac and PC operating systems?

Currently, I am in the process of creating a website that allows clients to easily send an email with the content they are viewing. I want users to click on a button which will open their default mail client (compatible with both Mac and PC) and automatica ...

Ensure HTML5 video fills window completely without any overflow

I'm currently developing a new open-source alternative to Plex and I am facing some challenges with the in-browser video player. My goal is to have the video player maximize its size within the window during playback, similar to what Chrome and Netfli ...

Tips for adjusting the position of the second child in my navigation menu using CSS

Struggling with customizing my navigation menu in CSS, I'm seeking assistance. My goal is to have the second child element of the navigation menu on a new line instead of below the first child (refer to the image for clarification). An example of the ...

Building Dynamic Forms with React.js and Bootstrap for Easy Input Field Management

In the process of developing a web application using React.js and react-bootstrap, I encountered an interesting challenge. On one of the form pages, users should be able to input symptoms of an illness they are dealing with. The key functionality required ...

Is it possible to use jquery to specifically target classes?

I am trying to achieve the following: $('.class.img').css('cellpadding', variable); However, this code does not seem to be working as expected. Despite searching online, I have not been able to find a solution. Any assistance on how to ...

Utilizing Dojo widgets in Xpages

I'm having trouble applying CSS to certain dojo elements within my Xpage. Here is the CSS style sheet I am using: .formFields { color: rgb(5, 56, 107); font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-style: normal; font-variant: nor ...

Div blur event for editing content

Utilizing a content editable div as an input control has presented some challenges for me. Unlike a textarea or input element, the div does not send information to the server automatically. To work around this issue, I have implemented a solution where I u ...

Rendering HTML5 and CSS3 on Internet Explorer 8

My coding knowledge is limited, but I am conducting research for our front-end developers. Our goal is to revamp our portal application using CSS 3 and HTML 5 in order to achieve an adaptive layout that can accommodate different browser widths. The curre ...

Tips for creating a form with recurring elements efficiently

Currently struggling to summarize the issue at hand with a simple title, so here's the detailed explanation: Imagine I'm inputting information for multiple contacts, and there are various fields involved: Name of the contact Method of Contact ...

Tips for creating several radio buttons with separate functionality using Bootstrap 5

Is there a way to create separation between these two groups of radio buttons? Whenever I select an option in one group, it automatically deselects the option in the other group. <!DOCTYPE html> <html lang="en"> <head> ...

Having trouble with displaying the CSS background image?

I've been attempting to configure background images using CSS, but for some reason, I'm not able to get the images to show up correctly. Below is the CSS code that I'm working with: a.fb { background-image: url('img/Facebook.png&a ...

Having trouble retrieving JSON data from the open weather API

I'm working on a small website to display the weather of a specific city using an API. However, I am facing an issue where I can't seem to display the temperature from the response. Below are snippets of my JavaScript and HTML files: var ap ...

Display exclusively the chosen option from the dropdown menu

I am facing an issue with the select input on my webpage. Whenever I try to print the page, it prints all the options of the select instead of just the one that is selected. Can someone please guide me on how to modify it so that only the selected option ...

What could be causing my external JavaScript file to not function properly upon loading my HTML file?

I have organized my code by separating the HTML and JavaScript portions. The JavaScript code is now in its own separate file and I use 'script' tags to reference it in the HTML file. Within the JavaScript code, I have two functions - one creates ...

A guide on restricting overflow in React Spring Parallax 'pages'

Currently, I have integrated React Spring Parallax () into my project found at this link: https://codesandbox.io/s/parallax-sticky-scroll-2zd58?file=/src/App.js Upon clicking the button to navigate to the next section, it is noticeable that the image over ...

Background image in Bootstrap not covering entire web page

I am facing an issue where the background image is confined within the constraints of the login panel, and I'm unsure why. My goal is for the image to span the full width and height of the browser window. Any assistance on this matter would be greatly ...