CSS- how to give an object with scooped corners a border colour? - html

I created the following object with scooped borders ... http://jsfiddle.net/zjw3pg2e/
I want a way using pure CSS to give the object a black border. All my attempts at doing so have thus far failed.
HTML:
<div class="box"></div>
CSS:
.box {
position:relative;
height:200px;
width:200px;
overflow:hidden;
/*border: solid 2px black;*/
}
.box:before{
content:'';
position:absolute;
/*border: solid 2px black;*/
left:0;
margin:-20px;
height:40px;
width:40px;
border-radius:100%;
background:white;
box-shadow:200px 0 0 white,
0 200px 0 white,
200px 200px 0 white,
0 0 0 500px blue;
}
I tried setting the border for .box and .box:before as border: solid black 2px;, but this doesn't do what I am trying to achieve. I need the border to fit the shape of the object perfectly.
I suspect there's a way to do it by altering the box-shadow, but I can't figure it out. Any help is appreciated.

I did it with pure css in this example using 4 extra divs:
If youre worried about overflow you can just wrap it in an extra div.
JS FIDDLE
css:
.corner {
background:#fff;
height:20px;
width:20px;
position:absolute;
}
#sw {
left: -2px;
bottom: -2px;
border-radius: 0px 20px 0px 0px;
border-top: 2px solid #000;
border-right: 2px solid #000;
}
#se {
right: -2px;
bottom: -2px;
border-radius: 20px 0px 0px 0px;
border-top: 2px solid #000;
border-left: 2px solid #000;
}
#nw {
left: -2px;
top: -2px;
border-radius: 0px 0px 20px 0px;
border-bottom: 2px solid #000;
border-right: 2px solid #000;
}
#ne {
right: -2px;
top: -2px;
border-radius: 0px 0px 0px 20px;
border-bottom: 2px solid #000;
border-left: 2px solid #000;
}
.box {
position:relative;
height:200px;
width:200px;
border: solid 2px black;
background:blue;
border-radius: 5px -5px 5px 5px;
}
html:
<div class="box">
<div id="ne" class="corner"></div>
<div id="nw" class="corner"></div>
<div id="se" class="corner"></div>
<div id="sw" class="corner"></div>
</div>

So the solution I came up with... uses 3 divs (an outer-box, box, and inner-box).
The box:before/:after and box-inner:before/:after are the semi-circles. around the sides, that I gave a white background with a black border.
JS Fiddle
.box-wrapper{
position:relative;
height:202px;
width:202px;
overflow:hidden;
}
.box {
position: absolute;
height:200px;
width:200px;
background: blue;
border: 1px solid #000;
}
.box:before,
.box:after,
.box-inner:before,
.box-inner:after {
background: #fff;
content: ' ';
display: block;
height: 3em;
width: 3em;
border-radius: 50%;
border: solid 1px black;
position: absolute;
}
.box:before {
top: -1.5em;
left: -1.5em;
}
.box:after {
top: -1.5em;
right: -1.5em;
}
.box-inner:before {
bottom: -1.5em;
left: -1.5em;
}
.box-inner:after {
bottom: -1.5em;
right: -1.5em;
}
<div class="box-wrapper">
<div class="box">
<div class="box-inner"></div>
</div>
</div>
Normally you can apply a box-shadow: 0 0 1px #000;, which lets you give a border-like effect on top of borders, however the circles make the relative .box div will always sit on top of its :before/:after (making the box-shadow solution unobtainable).

Related

Slider Header using CSS

I have been trying to create an image like this using css.
which I partly achieved like this
<div class="nav-tab">
<div class="arrow-left"></div>
<div class="arrow"></div>
<div class="arrow-right"></div>
</div>
CSS
div {
float: left;
margin: 0;
padding: 0;
}
.arrow {
background-color: green;
height: 60px;
width: 240px;
}
.arrow-right {
width: 0;
height: 0;
border-top: 30px solid transparent;
border-bottom: 30px solid transparent;
border-left: 30px solid green;
}
.arrow-left {
width: 0;
height: 0;
border-top: 30px solid transparent;
border-bottom: 30px solid transparent;
border-left: 30px solid white;
position: relative;
left: 30px;
}
Fiddle: https://jsfiddle.net/codeandcloud/g3cmgw8y/6/
But the design has these problems
1) The arrow-left not having background-color transparent. ( Is it possible as per this design? )
2) What I want is to use it as the image below. When I put each .nav-tab in a ul > li with float:left the output is garbled.
Fiddle: https://jsfiddle.net/g3cmgw8y/7/
What am I doing wrong and how should I fix this.
How about using skew instead?
https://jsfiddle.net/foreyez/1gf3zam3/
<div class='arrow'>
<div class='arrowtop'>
</div>
<div class='arrowbottom'>
</div>
</div>
.arrowtop {
transform: translateX(50px) skewX(45deg);
width:400px;
height:50px;
background:red;
}
.arrowbottom {
transform: translateX(50px) skewX(-45deg);
width:400px;
height:50px;
background:red;
}
Hmm ... maybe this's an answer ?
.arrow-left {
border-top: 30px solid green;
border-bottom: 30px solid green;
border-left: 30px solid transparent;
position:relative;
left: 0px;
}

CSS border collapse different sizes in a div

Please take a look here:
http://jsfiddle.net/ztu267zp/1/
border:3px solid grey;
border-bottom: 8px solid red;
At the bottom corners you can see, that both the grey and the red borders intersect diagonally.
Can I cut the grey border to end at the bottom of the DIV and the red border having 100% width over the full distance?
Thank you very much,
Doing it right now with box-shadows, but also here, there is no clean edge in Chrome and FF:
http://imgur.com/mf7ABEO
Thanks
matt
its not possible but you can use something like this
<div id="bord">
<div class="line-cover">
</div>
css
#bord{
height:200px;
width:200px;
border:3px solid grey;
border-bottom: 8px solid white;
}
.line-cover{
position: relative;
border-bottom: 8px solid red;
width: 100%;
top: 200px;
padding: 0 3px;
left: -3px;
}
Fiddle here
What about st. like that, using pseudoelement after?
#bord{
height:200px;
width:200px;
border:3px solid grey;
border-bottom: 0;
/*border-bottom: 8px solid red;*/
position: relative;
}
#bord:after {
display: block;
background: red;
height: 8px;
width: 100%;
content: '';
position: absolute;
bottom: -8px;
left: 0;
margin: 0 -3px;
padding: 0 3px;
}
http://jsfiddle.net/ztu267zp/4/

How to make edgy corners with css

Does anyone know how to make edgy corners like in the following below? See how the edge wraps around the corner. I would like to know the term as well (if any). cross browser support (IE8 and up, bonus IE7) is a must. Thanks for any help.
Check out this tutorial. I don't know how crossbrowser compatible it is (as it is CSS3), but it achieves the effect you want.
HTML:
<div>
<h2></h2>
</div>
CSS:
div {
width: 200px;
padding: 50px;
margin: 0 auto;
border: 1px solid #333;
}
h2 {
position: relative;
width: 50%;
height: 50px;
margin: 30px 10px 10px -70px;
background-color: orange;
}
h2:after {
content: ' ';
position: absolute;
width: 0;
height: 0;
left: 0px;
top: 100%;
border-width: 5px 10px;
border-style: solid;
border-color: #666 #666 transparent transparent;
}
JS Fiddle Example
.box{
background: #666;
border: 4px solid #fff;
box-shadow: 0px 0px 20px #000;
width: 200px;
height: 200px;
margin: 40px auto;
position: relative;
}
.ribbon{
background: #FFA500;
position: absolute;
width: 100%;
top: 20px;
left: -20px;
height: 20px;
padding-right: 20px;
}
.ribbon::before{
content: '';
position: absolute;
left: 0px;
top: 20px;
width: 0px;
height: 0px;
border-style: solid;
border-width: 0 16px 10px 0;
border-color: transparent #FFA500 transparent transparent;
z-index: -5;
}
HTML:
<div class="box">
<div class="ribbon"></div>
</div>
(DEMO)
I don't think IE 7/8 support the ::before pseudo-element, so if you want IE compatibility add another element and put ::before styles on it :)
That edgy corner is only a div with a triangle actually, you only need ONE element to do it.
<div id="myCorner"></div>
myCorner will be the div, and myCorner:after will be the triangle.
Check it out : http://jsfiddle.net/Starx/Xp6E7/2/
#myCorner
{
width:100px;
height:70px;
background-color:orange;
-webkit-box-shadow: 0 4px 5px -3px black;
-moz-box-shadow: 0 4px 5px -3px black;
box-shadow: 0 4px 5px -3px black;
position:relative;
}
#myCorner:after
{
content:"";
position:absolute;
left: 0;
top:100%;
width: 0px;
height: 0px;
border-style:solid;
border-width: 5px 10px;
border-color: orange orange transparent transparent;
z-index: -1;
}

any border blank space trick ? for CSS

I need some trick to insert border blank space by using CSS like this..
I using CSS box-shadow like this
box-shadow:
-1px 0px 0px 0px #000,
0px -1px 0px 0px #000,
0px 1px 0px 0px #000,
1px 1px 0px 0px #000
I have no idea how to make border / shadow look like the picture.
I will use only one html element.. <div></div>
Any trick ?
Playground : http://jsfiddle.net/ES66k/
with one div only: http://jsfiddle.net/ES66k/1/ (tested on Fx18 and chrome)
div {
width:300px;
height:170px;
margin:100px;
border-top: 1px black solid;
border-bottom: 1px black solid;
position: relative;
}
div:after, div:before {
content: "";
position: absolute;
top: -1px;
width: 20px;
height: 172px;
border-top: 40px white solid;
border-bottom: 40px white solid;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
div:before { border-left: 1px black solid; left: 0; }
div:after { border-right: 1px black solid; right: 0; }
It's bit hacky, anyway, since it's relying on a fixed height and on a solid color as background (white) but maybe could be useful for your purpose.
You can create 4 <div>'s with classes .top-left, .top-right, .bottom-left and .bottom-right. Make them absolute and the container relative. Size them, make them the color of the containers bg-color and get them to the corners with top, right, bottom and left properties. Their value must be minus the border width.
Here is example of element with 3px border:
HTML:
<div class="box">
<div class="corner top-left"></div>
<div class="corner top-right"></div>
<div class="corner bottom-left"></div>
<div class="corner bottom-right"></div>
</div>
CSS:
.box{
width: 300px;
height: 300px;
border: 3px solid #666;
position:relative;
}
.corner{
width: 10px;
height: 10px;
background-color: #fff;
position: absolute;
}
.top-left{
top: -3px;
left: -3px;
}
.top-right {
top: -3px;
right: -3px;
}
.bottom-left{
bottom: -3px;
left: -3px;
}
.bottom-right{
bottom: -3px;
right: -3px;
}
Try to use the CSS3 attribute border-image:
Here's a demo you can have a look and try out yourself: CSS3 border-image
div {
width:300px;
height:170px;
margin:100px;
position:relative;
background:#ccc;
}
div:before, div:after {
content:"";
position:absolute;
top:0;
left:0;
}
div:before {
width:280px; /*****-20px*****/
height:168px; /*****-2px*****/
margin-left:10px;
border-top:1px solid #f00;
border-bottom:1px solid #f00;
}
div:after {
width:298px; /*****-2px*****/
height:150px; /*****-20px*****/
margin-top:10px;
border-left:1px solid #f00;
border-right:1px solid #f00;
}
Demo : http://jsfiddle.net/ES66k/4/
Done now, Don't need to set background-color :D
But thanks #Fabrizio Calderan anyway :D

Taking up layout space

I have the following CSS for a div element:
.tooltip
{
padding: .8em;
width: 12em; background:#999;
border-width: 2px !important;
border-color:#999;
position:absolute;
}
.tooltip .pointer, .tooltip .inner-pointer
{
position:absolute;
width:0;
height:0;
border-bottom-width: 0;
background: none;
}
.tooltip .pointer {
border-left: 7px solid transparent;
border-right: 7px solid transparent;
border-top: 14px solid #999;
bottom: -14px;
right: auto;
left: 5%;
margin-left: -7px;
}
.tooltip .inner-pointer {
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 5px solid #999;
bottom: auto;
top: -14px;
left: -5px;
}
Here is the DIV info
<div class="tooltip">Tooltip content goes here...<div class="pointer"><div class="inner-pointer"></div></div></div>
It the line below it, however cuts into the bottom of this tooltip, how do I make sure that it takes up all the space it is supposed to?
Here is an example in a jsFiddle:
http://jsfiddle.net/WEgBW/1/
Assuming that the problem is that something overlaps your tooltip, then you should add a z-index on the .tooltip
.tooltip
{
padding: .8em;
width: 12em; background:#999;
border-width: 2px !important;
border-color:#999;
position:absolute;
z-index: 999; /* added this line */
}