英文:
How to make a clipped card with a floating image on the left
问题
I want to make card style like this image using CSS but I can't make this curved left side and how to make the image positioned like this.
Any help, please!
I am trying to add border-radius for this left side but it's not working as expected.
Edited after applying some helpful answers, I get that result:
Here's the HTML:
<div class="card book" style="width:100%;">
<div class="card-body">
<div class="row">
<div class="col-4">
<img src="{{ asset('books/images/img.png') }}">
</div>
<div class="col-8" style="padding-left:5px;">
<h5 class="card-title">title</h5>
<h6 class="card-text card-subtitle text-muted mb-2">subtitle </h6>
<ul class="nav book-table-info align-items-center">
<li class="nav-item">
<p>الصفحات</p>
<p>
<span class="numero">324</span>
</p>
</li>
<li class="nav-item">
<p>lang</p>
<p>
en
</p>
</li>
<li class="nav-item">
<p>size</p>
<p> MB <span class="numero">7.34</span></p>
</li>
</ul>
</div>
</div>
</div>
</div>
And here's the CSS:
.book {
clip-path: polygon(150px 0, 100% 0, 100% 100%, 0 100%, 0 150px);
}
.book li:before {
content: '';
position: absolute;
left: -1rem;
top: 50%;
height: 20px;
background-color: #333;
width: 2px;
opacity: .5;
transform: translate(-50%, -50%);
}
.book li {
margin-left: 2rem;
margin-bottom: 1rem;
position: relative;
}
.book p {
vertical-align: middle;
border: 0;
font-size: 12px;
text-align: center;
font-weight: 600;
position: relative;
}
.book img {
position: absolute;
top: -24px;
border: 1px solid #ede9e5;
max-width: 120px;
height: auto;
max-height: 200px;
}
Now my problem is that the image is also clipped with the card.
英文:
I want to make card style like this image using css but I can't make this curved left side and how make image positioned like this
any help please !
curved image
I am trying to add border radius for this left side but not work like expected.
Edited
after apply trying some answers that was helpful
i get that result
result
and here html
<div class="card book" style="width:100%">
<div class="card-body">
<div class="row">
<div class="col-4">
<img src="{{ asset('books/images/img.png') }}">
</div>
<div class="col-8" style="padding-left:5px;">
<h5 class="card-title">title</h5>
<h6 class="card-text card-subtitle text-muted mb-2">substile </h6>
<ul class="nav book-table-info align-items-center">
<li class="nav-item">
<p>الصفحات</p>
<p>
<span class="numero">324</span>
</p>
</li>
<li class="nav-item">
<p>lang</p>
<p>
en
</p>
</li>
<li class="nav-item">
<p>size</p>
<p> MB <span class="numero">7.34</span></p>
</li>
</ul>
</div>
</div>
</div>
</div>
and here css
.book {
clip-path: polygon(150px 0, 100% 0, 100% 100%, 0 100%, 0 150px);
}
.book li:before {
content: '';
position: absolute;
left: -1rem;
top: 50%;
height: 20px;
background-color: #333;
width: 2px;
opacity: .5;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-o-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.book li {
margin-left: 2rem;
margin-bottom: 1rem;
position: relative;
}
.book p {
vertical-align: middle;
border: 0;
font-size: 12px;
text-align: center;
font-weight: 600;
position: relative;
}
.book img {
position: absolute;
top: -24px;
border: 1px solid #ede9e5;
max-width: 120px;
height: auto;
max-height: 200px;
}
now my problem is that image clipped too with card
答案1
得分: 0
你可以使用linear-gradient()
来创建这个形状:
background: linear-gradient(
135deg,
transparent var(--stop),
#ddd var(--stop)
);
然后,定位就很容易了:
.card {
position: relative;
/* ... */
}
.img {
position: absolute;
/* ... */
}
试一下:
<div>
<img src="https://picsum.photos/90/150">
</div>
英文:
You can use a linear-gradient()
to create the shape:
background: linear-gradient(
135deg,
transparent var(--stop),
#ddd var(--stop)
);
Positioning should be trivial then:
.card {
position: relative;
/* ... */
}
.img {
position: absolute;
/* ... */
}
Try it:
<!-- begin snippet: js hide: true -->
<!-- language: lang-css -->
:root {
--border-radius: 5px;
--height: 160px;
--width: 250px;
--padding-tb: 2em;
--padding-rl: 1em;
--stop: 90px;
--img-bottom: 1.5em;
--body-background: #fafafa;
}
div {
position: relative;
box-sizing: border-box;
border-radius: var(--border-radius);
height: var(--height);
width: var(--width);
padding: var(--padding-tb) var(--padding-rl);
background: linear-gradient(
135deg,
transparent var(--stop),
#ddd var(--stop)
);
}
img {
position: absolute;
bottom: var(--img-bottom);
}
/* Demo only */
body {
background: var(--body-background);
}
div {
margin: 3em auto;
box-shadow: 3px 3px 3px #aaa;
}
<!-- language: lang-html -->
<div>
<img src="https://picsum.photos/90/150">
</div>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论