嗨,我正在尝试在Bootstrap 4中实现以下目标。我有一个细长的横幅图像,需要在上面垂直对齐三个按钮。他们也应该有所反应。请参见下图。此图片中的徽标是细长横幅本身的一部分。两端的填充为106像素。我很困惑,如何实现呢?它在移动设备上的显示方式不同,按钮将堆叠在另一个按钮的上方。
我已经从主文件中删除了代码
<!doctype html>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>Hello, world!</title>
.btn-midweek-必须{
width: 184px;
height: 48px;
color: #41173F;
font-family: "Proxima Nova";
font-size: 14px;
font-weight: 600;
line-height: 20px;
text-align: center;
text-decoration: none !important;
background-color: #FFFFFF;
margin: 0 15px;
}
.buttonList { 位置:绝对; 顶部:0px; 右:0px; 填充:51px 30px; }
/* Media Query for 768px */
@media(最大宽度:768像素){ .buttonList { 位置:绝对; 顶部:0px; 右:0px; 填充:24px 30px; } .btn-midweek-Must { 宽度:120像素; 高度:40px; 颜色:#41173F; 字体家族:“ Proxima Nova”; font-size:14px; 字体粗细:600; 行高:20px; 文本对齐:居中; 文字修饰:无!重要; 背景颜色:#FFFFFF; 边距:0 10px; }
}
</style>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<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>
<div class="container">
<div class="row mt-5">
<div class="col col-12">
<picture>
<source media="(max-width:767px)" srcset="/Users/bzest/Beenish 2020/Web Development Bootstrap/midweek musts/slim-midweek-m@2x.png"/>
<img src="/Users/bzest/Beenish 2020/Web Development Bootstrap/midweek musts/slim-midweek.png" srcset="/Users/bzest/Beenish 2020/Web Development Bootstrap/midweek musts/slim-midweek@2x 2x" />
</picture>
<div class="buttonList ">
<button class="btn-primary btn-midweek-Must cta body-font">
<a href="$url('Search-Show','cgid','mid-week-250')$" >
Under $250 › </a></button>
<button class="btn-primary btn-midweek-Must cta body-font">
<a href="$url('Search-Show','cgid','mid-week-500')$" >Under $500 ›</a></button>
<button class="btn-primary btn-midweek-Must cta body-font">
<a href="$url('Search-Show','cgid','mid-week-1000')$" >Under $1000 ›</a></button>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
Flex
使用全套响应式flexbox实用工具快速管理网格列,导航,组件等的布局,对齐和大小调整: Bootstrap Flex
如果内容的高度固定,则用户flex
可以显示并按以下方式进行操作:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="d-flex align-items-center justify-content-around p-2 bg-light" style="height: 100px">
<div>
<span class="border p-2">
logo
</span>
</div>
<div>
<button class="btn btn-success">btn 1</button>
<button class="btn btn-success">btn 2</button>
<button class="btn btn-success">btn 3</button>
</div>
</div>
</body>
</html>
方法:
d-flex
会将弹性显示添加到您的父div。
通过添加align-items-center
,您的孩子div
将在第二条轴(此处为垂直轴)上居中。仅当您的父div的高度很明显时,它才起作用。
答案 1 :(得分:0)
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<div class="form-inline my-2 my-lg-0 mx-auto">
<button class="btn btn-outline-success my-2 my-sm-0 ml-3" type="submit">Button 1 </button>
<button class="btn btn-outline-success my-2 my-sm-0 ml-3" type="submit">Button 2</button>
<button class="btn btn-outline-success my-2 my-sm-0 ml-3" type="submit">Button 3</button>
</div>
</div>
</nav>