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 7974833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:29:36+00:00 2026-06-04T08:29:36+00:00

Iam trying to position a control at the centre of a web page depending

  • 0

Iam trying to position a control at the centre of a web page depending on the resolution of the page.

The left property I am assigning it in a css class and adding it as follows-
Style class-

.PanelStyle
{
   left:100px;
   top:120px;
   border:2px solid #CCC;
   border-radius: 4px 4px 0 0;
}

oPanel.addStyleClass("PanelStyle");//oPanel is my control.

This is working perfectly fine.But Instead of hard coding the pixel value for left property I want to assign it dynamically depending on the resolution .For which I am doing something like below

var leftoffset = Math.floor($(window).width()-400)/2+ "px";//400 is my control width
leftoffset = leftoffset.toString(); 
oPanel.style.left=leftoffset ;  

But this is not reflected in the web page.

I also tried simply adding the left property value without calculation like

oPanel.style.cssText="left : 100px";        

but no use.
Kindly tell me why inline object.style.left/object.style.cssText=cssString is not working here?

  • 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-04T08:29:37+00:00Added an answer on June 4, 2026 at 8:29 am

    Try like this:

    $(oPanel).css("left",Math.floor($(window).width()-400)/2+"px");
    

    or if '400' is your control’s width, then:

    $(oPanel).css("left",Math.floor($(window).width()-$(oPanel).width())/2+"px");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get the position of user control via TransformToVisual method using
I am trying to position the footer at the bottom of the browser window.
I am trying to position a dialog box right under a + (plus) sign.
I am trying to position a gradient over an inline / inline-block anchor link,
I am trying to position an overlay over a div. I had the code
I am trying to position this sale banner over the image. The red border
I am trying to position a <span> relative to a particular image. I must
I am trying to absolutely position a TinyMCE editor at a set position using
I am trying to implement position-sensitive zooming inside a JScrollPane . The JScrollPane contains
I am trying to get position inside a fling for a listview. No matter

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.