css3 calc():css簡單的數學運算–加減乘除
多好的東西啊,不用js,一個css就解決了。
- .box{
- border:1px solid #ddd;
- width:calc(100% - 100px);
- background:#9AC8EB;
- }
3欄等寬佈局。
- .box{
- margin-left:20px;
- width:calc(100%/3 - 20px);
- }
- .box:nth-child(3n){
- margin-left:0;
- }
實例:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>css3 calc():css簡單的數學運算-加減乘除--劉和虎的博客</title>
<script type="text/javascript" src="http://www.liuhehu.com/wp-content/themes/sohodesign/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/iehtml5.js"></script>
<style>
.box{
border:1px solid #ddd;
margin:0 auto;
width:calc(100% - 100px);
width:-moz-calc(100% - 100px);
width:-webkit-calc(100% - 100px);
background:#9AC8EB;
}
</style>
</head>
<body>
<div class="box">width:calc(100% - 100px)</div>
<script>
/*
作者:劉和虎
*/
$(function(){
});
</script>
</body>
</html>