【问题标题】:Complex circles with images inside内部带有图像的复杂圆圈
【发布时间】:2014-11-19 22:09:43
【问题描述】:

我正在尝试创建一个内部带有图像的圆圈,并在该圆圈的页脚中创建一个矩形..

显示解释更简单:http://i.imgur.com/yK7Edrc.png

小提琴:http://jsfiddle.net/77b34nh0/

我有点迷茫,圆圈底部的信息框怎么办?

谢谢。

代码:

HTML:

<img class="wow rotateIn" src="http://lorempixel.com/250/250/">

CSS:

img {
    margin: 10px 0 20px 0;
    width: 254px;
    height: 254px;
    border-radius: 50%;
    border: 2px solid #f98835; 
}

【问题讨论】:

    标签: html css image frontend


    【解决方案1】:

    你需要

    1. 将图像包装在容器中

    2. 制作容器position:relative - 这允许您将.caption div 相对于该父div 定位

    3. 相对于容器div底部的绝对定位矩形

    HTML

    <div class="circle_image_box_with_caption">
        <img class="wow rotateIn" src="http://lorempixel.com/250/250/">
        <div class="caption">
            This is my caption text
        </div>
    </div>
    

    或使用 HTML5

    <figure class="circle_image_box_with_caption">
        <img class="wow rotateIn" src="http://lorempixel.com/250/250/">
        <figcaption class="caption"> <!-- don't need the class really since it's already a semantic element and can be targeted in css with .circle_image_box_with_caption figcaption -->
            This is my caption text
        </figcaption>
    </figure>
    

    CSS

    .circle_image_box_with_caption {
        position:relative;
        width: 254px;
        height: 254px;
    
    }
    .circle_image_box_with_caption img {
        margin: 10px 0 20px 0;
        width:100%;
        height:100%;
        border-radius: 50%;
        border: 2px solid #f98835; 
    }
    .circle_image_box_with_caption .caption {
        position: absolute;
        bottom: -20px;
        border: 1px solid #ccc;
        width: 100%;
        text-align: center;
        padding: 10px 0px;
        background: #ccc;
    }
    

    小提琴:http://jsfiddle.net/77b34nh0/2/

    【讨论】:

    • 请记住,上述方法不适用于非正方形的图像,而不会弄乱图像比例。
    • 如果您使用 &lt;figure&gt;&lt;figcaption&gt; 元素来表示语义,则可以加分。
    • 非常感谢乔娜、海和巴里!
    猜你喜欢
    • 2019-03-18
    • 2015-06-09
    • 1970-01-01
    • 2020-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-22
    相关资源
    最近更新 更多