开发者

Corners with border - is there any possibility?

Let assume that I have image with border: 1 px solid black because i want it to have border. But for more i want rounded corners so i give border-radius: 10px. But 开发者_如何学Cthis now looks bad because corners don't have border. Is there possibility in html and css to do something which give borders to corners or answer is maybe somewhere in (for example) in jQuery?


sure just put the border on too.. and where there's a background color you can use an image, however IE support will be non-existant, but you might try CSSPie for enhancement for it. I think also some browsers do have a problem clipping on image to the round corners but am not too sure on overall support or fixes, perhaps putting the border on a parent div then rounding the image inside it might give a neat effect?

Example Fiddle

div, img {
    -moz-border-radius: 10px;
    -webkit-border-radius: 10px;
    border-radius: 10px;
    border: 1px solid #000;
    background: #0f0;
    width: 200px;
    margin: 50px;
    text-align: center;
    line-height: 40px;
}

HTML:

<div>rounded with border</div>
<img src="http://placekitten.com/100/100/" alt="">

Update: Webkit browsers do have problems with this if it's actually an image that needs rounding with borders, here's one workaround that seems to help:

New Example Fiddle

(view with webkit to see difference between second and third images)

HTML:

<div class="ri"><img src="http://placekitten.com/100/100/" alt=""></div>

CSS:

div {
   margin: 50px;
   text-align: center;
   line-height: 40px;
   width: 100px;
   height: 100px;
}

.ri {
   -moz-border-radius: 10px;
   -webkit-border-radius: 10px;
   border-radius: 10px;
   -webkit-background-clip: padding-box;
   border: 1px solid #000;
}

.ri img {
   display: block;
   -moz-border-radius: 10px;
   -webkit-border-radius: 10px;
   border-radius: 10px;
   -webkit-background-clip: padding-box;
}

the background-clip is supposed to help the background clip to the padding-box, which should in theory stop a background-image or color from extending into the border, but in itself it doesn't appear to work very well, so I nested the image and rounded both it and the parent div and then put the border onto the parent div, Webkit was happy ;)


You might try this curved-corner project on Google Code that purports to allow the border-radius CSS property to work cross-browser.


you can write with css3 & for IE you can download piecss3 js.

Example

div{
    width:200px;
    height:200px;
    background:red;
    color:#fff;
    -moz-border-radius:10px;
    -webkit-border-radius:10px;
    -khtml-border-radius:10px;
    border-radius:10px;
    border:2px solid yellow;
    behavior: url(PIE.htc);
}

check this http://jsfiddle.net/sandeep/KDBGV/


The other ways is:

CSS:

.container {
  background:gray; 
  color:#fff; 
  margin:0 15px;
}
.rtop, .rbottom {
  display:block;
  background:#fff;
}
.crvtop *, .crvbottom {
  display: block;
  height: 1px;
  overflow: hidden;
  background:gray;
}
.r1{margin: 0 5px}
.r2{margin: 0 3px}
.r3{margin: 0 2px}
.r4{margin: 0 1px; height: 2px}

HTML:

<div class="container">
   <b class="crvtop">
       <b class="r1"></b>
       <b class="r2"></b>
       <b class="r3"></b>
       <b class="r4"></b>
   </b>
   Place the content here
   <b class="crvbottom">
       <b class="r4"></b>
       <b class="r3"></b>
       <b class="r2"></b>
       <b class="r1"></b>
   </b>
</div>

This is going to work in all the browsers.

Cheers and Enjoy :)


Well Cris, The classes are for the spanned elements to create a curvy edges. Simply modify

.rtop, .rbottom {
  display:block;
  background:#fff;
}

.crvtop *, .crvbottom {
  display: block;
  height: 1px;
  overflow: hidden;
  background:gray;
}

with

.crvtop, .crvbottom {
  display:block;
  background:#fff;
}

.crvtop *, .crvbottom * {
  display: block;
  height: 1px;
  overflow: hidden;
  background:gray;
}



and it will work

Hope that helps..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜