CSS中插入边框半径形状?

时间:2013-02-13 09:57:39

标签: jquery html css css3 css-shapes

有没有办法在CSS中制作这个形状图像? CSS3很好,不需要IE兼容性。它的渐变部分并不重要,它是右下方的曲线,我看不到怎么做。我已经看过各种jQuery角落插件但到目前为止对我来说没什么用。我无法使用背景图片,因为此内容的长度可变。

enter image description here

编辑:感谢您的回复,非常令人印象深刻!但有一件事 - 在图像本身中,有一个蓝色背景和一个无缝的灰色边框围绕着整个事物,包括右边的曲线。如果解决方案涉及额外元素的边界半径“黑客”,也许不可能保持这个边界,但是如果这样可以保持也会更好。

3 个答案:

答案 0 :(得分:3)

我创造了一些东西。可能有更好的解决方案,但也许这会有所帮助。

jsFiddle

CSS:

.bubble {
    width: 200px;
    height: 30px;
}

.bubble .content {
    background: #00f;
    height: 100%;
    border-top-left-radius: 10px;
    border-bottom-left-radius: 10px;
    margin-right: 20px;
}

.bubble .blue,
.bubble .white,
.bubble .white .innerwhite {
    width: 10px;
    height: 100%;
    float: right;
}

.bubble .blue {
    background: #00f;
    border-top-right-radius: 10px;
}

.bubble .white {
    background: #00f;
}

.bubble .white .innerwhite {
    background: #fff;
    border-bottom-left-radius: 10px;
}

HTML:

<div class="bubble">
    <div class="white">
        <div class="innerwhite"></div>
    </div>
    <div class="blue"></div>
    <div class="content"></div>
</div>

答案 1 :(得分:2)

这是形状的CSS。你需要多种形状才能达到你想要的效果。

body{background:white;}

.Shape{margin:20px 30px;}

.Shape1{
  position:relative;
  width:200px;
  height:65px;
  background:blue;
  border-radius:20px;
  border:2px solid white;
  z-index:2;
  top:0px;
  left:0px;}

.Shape2{

  position:relative;
  width:70px;
  height:40px;
  background:blue;
  border-radius:12px;
  border-bottom:2px solid white;
  z-index:3;
  top:-42px;
  left:170px;}

.Shape3{
  position:relative;
  width:20px;
  height:20px;
  background:blue;
  z-index:4;
  top:-64px;
  left:170px;}

.Shape4{
   position:relative;
   width:40px;
   height:46px;
   background:white;
   top:-110px;
   left:202px;
   z-index:3;
   box-shadow:inset 2px 0px 4px lightgray;
   border-bottom-left-radius:40px;}

.Shape5{
  position:relative;
  height:1px;
  width:218px;
  background:transparent;
  box-shadow:0px 0px 8px black;
  left:18px;
  top:-110px;}

.Shape6{
  position:relative;
  height:50px;
  width:20px;
  background:white;
  top:-160px;
  left:236px;
  z-index:4;}

.Shape7{
  position:relative;
  height:10px;
  width:50px;
  background:white;
  top:-210px;
  left:203px;
  z-index:4;}

HTML:

  <div class="Shape">

  <div class="Shape1"></div>
  <div class="Shape2"></div>
  <div class="Shape3"></div>
  <div class="Shape4"></div>
  <div class="Shape5"></div>
  <div class="Shape6"></div>
  <div class="Shape7"></div>

  </div>

这是output的JsBin。

答案 2 :(得分:0)

在单个DOM对象上无法使用标准CSS完成向外边框,但您可以使用CSS通过添加额外元素来完成此操作。

这样做的诀窍是使用CSS :before:after选择器在主元素的任一侧有效地创建一个额外的元素,然后使用适当的border-radius和{ {1}}将其塑造成适合的。

这并不容易,但将它用于制表符已经成为一种常见的技巧。例如,see here是一个很好的教程。

希望有所帮助。