简体   繁体   English

如何在图像CSS上放置思想泡泡

[英]How to place a thought bubble on top of an image CSS

I have a work project that entails getting an image from a user, and based on that image, place a thought bubble, or speech bubble on top of that image.I have to consider placement and all that, but I just want a working version first. 我有一个工作项目,需要从用户那里获取图像,并根据该图像,在该图像上放置一个思想泡泡或语音气泡。我必须考虑放置和所有这些,但我只想要一个工作版本第一。 I'm using the jQuery facial recognition library for the image but I can't find any info on how to get a bubble on the image. 我正在使用jQuery面部识别库来获取图像,但我找不到有关如何在图像上获取气泡的任何信息。

What about something like this. 这样的事情呢。

You can place the image inside a <div> which has a border-radius of 50% and overflow: hidden . 您可以将图像放在border-radius为50%且overflow: hidden<div>中。 This will clip the image to a rounded shape. 这会将图像剪切为圆形。

Then, using the CSS pseudo elements :before and :after , you can create two thought bubble trails. 然后,使用CSS伪元素:before:after ,您可以创建两个思想泡泡轨迹。

I also added a little animation to make the bubbles float. 我还添加了一个小动画来使气泡浮动。

 body { text-align: center; } .bubble-inner { overflow: hidden; border-radius: 50%; animation: float 2s ease-in-out infinite; } .bubble img { display: block; max-width: 100%; } .bubble { position: relative; display: inline-block; } .bubble:before, .bubble:after { content: ''; position: absolute; background-color: rgba(255,255,255,0.5); box-shadow: inset 0px 0px 2px 0px #000; border-radius: 50%; } .bubble:after { padding: 40px; bottom: -40px; left: 0; animation: float 2s ease-in-out 0.2s infinite; } .bubble:before { padding: 20px; bottom: -60px; left: -20px; animation: float 2s ease-in-out 0.3 infinite; } @keyframes float { 0% {transform: translate(0,0) scale(1,1);} 50% {transform: translate(0px,10px) scale(1.05,1);} 100% {transform: translate(0,0) scale(1,1);} } 
 <div class="bubble"> <div class="bubble-inner"> <img src="http://lorempixel.com/output/people-qc-200-200-1.jpg" alt="Person" > </div> </div> 

Since your question leaves a very broad range of answers, I will give you the simplest approach to use here: 由于您的问题留下了非常广泛的答案,我将在这里为您提供最简单的方法:

  1. Getting an image from a user, assumptions: 从用户那里获取图像,假设:

    • Either you have your own way of getting the image from the user and do not need help in such implementation, but are able to produce this image in HTML in a manner remotely similar to the following: 您可以使用自己的方式从用户获取图像,并且在此类实现中不需要帮助,但能够以远程类似于以下方式的HTML格式生成此图像:
    • Do not have your own way of getting an image. 没有自己的方式来获取图像。 In that case you need help with any kind of implementation; 在这种情况下,您需要任何类型的实施方面的帮助; which according to your tags: javascript/jquery/css/html allows for a wide variety, meaning I can provide with a very simple PHP alternative: PHP Upload a picture and display on page 根据你的标签:javascript / jquery / css / html允许多种多样,这意味着我可以提供一个非常简单的PHP替代方案: PHP上传图片并在页面上显示
  2. Getting a bubble on the image: very broad again, but considering we have CSS available (as well as being part of the tags) then I can easily refer you to a myriad of ways of getting this done (including the answers already provided here): Speech bubble with a shadow . 在图像上获得一个泡泡:非常宽泛,但考虑到我们有CSS可用(以及作为标签的一部分),那么我可以轻松地向您介绍完成此操作的各种方法(包括此处已提供的答案) : 带阴影的语音泡泡 You would then use either pure CSS or Javascript in order to dynamically show the speech bubble on the image after the image has been successfully loaded onto the page. 然后,您可以使用纯CSS或Javascript,以便在图像成功加载到页面后动态显示图像上的语音气泡。

HTML: HTML:

<span class="bubble">Speech bubble with a shadow</span>

CSS: CSS:

body {
    background: #d6d6d6;
    padding: 100px;
}

/* Speech bubble with a shadow */

.bubble {
    background-color: #fff0a0;
    background-image: -webkit-linear-gradient(top, hsla(0,0%,100%,.5), hsla(0,0%,100%,0));
    background-image:    -moz-linear-gradient(top, hsla(0,0%,100%,.5), hsla(0,0%,100%,0));
    background-image:     -ms-linear-gradient(top, hsla(0,0%,100%,.5), hsla(0,0%,100%,0));
    background-image:      -o-linear-gradient(top, hsla(0,0%,100%,.5), hsla(0,0%,100%,0));
    background-image:         linear-gradient(top, hsla(0,0%,100%,.5), hsla(0,0%,100%,0));
    border-radius: 5px;
    box-shadow: inset 0 1px 1px hsla(0,0%,100%,.5),
                3px 3px 0 hsla(0,0%,0%,.1);
    color: #333;
    display: inline-block;
    font: 16px/25px sans-serif;
    padding: 15px 25px;
    position: relative;
    text-shadow: 0 1px 1px hsla(0,0%,100%,.5);
}
.bubble:after, .bubble:before {
    border-bottom: 25px solid transparent;
    border-right: 25px solid #fff0a0;
    bottom: -25px;
    content: '';
    position: absolute;
    right: 25px;
}
.bubble:before {
    border-right: 25px solid hsla(0,0%,0%,.1);
    bottom: -28px;
    right: 22px;
}
  1. What to worry about: custom work, at that point in time you should come back with more questions (and code please). 需要担心的是:定制工作,在那个时候你应该回来提出更多问题(请提供代码)。

Regardless of how neat you wish to get this to work, you will not get a straight and exact answer from anyone unless we see more code from your side. 无论你希望如何使用它,你都不会得到任何人的直接和准确的答案,除非我们看到你身边的更多代码。 That aside, I believe that starting simple and working up from there will take you a long way... good luck! 除此之外,我相信从那里开始简单和工作将需要很长的路要走...祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM