Jump to content

Not mixing px with %


stockton

Recommended Posts

I have been given an application to maintain and it includes an external style sheet part of which is shown below:-

#SlotsWindow {
    position:absolute;
    width:47%;
    height:80%;
    top: 125px;
    left: 120px;
    overflow: hidden;
}

I have been given to understand that mixing percentages with px is bad practice but I do not understand how I can easily translate the above px to percentages.

Suggestions please.

Link to comment
Share on other sites

If you have an element that is 200px wide and another element inside it at 80%, it is pretty obvious that with little calculation the 80% wide element will be 160px.

 

Bear this in mind when trying to convert from % to px.

Link to comment
Share on other sites

Depending on what you are using the px for, there is nothing wrong with mixing px and either %s or ems. Percentages are static, and as such will not change when either the browser is resized, or the font size is increased/decreased. This can be a good thing for margins and/or padding sometimes, as they will make your site expand or contract a little more gracefully by remaining static. The example you gave is one such example. The element in question will always remain 125 pix from the top and 120 from the left regardless of how the browser is resized.

 

That being said, those numbers seem a little big, and there is a good chance that its not the best coding for the site. Without seeing the site and the rest of the code, it's hard to say.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.