HTML element vertical positioning does not work with jQuery mobile?

Hi Experts:

I wrote this code to try to make a canvas in the middle of web browser:
<!DOCTYPE html>
<html style="height: 99%; width: 99%; padding: 0; margin:0">
<head>
    <title>abc</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="js/jquery.mobile.theme-1.4.5.css">
    <link rel="stylesheet" type="text/css" href="js/jquery.mobile-1.4.5.css">

    <script type="text/javascript" src="js/jquery-1.11.3.js"></script>
    <script type="text/javascript" src="js/jquery.mobile-1.4.5.js"></script>
</head>
<body style="width: 100%; height: 100%; margin: 0; padding: 0; border: 5px blue solid;">
        <canvas style="background-color: red; width: 50%; height: 50%; position: relative; top: 25%; left: 25%"></canvas>
</body>
</html>

Open in new window


The vertical positioning of the canvas does not work, such that it still locates at the top of the web page.
However, if I remove the reference to jQuery mobile:
    <script type="text/javascript" src="js/jquery.mobile-1.4.5.js"></script>

Open in new window

then the canvas will be in the middle of the web page.

Seems jQuery mobile has conflict with the vertical positioning. Is this a bug? or jQuery mobile is designed to do that? How can I do vertical positioning when using jQuery mobile?

Thank you!
huangs3Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

huangs3Author Commented:
I tried to replace the Canvas element with DIV element. But got the same result.

<div style="border: red solid 1px; width: 200px; height: 200px; position: relative; top: 25%; left: 25%"></div>

Open in new window


I am using Chrome browser.
0
Julian HansenCommented:
jQuery Mobile wraps the <canvas> element in a div - which is what is causing your problem. This is by design.

This article describes the issue in more detail

http://www.gajotres.net/how-jquery-mobile-page-handling-affects-javascript-executions/

Looks like either you have to drop jQuery mobile or add specific styling to the div - currently it is defaulting to a min-height of 500px - you might need to add a height style and make it 100%

Something like

body > .ui-page-active {
     height: 100%;
}

Open in new window


Full code
<!DOCTYPE html>
<html style="height: 99%; width: 99%; padding: 0; margin:0">
<head>
    <title>abc</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile.theme-1.4.5.css">
    <link rel="stylesheet" type="text/css" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">

    <script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
	<style type="text/css">
body > .ui-page-active {
     height: 100%;
}
	</style>
</head>
<body style="width: 100%; height: 100%; margin: 0; padding: 0; border: 5px blue solid;">
	<canvas style="background-color: red; width: 50%; height: 50%; position: relative; top: 25%; left: 25%"></canvas>
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
huangs3Author Commented:
Thank you, it works.
0
Julian HansenCommented:
You are welcome.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.