CSS应用边框到云形状? [英] CSS apply border to a cloud shape?

查看:187
本文介绍了CSS应用边框到云形状?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用不同的 div 标签通过CSS3绘制一个云我试图添加一个边框到整个形状,但我有麻烦,因为每个形状都有自己的边框我可以应用一个边界到整个云吗?



HTML

 < div id =cloud> 
< div id =bottom_c>< / div>
< div id =right_c>< / div>
< div id =left_c>< / div>
< / div>

CSS:

  * {
margin:0;
padding:0;
border:0;
}

body {
background-color:#4ca3ff;
}
#cloud {
position:absolute;

}
#bottom_c {
position:relative; top:200px; left:500px;
width:350px;
height:150px;
background-color:#fff;
border-radius:100px;
border:solid 5px black;
z-index:100;
}
#right_c {
position:absolute; top:140px; left:640px;
width:150px;
height:150px;
border-radius:100%;
background-color:#fff;
border:solid 5px black;
}
#left_c {
position:absolute; top:170px; left:550px;
width:100px;
height:100px;
border-radius:100%;
background-color:#fff;
border:solid 5px black;
}

图片



解决方案

你可以做到没有任何额外的元素。只需使用与顶层云相同大小和圆形的 :: before :: after 气泡。 z-index 会将所有内容保留在正确的层中。



演示:



输出:





CSS:



  body {
background-color:#4ca3ff;
}

#cloud {
height:230px;
margin:40px;
position:relative;
width:400px;
}

#cloud div {
border:solid 5px black;
}

#bottom_c {
background-color:#fff;
border-radius:100px;
height:150px;
position:absolute;
top:100px;
width:350px;
z-index:0;
}

#right_c {
background-color:#fff;
border-radius:100%;
height:150px;
left:140px;
position:absolute;
top:40px;
width:150px;
z-index:-1;
}

#left_c {
background-color:#fff;
border-radius:100%;
height:100px;
left:50px;
position:absolute;
top:70px;
width:100px;
z-index:-1;
}

#cloud :: before {
background-color:white;
border-radius:50%;
content:'';
height:100px;
left:55px;
position:absolute;
top:75px;
width:100px;
z-index:1;
}

#cloud :: after {
position:absolute; top:45px; left:145px;
background-color:white;
border-radius:50%;
content:'';
width:150px;
height:150px;
z-index:1;
}



HTML:



< class =lang-html prettyprint-override> < div id =cloud>
< div id =bottom_c>< / div>
< div id =right_c>< / div>
< div id =left_c>< / div>
< / div>


I drew a cloud via CSS3 using different div tags I am trying to add a border to the whole shape but I am having trouble since every shape get its own border how can I apply a border to the whole cloud?

HTML:

<div id="cloud">
  <div id="bottom_c"></div>
  <div id="right_c"></div>
  <div id="left_c"></div>
</div>

CSS:

* {
  margin: 0;
  padding: 0;
  border: 0;
}

body{
  background-color: #4ca3ff;
}
#cloud {
  position: absolute;

}
#bottom_c {
  position: relative; top: 200px; left: 500px;
  width: 350px;
  height: 150px;
  background-color: #fff;
  border-radius: 100px;
  border: solid 5px black;
  z-index: 100;
}
#right_c{
  position: absolute; top: 140px; left: 640px;
  width: 150px;
  height: 150px;
  border-radius: 100%;
  background-color: #fff;
  border: solid 5px black;
}
#left_c{
  position: absolute; top: 170px; left: 550px;
  width: 100px;
  height: 100px;
  border-radius: 100%;
  background-color: #fff;
  border: solid 5px black;
}

Image:

解决方案

You can do it without any additional elements. Just use the ::before and ::after pseudo-elements with the same size and round shape as the top cloud bubbles. z-index keeps everything in the right layer.

Demo:

Output:

CSS:

body{
    background-color: #4ca3ff;
}

#cloud {
    height: 230px;
    margin: 40px;
    position: relative;
    width: 400px;
}

#cloud div {
    border: solid 5px black;
}

#bottom_c {
    background-color: #fff;
    border-radius: 100px;
    height: 150px;
    position: absolute; 
    top: 100px;
    width: 350px;
    z-index: 0;
}

#right_c{
    background-color: #fff;
    border-radius: 100%;
    height: 150px;
    left: 140px;
    position: absolute; 
    top: 40px; 
    width: 150px;
    z-index: -1;
}

#left_c{
    background-color: #fff;  
    border-radius: 100%;
    height: 100px;
    left: 50px;
    position: absolute; 
    top: 70px; 
    width: 100px;
    z-index: -1;
}

#cloud::before {
    background-color: white;
    border-radius: 50%;
    content: '';
    height: 100px;
    left: 55px;
    position: absolute; 
    top: 75px; 
    width: 100px;
    z-index: 1;
}

#cloud::after {
    position: absolute; top: 45px; left: 145px;
    background-color: white;
    border-radius: 50%;
    content: '';
    width: 150px;
    height: 150px;
    z-index: 1;
}

HTML:

<div id="cloud">
  <div id="bottom_c"></div>
  <div id="right_c"></div>
  <div id="left_c"></div>
</div>

这篇关于CSS应用边框到云形状?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆