如何制作一个带有左侧浮动图像的剪裁卡片

huangapple go评论67阅读模式
英文:

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!

curved image

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:

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

&lt;div class=&quot;card book&quot; style=&quot;width:100%&quot;&gt;
        &lt;div class=&quot;card-body&quot;&gt;
            &lt;div class=&quot;row&quot;&gt;
                &lt;div class=&quot;col-4&quot;&gt;
                    &lt;img src=&quot;{{ asset(&#39;books/images/img.png&#39;) }}&quot;&gt;
                &lt;/div&gt;
                &lt;div class=&quot;col-8&quot; style=&quot;padding-left:5px;&quot;&gt;
                    &lt;h5 class=&quot;card-title&quot;&gt;title&lt;/h5&gt;
                    &lt;h6 class=&quot;card-text card-subtitle text-muted mb-2&quot;&gt;substile &lt;/h6&gt;

                    &lt;ul class=&quot;nav book-table-info align-items-center&quot;&gt;
                        &lt;li class=&quot;nav-item&quot;&gt;
                            &lt;p&gt;الصفحات&lt;/p&gt;
                            &lt;p&gt;
                                &lt;span class=&quot;numero&quot;&gt;324&lt;/span&gt;
                            &lt;/p&gt;
                        &lt;/li&gt;
                        &lt;li class=&quot;nav-item&quot;&gt;
                            &lt;p&gt;lang&lt;/p&gt;
                            &lt;p&gt;
                                en
                            &lt;/p&gt;
                        &lt;/li&gt;
                        &lt;li class=&quot;nav-item&quot;&gt;
                            &lt;p&gt;size&lt;/p&gt;
                            &lt;p&gt; MB &lt;span class=&quot;numero&quot;&gt;7.34&lt;/span&gt;&lt;/p&gt;
                        &lt;/li&gt;
                    &lt;/ul&gt;
                &lt;/div&gt;
            &lt;/div&gt;

        &lt;/div&gt;

    &lt;/div&gt; 

and here css

 .book {
            clip-path: polygon(150px 0, 100% 0, 100% 100%, 0 100%, 0 150px);
        }
  .book li:before {
            content: &#39;&#39;;
            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 -->

&lt;div&gt;
  &lt;img src=&quot;https://picsum.photos/90/150&quot;&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年5月28日 14:32:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76350238.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定