Getting a CSS calc percentage result -


I'm trying to get some responsive CSS, which changes an image element in a spectacular way.

Within a range ( @ media screen and (minimum-width: 600px) and (max-width: 960px) ) Percentage of your image Property is different.

Specifically, at 960, I want to effectively do this width: 50% , but at the bottom 600, I have it effectively width: 38.1966 % For every pixel of width decrease, I need to reduce the width of 0.032787%.

So far, I have not found any way to get the calc () to handle it.

I need to first calculate the original calculation: (960px - 100vw) . Unfortunately, it gives results in pixels, while I have to convert it to some number, so that I can multiply my target percentage by variance.

Is this possible?

If you want to use jQuery:

You calculate the calculated value as you mentioned, you can get it var madwithath = $ ('# id'). Internal (); After this, you can get the width of the page with the var bodyWidth = $ ('body'). InnerWidth ();

So, you can write a script which is used to calculate body volume and itemwidth one cent var percentageVar = ItemWidth / bodyWidth * 100; and use it to set the breadth of an item $ ("#id"). CSS ("width", percentage); .

So, jQuery will look something like these rows:

  var main = function () {var itemWidth = $ ('# id'). InnerWidth (); Var bodywidth = $ ('body'). Intrinsic (); Var Percentage = Itemwuth / Bodywidth * 100; $ ("# Id") CSS ("width", percentage); } $ (Document) .ready (main)  

Or, if you want to reuse it, create a function and keep it in the main function

  Var main = function () {element_sizer ('# id'); Element_sizer ('# id2'); } $ (Document) .ready (main) function element_sizer (id) {var itemWidth = $ (id) .innerWidth (); Var bodywidth = $ ('body'). Intrinsic (); Var Percentage = Itemwuth / Bodywidth * 100; $ (Id). CSS ("width", percentage); }  

Note: You use width , innerWidth , external wide depending on the requirement you need Can P>


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

c# - NewtonSoft JArray - how to select multiple elements with LINQ -

javascript - amcharts makechart not working -