所以我有3张卡片,我要把我的项目放进去,我需要它们完全水平居中。我尝试过很多东西,但到目前为止还没有。
以下是卡片的代码。
.card {
background: #fff;
border-radius: 3px;
display: inline-block;
height: 300px;
margin: 1rem;
position: relative;
width: 290px;
overflow: hidden;
opacity: 1;
}
.card .topImage {
display: inline-flex;
width: 100%;
height: 220px;
overflow: hidden;
align-content: center;
}
.topImage {
background-color: rgba(0, 0, 0, .3);
}
.card .topImage img {
height: 220px;
}
.card .bottom {
height: 80px;
width: 100%;
}
.card .bottom p {
text-align: left;
height: 80px;
width: 100%;
box-sizing: border-box;
margin: 0;
padding: 0;
padding-left: 20px;
display: flex;
align-items: center;
text-decoration: none;
color: #444;
font-size: 18px;
font-family: Roboto, sans-serif;
}
.card-1 {
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
transition: all 0.3s cubic-bezier(.25,.8,.25,1);
}
.card-1:hover {
box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
cursor: pointer;
}
<div class="card card-1">
<div class="topImage">
</div>
<div class="bottom">
<p>Project 1</p>
</div>
</div>
<div class="card card-1">
<div class="topImage">
</div>
<div class="bottom">
<p>Project 2</p>
</div>
</div>
<div class="card card-1">
<div class="topImage">
</div>
<div class="bottom">
<p>Project 3</p>
</div>
</div>
答案 0 :(得分:2)
使用flexbox这很容易。在包含div的元素上,只需添加display: flex;
和justify-content: center;
:
.card {
background: #fff;
border-radius: 3px;
display: inline-block;
height: 300px;
margin: 1rem;
position: relative;
width: 290px;
overflow: hidden;
opacity: 1;
}
.card .topImage {
display: inline-flex;
width: 100%;
height: 220px;
overflow: hidden;
align-content: center;
}
.topImage {
background-color: rgba(0, 0, 0, .3);
}
.card .topImage img {
height: 220px;
}
.card .bottom {
height: 80px;
width: 100%;
}
.card .bottom p {
text-align: left;
height: 80px;
width: 100%;
box-sizing: border-box;
margin: 0;
padding: 0;
padding-left: 20px;
display: flex;
align-items: center;
text-decoration: none;
color: #444;
font-size: 18px;
font-family: Roboto, sans-serif;
}
.card-1 {
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
transition: all 0.3s cubic-bezier(.25, .8, .25, 1);
}
.card-1:hover {
box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
cursor: pointer;
}
body {
display: flex;
justify-content: center;
}
&#13;
<div class="card card-1">
<div class="topImage">
</div>
<div class="bottom">
<p>Project 1</p>
</div>
</div>
<div class="card card-1">
<div class="topImage">
</div>
<div class="bottom">
<p>Project 2</p>
</div>
</div>
<div class="card card-1">
<div class="topImage">
</div>
<div class="bottom">
<p>Project 3</p>
</div>
</div>
&#13;
答案 1 :(得分:2)
只需使用flexbox。为卡片制作一个容器并放置display:flex;在它上面然后证明内容:无论新容器div的大小如何,都将它们置于中心位置
.card {
background: #fff;
border-radius: 3px;
display: inline-block;
height: 300px;
margin: 1rem;
position: relative;
width: 290px;
overflow: hidden;
opacity: 1;
}
.card .topImage {
display: inline-flex;
width: 100%;
height: 220px;
overflow: hidden;
align-content: center;
}
.topImage {
background-color: rgba(0, 0, 0, .3);
}
.card .topImage img {
height: 220px;
}
.card .bottom {
height: 80px;
width: 100%;
}
.card .bottom p {
text-align: left;
height: 80px;
width: 100%;
box-sizing: border-box;
margin: 0;
padding: 0;
padding-left: 20px;
display: flex;
align-items: center;
text-decoration: none;
color: #444;
font-size: 18px;
font-family: Roboto, sans-serif;
}
.card-1 {
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
transition: all 0.3s cubic-bezier(.25,.8,.25,1);
}
.card-1:hover {
box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
cursor: pointer;
}
.card-container {
display: flex;
justify-content: center;
}
&#13;
<div class="card-container">
<div class="card card-1">
<div class="topImage">
</div>
<div class="bottom">
<p>Project 1</p>
</div>
</div>
<div class="card card-1">
<div class="topImage">
</div>
<div class="bottom">
<p>Project 2</p>
</div>
</div>
<div class="card card-1">
<div class="topImage">
</div>
<div class="bottom">
<p>Project 3</p>
</div>
</div>
</div>
&#13;
答案 2 :(得分:1)
使用text-align: center
.card {
background: #fff;
border-radius: 3px;
display: inline-block;
height: 300px;
margin: 1rem;
position: relative;
width: 290px;
overflow: hidden;
opacity: 1;
}
.card .topImage {
display: inline-flex;
width: 100%;
height: 220px;
overflow: hidden;
align-content: center;
}
.topImage {
background-color: rgba(0, 0, 0, .3);
}
.card .topImage img {
height: 220px;
}
.card .bottom {
height: 80px;
width: 100%;
}
.card .bottom p {
text-align: left;
height: 80px;
width: 100%;
box-sizing: border-box;
margin: 0;
padding: 0;
padding-left: 20px;
display: flex;
align-items: center;
text-decoration: none;
color: #444;
font-size: 18px;
font-family: Roboto, sans-serif;
}
.card-1 {
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
transition: all 0.3s cubic-bezier(.25,.8,.25,1);
}
.card-1:hover {
box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
cursor: pointer;
}
.parent {
text-align: center;
}
&#13;
<div class="parent">
<div class="card card-1">
<div class="topImage">
</div>
<div class="bottom">
<p>Project 1</p>
</div>
</div>
<div class="card card-1">
<div class="topImage">
</div>
<div class="bottom">
<p>Project 2</p>
</div>
</div>
<div class="card card-1">
<div class="topImage">
</div>
<div class="bottom">
<p>Project 3</p>
</div>
</div>
</div>
&#13;
答案 3 :(得分:0)
使用Sub Refresh()
Worksheets("A").Range("A1:A7").Copy
Worksheets("B").Range("A1").PasteSpecial xlPasteAll
End Sub
和translateX
规则来定位它们。
left
&#13;
.card {
background: #fff;
border-radius: 3px;
display: inline-block;
height: 300px;
margin: 1rem;
position: relative;
width: 290px;
overflow: hidden;
opacity: 1;
left: 50%;
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
}
.card .topImage {
display: inline-flex;
width: 100%;
height: 220px;
overflow: hidden;
align-content: center;
}
.topImage {
background-color: rgba(0, 0, 0, .3);
}
.card .topImage img {
height: 220px;
}
.card .bottom {
height: 80px;
width: 100%;
}
.card .bottom p {
text-align: left;
height: 80px;
width: 100%;
box-sizing: border-box;
margin: 0;
padding: 0;
padding-left: 20px;
display: flex;
align-items: center;
text-decoration: none;
color: #444;
font-size: 18px;
font-family: Roboto, sans-serif;
}
.card-1 {
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
transition: all 0.3s cubic-bezier(.25,.8,.25,1);
}
.card-1:hover {
box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
cursor: pointer;
}
&#13;