开发者

Calculate a margin using CSS percentage and unit together

开发者 https://www.devze.com 2023-02-23 01:09 出处:网络
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 th
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

精彩评论

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