Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9074191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:34:48+00:00 2026-06-16T18:34:48+00:00

I wrote the below program to get notifications from the database and display it.

  • 0

I wrote the below program to get notifications from the database and display it. The situation was to display the div inside div.note vertically centered.

I tried vertical-align: middle and vertical-align: center and both failed. I found that they are for table cell. So I opted this.

<?php
include("../common/config.php");
$query = "SELECT content FROM st_notifications";
$result = mysqli_query($dbc, $query) or die(mysqli_error($dbc));
while($row = mysqli_fetch_row($result))
{
    echo "<div class='note'><div style='word-wrap: break-word;'>".$row[0]."</div></div>";
}
?>
<script>
    $(function () {
        $(".note").each(function () {
            var note = $(this);
            var diff = 100 - ($("div", note).outerHeight() / 2);
            $("div", note).css({ 'margin-top': diff >= 0 ? diff : 0 });
        });
    });
</script>

the output was something like this.

enter image description here

The css of .note is:

.note {
    height: 200px;
    width: 500px;
    margin: 25px auto 0px auto;
    background-color: #fff;
    padding: 10px;
    vertical-align: baseline;
    background-image: url(../images/notebg.png);
    background-size: 100% 100%;
}

The output on Chrome debugger was:

enter image description here

You can see that both the margins are 100px instead of being assigned relatively.

I read this. But don’t know how to relate it to my problem

And the solution here seems to be incredibly long.

Can somebody tell where I am wrong? Thanks in advance.

PS:
I tried jQuery by directly calling the element and using each() function both give the same. And there is no debugging error in Chrome regarding JavaScripts or PHP.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T18:34:49+00:00Added an answer on June 16, 2026 at 6:34 pm

    Use display: table-cell; to align the nested div vertically centered

    Demo

    HTML

    <div class="wrapper"><div class="inner">This is vertically centered</div></div>
    

    CSS

    div.wrapper {
        display: table-cell;
        vertical-align: middle;
        height: 200px;
        width: 300px;
        background-color: #ff0000;
        text-align: center;
    }
    
    div.inner {
        display: inline-block; /* This is optional */
    }
    

    If the div is fixed

    Way 2 Demo

    HTML

    <div class="container"><div class="float">This will work with fixed dimensions</div></div>
    

    CSS

    .container {
        width: 500px;
        height: 300px;
        background: #eee;
        position: relative;
    }
    
    .float {
        position: absolute;
        height: 50px;
        width: 150px;
        left: 50%;
        top: 50%;
        margin-left: -75px; /* Half Of Width */
        margin-top: -25px; /* Half Of Height */
        border: 1px solid #aaa;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is the program that I wrote. /******************************************************************************* * This program reads EOF from
I have wrote the code below which was taken from Java How to program
Below is the program I wrote to find sum of a subarray from given
I wrote many Async Future Task Calls one below another in my java program.
I wrote the program below in order to read every line of the file
Whenever I type in a phone number, this program below that I wrote to
I wrote a small email sending program in java, it has from , to
(In short: main()'s WaitForSingleObject hangs in the program below). I'm trying to write a
Every time I write a program of the form below using LINQ to SQL,
I have a C program like the one below. I am trying to write

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.