Bootstrap 使用显示属性的示例
在Bootstrap中, 显示属性 用于设置元素的显示属性。Bootstrap提供了诸如” block “, ” inline “等类,用于直接控制元素的显示属性。这些在Bootstrap中的显示属性类允许开发人员轻松应用CSS显示属性值到元素,而无需手动编写相应的CSS样式。
以下是显示属性类:
- .d-block - 该类将元素的显示属性设置为块级元素。
-
.d-inline - 该类将元素的显示属性设置为内联元素。
-
.d-inline-block - 该类将元素的显示属性设置为内联块元素。
语法
以下是Bootstrap中” d-inline “, ” d-block “和” d-inline-block “类的语法:
<div class="d-inline"> Inline </div> // for inline display
<div class="d-block"> Block </div> // for block display
<div class="d-inline-block"> Inline Block </div> // for inline-block display
示例1
在以下示例中,我们演示了”d-block”类的用法。
<!DOCTYPE html>
<html>
<head>
<style>
div {
font-size: 20px;
}
</style>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="d-block bg-success"> Tutorialspoint </div>
<div class="d-block bg-success"> Tutorialspoint </div>
</body>
</html>
示例2
在下面的示例中,我们在HTML的
<
div>元素上使用了bootstrap的”d-inline”类。
<!DOCTYPE html>
<html>
<head>
<style>
div {
font-size: 20px;
}
</style>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</head>
<body>
<div class="d-inline bg-success"> Tutorialspoint </div>
<div class="d-inline bg-success"> Tutorialspoint </div>
</body>
</html>
示例3
在下面的示例中,我们演示了”d-inline-block”类的使用。
<!DOCTYPE html>
<html>
<head>
<style>
div {
font-size: 20px;
}
</style>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</head>
<body>
<div class="d-inline-block bg-success"> Tutorialspoint </div>
<div class="d-inline-block bg-success"> Tutorialspoint </div>
</body>
</html>