开发者

Calculate a margin using CSS percentage and unit together

margin-left: 100 + 20%;

I want to do something the same as above. But CSS does not have any format. How can I successfully use these开发者_开发问答 together ?


Without javascript? Only by wrapping that content into another element (usually <div>) and splitting that margin to two elements.

Something like:

<div style="margin-left:20%">
  <div style="margin-left:100px">
  <!-- content -->
  </div>
</div>


Hi there and welcome to StackOverflow. Unfortunately CSS doesn't have this (good) behaviour, but LESS will. For a JavaScript implementation, look here. If you want a PHP implementation, look here. You may be confused as to why I'm talking about JS and PHP, but what LESS will do is take your .less file and turn it into a vanilla CSS file, either on the client (JS), or on your server (PHP).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜