我得到了一系列的发射,我希望将每个图像居中 但图像可以有不同的大小,我不想让它们变形
#emission .card_emission_container_circle {
padding: 30px;
width: 350px;
height: 350px;
position: relative;
text-align: center;
margin-bottom: 20px;
}
#emission .card_emission_circle {
box-shadow: 0 12px 16px 0 rgba(0, 0, 0, 0.24), 0 17px 50px 0 rgba(0, 0, 0, 0.19) !important;
text-align: center;
transition: box-shadow 0.3s;
border-radius: 50%;
width: 300px;
height: 300px;
}
#emission .card_emission_circle:hover {
box-shadow: 0 12px 16px 0 rgba(216, 63, 65, 1), 0 17px 50px 0 rgba(216, 63, 65, 1) !important;
}
#emission .card_emission_image_circle img {
border-radius: 50%;
max-width: 300px;
max-height: 300px;
}
#emission .card_emission_container_circle a {
text-decoration: none;
color: rgba(37, 39, 51, 0.9);
width: 300px;
height: 300px;
}
#emission .card_emission_descript_circle {
border-radius: 10%;
z-index: 2;
padding: 0.01em 16px;
text-align: center;
overflow-y: hidden;
text-overflow: ellipsis;
word-wrap: break-word;
position: absolute;
top: 100px;
opacity: 0;
width: 300px;
height: 300px;
}
#emission .card_emission_descript_circle a {
text-decoration: none;
color: rgba(37, 39, 51, 0.9);
width: 300px;
height: 300px;
}
<div id="emission">
<div class="card_emission_container_circle grid-4 grid-t-6 grid-m-12">
<a class="ajax" href="./contentEmission.php?chrid=7">
<div class="card_emission_circle">
<div class="card_emission_image_circle">
<img src="https://www.chassimages.com/mag/wp-content/uploads/2017/02/ImageJour-ThomasMeunier-300x160.jpg" alt="Image de l'émission">
</div>
<div class="card_emission_descript_circle">
<p>Description</p>
</div>
</div>
<div class="card_emission_title_circle">
<h3>Title</h3>
</div>
</a>
</div>
<div class="card_emission_container_circle grid-4 grid-t-6 grid-m-12">
<a class="ajax" href="./contentEmission.php?chrid=7">
<div class="card_emission_circle">
<div class="card_emission_image_circle">
<img src="https://www.france.tv/image/carre/300/300/0/9/9/b5b0b7bd-b4ed2457c172bf7c0abd9e904aff7f5f1a0fea5d60eca094df1dd476b0c6a990.jpg" alt="Image de l'émission">
</div>
<div class="card_emission_descript_circle">
<p>Description</p>
</div>
</div>
<div class="card_emission_title_circle">
<h3>Title</h3>
</div>
</a>
</div>
</div>
第二个是好的,第一个是不正确的,我想将它垂直居中于它的div,问题是我需要通用解决方案,可以应用于所有图像,好或“坏”大小
答案 0 :(得分:1)
这里有两个选项:
top: 50%; transform: translateY(-50%);
方法flex
与align-items
- 首选,imo 以下是方法:
1。但需要向height: 100%
元素添加#emission .card_emission_image_circle
。
然后我们可以为#emission .card_emission_image_circle img
元素提供top: 50%; transform: translateY(-50%)
处理。
#emission .card_emission_image_circle {
height: 100%;
}
#emission .card_emission_image_circle img {
position: relative;
top: 50%;
transform: translateY(-50%);
border-radius: 50%;
max-width: 300px;
max-height: 300px;
}
#emission .card_emission_container_circle {
padding: 30px;
width: 350px;
height: 350px;
position: relative;
text-align: center;
margin-bottom: 20px;
}
#emission .card_emission_circle {
box-shadow: 0 12px 16px 0 rgba(0, 0, 0, 0.24), 0 17px 50px 0 rgba(0, 0, 0, 0.19) !important;
text-align: center;
transition: box-shadow 0.3s;
border-radius: 50%;
width: 300px;
height: 300px;
position: relative;
}
#emission .card_emission_circle:hover {
box-shadow: 0 12px 16px 0 rgba(216, 63, 65, 1), 0 17px 50px 0 rgba(216, 63, 65, 1) !important;
}
#emission .card_emission_image_circle {
height: 100%;
}
#emission .card_emission_image_circle img {
position: relative;
top: 50%;
transform: translateY(-50%);
border-radius: 50%;
max-width: 300px;
max-height: 300px;
}
#emission .card_emission_container_circle a {
text-decoration: none;
color: rgba(37, 39, 51, 0.9);
width: 300px;
height: 300px;
}
#emission .card_emission_descript_circle {
border-radius: 10%;
z-index: 2;
padding: 0.01em 16px;
text-align: center;
overflow-y: hidden;
text-overflow: ellipsis;
word-wrap: break-word;
position: absolute;
top: 100px;
opacity: 0;
width: 300px;
height: 300px;
}
#emission .card_emission_descript_circle a {
text-decoration: none;
color: rgba(37, 39, 51, 0.9);
width: 300px;
height: 300px;
}
&#13;
<div id="emission">
<div class="card_emission_container_circle grid-4 grid-t-6 grid-m-12">
<a class="ajax" href="./contentEmission.php?chrid=7">
<div class="card_emission_circle">
<div class="card_emission_image_circle">
<img src="https://www.chassimages.com/mag/wp-content/uploads/2017/02/ImageJour-ThomasMeunier-300x160.jpg" alt="Image de l'émission">
</div>
<div class="card_emission_descript_circle">
<p>Description</p>
</div>
</div>
<div class="card_emission_title_circle">
<h3>Title</h3>
</div>
</a>
</div>
<div class="card_emission_container_circle grid-4 grid-t-6 grid-m-12">
<a class="ajax" href="./contentEmission.php?chrid=7">
<div class="card_emission_circle">
<div class="card_emission_image_circle">
<img src="https://www.france.tv/image/carre/300/300/0/9/9/b5b0b7bd-b4ed2457c172bf7c0abd9e904aff7f5f1a0fea5d60eca094df1dd476b0c6a990.jpg" alt="Image de l'émission">
</div>
<div class="card_emission_descript_circle">
<p>Description</p>
</div>
</div>
<div class="card_emission_title_circle">
<h3>Title</h3>
</div>
</a>
</div>
</div>
&#13;
2。这是一个更简单的更改,只需要添加以下样式:
#emission .card_emission_image_circle {
height: 100%;
display: flex;
align-items: center;
}
#emission .card_emission_container_circle {
padding: 30px;
width: 350px;
height: 350px;
position: relative;
text-align: center;
margin-bottom: 20px;
}
#emission .card_emission_circle {
box-shadow: 0 12px 16px 0 rgba(0, 0, 0, 0.24), 0 17px 50px 0 rgba(0, 0, 0, 0.19) !important;
text-align: center;
transition: box-shadow 0.3s;
border-radius: 50%;
width: 300px;
height: 300px;
}
#emission .card_emission_circle:hover {
box-shadow: 0 12px 16px 0 rgba(216, 63, 65, 1), 0 17px 50px 0 rgba(216, 63, 65, 1) !important;
}
#emission .card_emission_image_circle {
height: 100%;
display: flex;
align-items: center;
}
#emission .card_emission_image_circle img {
border-radius: 50%;
max-width: 300px;
max-height: 300px;
}
#emission .card_emission_container_circle a {
text-decoration: none;
color: rgba(37, 39, 51, 0.9);
width: 300px;
height: 300px;
}
#emission .card_emission_descript_circle {
border-radius: 10%;
z-index: 2;
padding: 0.01em 16px;
text-align: center;
overflow-y: hidden;
text-overflow: ellipsis;
word-wrap: break-word;
position: absolute;
top: 100px;
opacity: 0;
width: 300px;
height: 300px;
}
#emission .card_emission_descript_circle a {
text-decoration: none;
color: rgba(37, 39, 51, 0.9);
width: 300px;
height: 300px;
}
&#13;
<div id="emission">
<div class="card_emission_container_circle grid-4 grid-t-6 grid-m-12">
<a class="ajax" href="./contentEmission.php?chrid=7">
<div class="card_emission_circle">
<div class="card_emission_image_circle">
<img src="https://www.chassimages.com/mag/wp-content/uploads/2017/02/ImageJour-ThomasMeunier-300x160.jpg" alt="Image de l'émission">
</div>
<div class="card_emission_descript_circle">
<p>Description</p>
</div>
</div>
<div class="card_emission_title_circle">
<h3>Title</h3>
</div>
</a>
</div>
<div class="card_emission_container_circle grid-4 grid-t-6 grid-m-12">
<a class="ajax" href="./contentEmission.php?chrid=7">
<div class="card_emission_circle">
<div class="card_emission_image_circle">
<img src="https://www.france.tv/image/carre/300/300/0/9/9/b5b0b7bd-b4ed2457c172bf7c0abd9e904aff7f5f1a0fea5d60eca094df1dd476b0c6a990.jpg" alt="Image de l'émission">
</div>
<div class="card_emission_descript_circle">
<p>Description</p>
</div>
</div>
<div class="card_emission_title_circle">
<h3>Title</h3>
</div>
</a>
</div>
</div>
&#13;