我有一个在我的项目中动态扩展的div。但我需要应用bootstrap列样式来扩展div。我根据窗口调整大小而不是div大小更改应用。
我的代码是:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script>
$(document).ready(function(){
$("button").click(function(){
$("div").width($("div").width()+20);
});
});
</script>
</head>
</head>
<body>
</br>
<div class="container-fluid" style="background-color:orange;width:200px;height:200px;">
<div class="col-sm-6" style="background-color:lavender;">
<p>Lorem ipsum dolor sit amet</p>
</div>
<div class="col-sm-6" style="background-color:lavenderblush;">
<p>Sed ut perspiciatis unde omnis </p>
</div>
</div>
<button>expand</button>
</body>
</html>
按钮会在每次点击时继续展开div。
请帮助我们将bootstrap样式应用于动态扩展的div。
答案 0 :(得分:0)
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script>
$(document).ready(function(){
console.log($("div").width());
$("button").click(function(){
$("div.col-sm-6").width($("div.col-sm-6").width()+20);
});
});
</script>
<div class="container-fluid" style="background-color:orange;height:200px;overflow:auto;">
<div class="col-sm-6 " style="background-color:lavender;">
<p>Lorem ipsum dolor sit amet </p>
</div>
<div class="col-sm-6 " style="background-color:lavenderblush;">
<p>Sed ut perspiciatis unde omnis</p>
</div>
</div>
<button>expand</button>
&#13;