我有四张相同的卡片,它们的高度可以根据里面的内容而变化。我想将卡片相对于容器中心的圆对齐,其高度和宽度为138 px。下面是我想要实现的图片布局:-x1c 0d1x
我想实现给定的布局。目前我使用的是绝对定位,并给固定值的顶部,右侧,底部,左侧的价值各自的四张卡。但是卡内的内容可以从后端增加或减少。因此,如果卡的内容是增加说,布局是打破,我希望这个布局是相同的卡内容和高度无关,但附近的圆圈的位置应该是相同的。以下是我实施的。是否有任何方法来实现所述布局是动态的,并相对于圆定位。
HTML和CSS:
.testi {
max-width: 1280px;
margin: 0 auto;
}
.container {
position: relative;
height: 1500px;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
.circle {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 138px;
height: 138px;
border-radius: 50%;
background-image: linear-gradient(to bottom, #00aeef 0%, #0095da 25%, #0071b4 50%, #0061af 75%, #293996 100%);
}
.inner-circle {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 80px;
height: 80px;
border-radius: 50%;
background-color: #fff;
}
/* testimonial card style */
.testimonial-card {
position: absolute;
width: 406px;
max-height: 888px;
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: stretch;
gap: 32px;
padding: 48px;
border-radius: 16px;
box-shadow: 0 4px 10px 0 rgba(0, 0, 0, 0.08);
background-color: #fff;
}
.testimonial-card {
width: 406px;
max-height: 888px;
flex-grow: 0;
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: stretch;
gap: 32px;
padding: 48px;
border-radius: 16px;
box-shadow: 0 4px 10px 0 rgba(0, 0, 0, 0.08);
background-color: #fff;
}
.testimonial-card-title {
font-family: Gotham;
font-size: 18px;
font-weight: normal;
font-stretch: normal;
font-style: normal;
line-height: 1.44;
letter-spacing: normal;
text-align: left;
color: #757584;
}
.testimonial-person-wrapper {
display: flex;
justify-content: space-between;
align-items: center;
}
.testimonial-card-image {
width: 120px;
height: 120px;
border-radius: 50%;
overflow: hidden;
}
.person-detail {
width: 250px;
}
.person-name {
height: 20px;
font-family: Gotham;
font-size: 14px;
font-weight: 500;
font-stretch: normal;
font-style: normal;
line-height: 1.43;
letter-spacing: normal;
text-align: left;
color: #263746;
}
.person-des {
font-family: Gotham;
font-size: 14px;
font-weight: normal;
font-stretch: normal;
font-style: normal;
line-height: 1.43;
letter-spacing: normal;
text-align: left;
color: #263746;
}
.location-container {
display: flex;
justify-content: space-between;
}
.Location {
width: 24px;
height: 24px;
flex-grow: 0;
object-fit: contain;
}
.office-title {
width: 106px;
font-family: Gotham;
font-size: 14px;
font-weight: normal;
font-stretch: normal;
font-style: italic;
line-height: 1.43;
letter-spacing: normal;
text-align: left;
color: #263746;
}
/* End of testimonial-card style */
.card1 {
top: 115px;
left: 0;
}
.card2 {
top: 115px;
right: 145px;
}
.card3 {
bottom: 165px;
left: 115px;
}
.card4 {
bottom: 165px;
right: 0;
}
<div class="container">
<div class="circle">
<div class="inner-circle"></div>
</div>
<div class="testimonial-wrapper">
<div class="testimonial-card card1">
<div class="testimonial-card-title">
“This will be my third year at HUB working on the Human Resources team. As a military spouse, it can be hard to find a role that allows you to advance in your career, but also be there for your service member and family. HUB has granted me that, and so much more. My supervisor understands my situation and continuously supports me through it. When my husband deployed, my team rallied around me and celebrated with us when he returned. The Military Veterans & Military Family Voices group is a special place where anyone who is in the military community has instant comradery and support. What I am impressed with most is this group’s ability to actively listen to each other’s experiences and draw lessons on how to be a better advocate from it.”
</div>
<div class="testimonial-person-wrapper">
<img class="testimonial-card-image" alt="100%x280" src="https://images.unsplash.com/photo-1532712938310-34cb3982ef74?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjMyMDc0fQ&s=3d2e8a2039c06dd26db977fe6ac6186a">
<div class="person-detail">
<div class="person-name">
Glenn Agoncillo
</div>
<div class="person-des">
Vice President of Constituent Experience and Co-chair of HUB Pride (LGBT) Voices
</div>
<div class="location-container">
<img src="Location.png" class="Location" alt="location-icon">
<div class="office-title">Office Location</div>
</div>
</div>
</div>
</div>
<div class="testimonial-card card2">
<div class="testimonial-card-title">
“My passion is to give a voice to those who are underrepresented. As someone who fits into that category, I’m passionate about bringing awareness and opportunities to those who look like me and making allies out of those who don’t. HUB Black Inclusion Network does just that; it provides a safe and collaborative space for this while enhancing HUB’s inclusive culture and expanding our diversity footprint.”
</div>
<div class="testimonial-person-wrapper">
<img class="testimonial-card-image" alt="100%x280" src="https://images.unsplash.com/photo-1532712938310-34cb3982ef74?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjMyMDc0fQ&s=3d2e8a2039c06dd26db977fe6ac6186a">
<div class="person-detail">
<div class="person-name">
Glenn Agoncillo
</div>
<div class="person-des">
Vice President of Constituent Experience and Co-chair of HUB Pride (LGBT) Voices
</div>
<div class="location-container">
<img src="Location.png" class="Location" alt="location-icon">
<div class="office-title">Office Location</div>
</div>
</div>
</div>
</div>
<div class="testimonial-card card3">
<div class="testimonial-card-title">
“In order for HUB to thrive, we must embrace diversity and inclusion so we can continue to serve all our clients from all walks of life. HUB Women Network (HWN) provides a forum to help women of all levels and diversity at HUB be able to Engage, Empower, and Excel in all aspects of their lives. Through monthly calls, webinars, and panel discussions, we create a safe space for women to speak freely, engage with others and exchange insights.”
</div>
<div class="testimonial-person-wrapper">
<img class="testimonial-card-image" alt="100%x280" src="https://images.unsplash.com/photo-1532712938310-34cb3982ef74?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjMyMDc0fQ&s=3d2e8a2039c06dd26db977fe6ac6186a">
<div class="person-detail">
<div class="person-name">
Glenn Agoncillo
</div>
<div class="person-des">
Vice President of Constituent Experience and Co-chair of HUB Pride (LGBT) Voices
</div>
<div class="location-container">
<img src="Location.png" class="Location" alt="location-icon">
<div class="office-title">Office Location</div>
</div>
</div>
</div>
</div>
<div class="testimonial-card card4">
<div class="testimonial-card-title">
“This year I’ll be celebrating 6 years working at HUB in the Risk Services Division and I am very proud to be involved in all the different opportunities to create a culture of diversity, equity, and inclusion in all regions. Now there are several ways to get involved as a leader, a participant, and an ambassador to do our part here at HUB. The Asian American/Pacific Islander community is a special place for me, to feel the genuine connection I have with other colleagues because of our similar cultural background. I am Chinese and Filipino, and this community provides me a natural way to support, connect and identify with other peers all while working at HUB.”
</div>
<div class="testimonial-person-wrapper">
<img class="testimonial-card-image" alt="100%x280" src="https://images.unsplash.com/photo-1532712938310-34cb3982ef74?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjMyMDc0fQ&s=3d2e8a2039c06dd26db977fe6ac6186a">
<div class="person-detail">
<div class="person-name">
Glenn Agoncillo
</div>
<div class="person-des">
Vice President of Constituent Experience and Co-chair of HUB Pride (LGBT) Voices
</div>
<div class="location-container">
<img src="Location.png" class="Location" alt="location-icon">
<div class="office-title">Office Location</div>
</div>
</div>
</div>
</div>
</div>
</div>
在此处附加原始UI:
3条答案
按热度按时间km0tfn4u1#
您的布局被破坏可能是因为顶部2必须基于
bottom
定位,底部2必须基于top
定位,因为内容被添加到容器的末尾。绝对定位应该足够了。
btqmn9zl2#
我相信你的问题来自于
absolute
的定位。通过使用网格,您应该能够相对于网格中心定位每张卡。然后,你只需要把圆放在中心。
请注意,您仍然需要翻译卡才能获得您正在寻找的这个转变,简单的
transform: translate(x, y);
就可以了。让我知道这是否回答了你的问题:
xmjla07d3#
定位绝对将工作-与一些改变的方式,你的立场卡。
此代码段从容器中删除了flex,但保留了圆居中的方式。
它将每张卡片相对于要与圆直径对齐的相关侧进行定位,并使用translateX/Y将其定位在离圆稍远的位置(为了方便起见,它使用圆的直径来完成此操作,当然如果您希望它更大,可以添加更多)。
为了帮助将来在需要时进行调整,代码片段根据圆的直径(CSS变量--d)进行计算。
您可能会考虑将卡片的尺寸也放入CSS变量中,可能与视口的宽度相关,以便整个事情变得更具响应性。