Boostrap5-3列布局和文本右对齐
我正在创建一个个人资料页面。
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
<meta name="generator" content="Hugo 0.80.0">
<title>Detailed View</title>
<link rel="canonical" href="">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.4.0/font/bootstrap-icons.css">
<!-- Favicons -->
<link rel="apple-touch-icon" href="https://getbootstrap.com/docs/5.0/assets/img/favicons/apple-touch-icon.png" sizes="180x180">
<link rel="icon" href="https://getbootstrap.com/docs/5.0/assets/img/favicons/favicon-32x32.png" sizes="32x32" type="image/png">
<link rel="icon" href="https://getbootstrap.com/docs/5.0/assets/img/favicons/favicon-16x16.png" sizes="16x16" type="image/png">
<link rel="manifest" href="https://getbootstrap.com/docs/5.0/assets/img/favicons/manifest.json">
<link rel="mask-icon" href="https://getbootstrap.com/docs/5.0/assets/img/favicons/safari-pinned-tab.svg" color="#7952b3">
<link rel="icon" href="https://getbootstrap.com/docs/5.0/assets/img/favicons/favicon.ico">
<meta name="theme-color" content="#7952b3">
<!-- Custom styles for this template -->
<link href="../css/t02-stockDetailView_style.css" rel="stylesheet">
</head>
<body>
<main>
<nav aria-label="breadcrumb">
<ol>
<li><a href="#">Home</a></li>
<li aria-current="page">Library</li>
</ol>
</nav>
<div>
<div>
<div>
<div>
<div>
<div>
<img src="http://placehold.it/380x500" alt="" />
</div>
<div>
<h4>
Bhaumik Patel</h4>
<p>CEO of Apple Inc.</p>
<small><cite title="San Francisco, USA">San Francisco, USA <i
>
</i></cite></small>
<p>
<i></i> email@example.com
<br/>
<i></i><a href="http://www.jquery2dotnet.com"> www.jquery2dotnet.com</a>
<br/>
<i></i> June 02, 1988</p>
</div>
<div>
<br>Last Trade: 12.March 2021
<br>#Shares: 123.432
<br>Type of Transaction: <span>Buy</span>
</div>
</div>
</div>
</div>
</div>
<div>
<ul role="tablist">
<li>
<a href="#pills-home" role="tab" aria-controls="pills-home" aria-selected="true">Home</a>
</li>
<li>
<a href="#pills-profile" role="tab" aria-controls="pills-profile" aria-selected="false">Profile</a>
</li>
<li>
<a href="#pills-contact" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</a>
</li>
</ul>
<div>
<div role="tabpanel" aria-labelledby="pills-home-tab">test</div>
<div role="tabpanel" aria-labelledby="pills-profile-tab">...</div>
<div role="tabpanel" aria-labelledby="pills-contact-tab">test2</div>
</div>
</div>
</div>
</main>
<!-- /.container -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/js/bootstrap.bundle.min.js" integrity="sha384-b5kHyXgcpbZJO/tY9Ul7kGkf1S0CWuKcCD38l8YkeH8z8QjE0GmW1gYU5S9FOnJ0" crossorigin="anonymous"></script>
</body>
</html>
回答
我已经修改了您的示例以匹配您想要的屏幕截图(右对齐的交易文本除外):
这是更改的摘要:
- 将周围的容器更改为始终
col-12:<div> - 将内部左 div 设置为
<div> - 将内部中间div设置为
<div>- 移动文本将居中对齐;
sm和上面将左对齐
- 移动文本将居中对齐;
- 将内部右侧 div 设置为
<div>- 移动文本将居中对齐;
sm及以上将右对齐(text-sm-start如果您希望左对齐,请更改为)
- 移动文本将居中对齐;
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
<meta name="generator" content="Hugo 0.80.0">
<title>Detailed View</title>
<link rel="canonical" href="">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.4.0/font/bootstrap-icons.css">
<!-- Favicons -->
<link rel="apple-touch-icon" href="https://getbootstrap.com/docs/5.0/assets/img/favicons/apple-touch-icon.png" sizes="180x180">
<link rel="icon" href="https://getbootstrap.com/docs/5.0/assets/img/favicons/favicon-32x32.png" sizes="32x32" type="image/png">
<link rel="icon" href="https://getbootstrap.com/docs/5.0/assets/img/favicons/favicon-16x16.png" sizes="16x16" type="image/png">
<link rel="manifest" href="https://getbootstrap.com/docs/5.0/assets/img/favicons/manifest.json">
<link rel="mask-icon" href="https://getbootstrap.com/docs/5.0/assets/img/favicons/safari-pinned-tab.svg" color="#7952b3">
<link rel="icon" href="https://getbootstrap.com/docs/5.0/assets/img/favicons/favicon.ico">
<meta name="theme-color" content="#7952b3">
<!-- Custom styles for this template -->
<link href="../css/t02-stockDetailView_style.css" rel="stylesheet">
</head>
<body>
<main>
<nav aria-label="breadcrumb">
<ol>
<li><a href="#">Home</a></li>
<li aria-current="page">Library</li>
</ol>
</nav>
<div>
<div>
<div>
<div>
<div>
<div>
<img src="http://placehold.it/380x500" alt="" />
</div>
<div>
<h4>Bhaumik Patel</h4>
<p>CEO of Apple Inc.</p>
<small>
<cite title="San Francisco, USA">San Francisco, USA <i></i></cite>
</small>
<p>
<span><i></i> email@example.com</span>
<span><i></i> <a href="http://www.jquery2dotnet.com">www.jquery2dotnet.com</a></span>
<span><i></i> June 02, 1988</span>
</p>
</div>
<div>
<span>Last Trade: 12.March 2021</span>
<span>#Shares: 123.432</span>
<span>Type of Transaction: <span>Buy</span></span>
</div>
</div>
</div>
</div>
</div>
<div>
<ul role="tablist">
<li>
<a href="#pills-home" role="tab" aria-controls="pills-home" aria-selected="true">Home</a>
</li>
<li>
<a href="#pills-profile" role="tab" aria-controls="pills-profile" aria-selected="false">Profile</a>
</li>
<li>
<a href="#pills-contact" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</a>
</li>
</ul>
<div>
<div role="tabpanel" aria-labelledby="pills-home-tab">test</div>
<div role="tabpanel" aria-labelledby="pills-profile-tab">...</div>
<div role="tabpanel" aria-labelledby="pills-contact-tab">test2</div>
</div>
</div>
</div>
</main>
<!-- /.container -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/js/bootstrap.bundle.min.js" integrity="sha384-b5kHyXgcpbZJO/tY9Ul7kGkf1S0CWuKcCD38l8YkeH8z8QjE0GmW1gYU5S9FOnJ0" crossorigin="anonymous"></script>
</body>
</html>