Custom/irregular border radius using css - css

Is there a way to create this kind of border radius? its like the opposite of the normal border-radius, I cant figure out how to make that one.
I search on related questions here, but cant find one.
Hope you help me.
thanks

I would do it like this:
body {
background:pink;
}
.box {
margin:40px;
height:80px;
border:3px solid #000;
border-bottom:none;
border-radius:20px 20px 0 0;
position:relative;
}
.box:before {
content:"";
position:absolute;
bottom:-20px;
left:-20px;
right:-20px;
border-bottom:3px solid #000;
}
.box:after {
content:"";
position:absolute;
left:-20px;
right:-20px;
top:100%;
height:20px;
background:
radial-gradient(circle at top right, transparent 60%,#000 61.5%,#000 72%,transparent 74%) top right/20px 100% no-repeat,
radial-gradient(circle at top left, transparent 60%,#000 61.5%,#000 72%,transparent 74%) top left/20px 100% no-repeat;
}
<div class="box">
</div>
You can add more control with CSS variable:
body {
background:pink;
}
.box {
margin:var(--r,20px);
height:80px;
border:3px solid #000;
border-bottom:none;
border-radius:var(--r,20px) var(--r,20px) 0 0;
position:relative;
}
.box:before {
content:"";
position:absolute;
bottom:calc(-1 * var(--r,20px));
left:calc(-1 * var(--r,20px));
right:calc(-1 * var(--r,20px));
border-bottom:3px solid #000;
}
.box:after {
content:"";
position:absolute;
left:calc(-1 * var(--r,20px));
right:calc(-1 * var(--r,20px));
top:100%;
height:var(--r,20px);
background:
radial-gradient(circle at top right, transparent calc(71% - 3px),#000 calc(71% - 2px),#000 71%,transparent 73%) top right,
radial-gradient(circle at top left, transparent calc(71% - 3px),#000 calc(71% - 2px),#000 71%,transparent 73%) top left;
background-size:var(--r,20px) 100%;
background-repeat:no-repeat;
}
<div class="box">
</div>
<div class="box" style="--r:50px">
</div>
<div class="box" style="--r:80px">
</div>

Related

Flip CSS bubble triangle position?

Fiddle
HTML:
<blockquote class="rectangle-speech-border">
<p>This is a blockquote that is styled to look like a speech bubble</p>
</blockquote>
CSS:
.rectangle-speech-border {
position:relative;
padding:50px 15px;
margin:1em 0 3em;
border:10px solid #5a8f00;
text-align:center;
color:#333;
background:#fff;
/* css3 */
-webkit-border-radius:20px;
-moz-border-radius:20px;
border-radius:20px;
}
/* creates larger curve */
.rectangle-speech-border:before {
content:"";
position:absolute;
z-index:10;
bottom:-40px;
left:50px;
width:50px;
height:30px;
border-style:solid;
border-width:0 10px 10px 0;
border-color:#5a8f00;
background:transparent;
/* css3 */
-webkit-border-bottom-right-radius:80px 50px;
-moz-border-radius-bottomright:80px 50px;
border-bottom-right-radius:80px 50px;
/* reduce the damage in FF3.0 */
display:block;
}
/* creates smaller curve */
.rectangle-speech-border:after {
content:"";
position:absolute;
z-index:10;
bottom:-40px;
left:50px;
width:20px;
height:30px;
border-style:solid;
border-width:0 10px 10px 0;
border-color:#5a8f00;
background:transparent;
/* css3 */
-webkit-border-bottom-right-radius:40px 50px;
-moz-border-radius-bottomright:40px 50px;
border-bottom-right-radius:40px 50px;
/* reduce the damage in FF3.0 */
display:block;
}
/* creates a small circle to produce a rounded point where the two curves meet */
.rectangle-speech-border > :first-child:before {
content:"";
position:absolute;
bottom:-40px;
left:45px;
width:10px;
height:10px;
background:#5a8f00;
/* css3 */
-webkit-border-radius:10px;
-moz-border-radius:10px;
border-radius:10px;
}
/* creates a white rectangle to cover part of the oval border*/
.rectangle-speech-border > :first-child:after {
content:"";
position:absolute;
bottom:-10px;
left:76px;
width:24px;
height:15px;
background:#fff;
}
Example taken from: Nicolas Gallagher
Basically this text bubble is curving to the left and on the bottom-left. I'd like to duplicate it exactly except have it on bottom-right and curving to the right. Just flip it.
I've tried changing the rights into lefts but it's not happening. Can anyone tell me what needs to change to flip this bubble?
Do you mean this?
If you want to change geometry, you should to play with border-width and border-radius. Also I changed pseudo-class from :after to :before, and vice versa in elements and border-radius from right to left.
.rectangle-speech-border {
position:relative;
padding:50px 15px;
margin:1em 0 3em;
border:10px solid #5a8f00;
text-align:center;
color:#333;
background:#fff;
/* css3 */
-webkit-border-radius:20px;
-moz-border-radius:20px;
border-radius:20px;
}
/* creates larger curve */
.rectangle-speech-border:after {
content:"";
position:absolute;
z-index:10;
bottom:-40px;
left:400px;
width:20px;
height:30px;
border-style:solid;
border-width:0 0 10px 10px;
border-color:#5a8f00;
background:transparent;
/* css3 */
-webkit-border-bottom-left-radius:40px 50px;
-moz-border-bottom-left-radius:40px 50px;
border-bottom-left-radius:40px 50px;
/* reduce the damage in FF3.0 */
display:block;
}
/* creates smaller curve */
.rectangle-speech-border:before {
content:"";
position:absolute;
z-index:10;
left:370px;
width:50px;
height:30px;
bottom: -40px;
border-style:solid;
border-width:0 0 10px 10px;
border-color:#5a8f00;
background:transparent;
/* css3 */
-webkit-border-bottom-left-radius:40px 50px;
-moz-border-bottom-left-radius:40px 50px;
border-bottom-left-radius:40px 50px;
/* reduce the damage in FF3.0 */
display:block;
}
/* creates a small circle to produce a rounded point where the two curves meet */
.rectangle-speech-border > :first-child:before {
content:"";
position:absolute;
bottom:-40px;
left:425px;
width:10px;
height:10px;
background:#5a8f00;
/* css3 */
-webkit-border-radius:10px;
-moz-border-radius:10px;
border-radius:10px;
}
/* creates a white rectangle to cover part of the oval border*/
.rectangle-speech-border > :first-child:after {
content:"";
position:absolute;
bottom:-10px;
left:376px;
width:24px;
height:15px;
background:#fff;
}
<blockquote class="rectangle-speech-border">
<p>This is a blockquote that is styled to look like a speech bubble</p>
</blockquote>

Increase space between border and background-image

I want to increase the distance between the border and the background-image ... I tried to add padding: 20px; but it doesn't work.
.Tab1 {
background-image: url("http://dl.dg-site.com/wp-content/themes/aeron/images/dl-products-icons5.jpg");
width: 100px;
height: 75px;
display: block;
}
.Tab1:hover {
border: 1px solid green;
}
<div class="Tab1"></div>
You can increase the space between the border and the background image with padding and background-clip:content-box; (see MDN for more info).
Also don't forget to center the background image with background-position:center;
.Tab1 {
background-image:url("http://dl.dg-site.com/wp-content/themes/aeron/images/dl-products-icons5.jpg");
background-position:center;
width:100px;
height:73px;
display:block;
padding:20px;
background-clip:content-box;
}
.Tab1:hover {
border:1px solid green;
}
<div class="Tab1"></div>
If you also want to avoid the position snap on hover created by the border, you can add a transparent border and only change the colour on hover :
.Tab1 {
background-image: url("http://dl.dg-site.com/wp-content/themes/aeron/images/dl-products-icons5.jpg");
background-repeat: no-repeat;
background-position: center;
background-clip: content-box;
width: 100px;
height: 75px;
display: block;
padding: 50px;
border: 1px solid transparent;
}
.Tab1:hover {
border-color: green;
}
<div class="Tab1"></div>
.Tab1{background-image:url("http://dl.dg-site.com/wp-content/themes/aeron/images/dl-products-icons5.jpg");
background-repeat:no-repeat;
background-position:center;
background-clip:content-box;
width:100px;
height:75px;
display:block;
padding:20px;
}
.Tab1:hover{border:1px solid green;}
This is what you need, you first align the background to the centre of the box and then add a padding with the padding CSS, as you originally tried to do. The background-repeat property will stop the background repeating into the padding of the CSS.
Please also remember to add units to the padding value, just in case you had tried to do what you'd written as adding padding:20.
You can check here the space between image and border...
.Tab1{background-image:url("http://dl.dg-site.com/wp-content/themes/aeron/images/dl-products-icons5.jpg");
width:100px;
height:75px;
display:block;
padding:15px;
background-repeat:no-repeat;
background-position:center center;
border:1px solid #fff;
}
.Tab1:hover{border:1px solid green;}
<div class="Tab1">
</div>
thanks
css code
.Tab1 {
background:url("http://dl.dg-site.com/wp-content/themes/aeron/images/dl-products-icons5.jpg");
background-position:center;
background-repeat:no-repeat;
width:100px;
height:75px;
display:block;
padding:15px;
}
.Tab1:hover {
border:1px solid green;
margin-left:-1px;
margin-top:-1px;
}

Button center positioning

I have a problem with center positioning a button in a row in a table.I used width and margin but it don't work.Can you help me? Here's the code for that button(in css):
.subm {
position:relative;
width:130px;
margin-left:auto;
margin-right:auto;
background-image:url('background.bmp');
border:none;
color:white;
opacity:1;
height:25px;
outline:0 none;
box-shadow:1px 1px 2px black
}
.subm:hover {
background-image:none;
background-color:darkgray;
box-shadow:10px 10px 10px black
}
.subm:active {
color:black ;
font-weight:bold;
width:128px;
height:24px;
background-image:none;
background-color:dimgray;
}
simply try this
button{
height:20px;
width:100px;
position:relative;
top:50%;
left:50%;
}
for just horizontal alignment use either
button{
margin: 0 auto;
}
DEMO
To achieve this, I would use following code:
.subm {
position:absolute;
width:130px;
height:25px;
top: calc(50% - 13px); // 50% - 0.5 * height.
left: calc(50% - 65px); // 50% - 0.5 * width.
}
And for the parent:
position: relative;
You can see a working JSFiddle here
If you used width and margin: auto's and it's still not centering you may just need to add display: block to your .sumb class like so:
.subm {
display:block;
position:relative;
width:130px;
margin-left:auto;
margin-right:auto;
background-image:url('background.bmp');
border:none;
color:white;
opacity:1;
height:25px;
outline:0 none;
box-shadow:1px 1px 2px black
}
Demo: http://jsfiddle.net/re079odr/

Insert a line on a box CSS

I want to make that line crossing the square (image below) in css, could anyone help me?
img http://www.brainmotion.com.br/download/img.png
If i have a div like this:
<div class="abcd">
</div>
.a {border:1px solid;}
Thanks so much
You can try using CSS triangle trick to render 2 triangles, the first has border-color the same as the color you want, the second has border-color the same as the background-color of the div:
div {
width:49px;
height:49px;
border:1px solid black;
position:relative;
}
div:before {
content:'';
position:absolute;
width:0;
height:0;
top:-1px;
left:-1px;
border:25px solid transparent;
border-right:25px solid black;
border-bottom:25px solid black;
z-index:-3;
}
div:after {
position:absolute;
content:'';
width:0;
height:0;
top:1px;
left:1px;
border:24px solid transparent;
border-right:24px solid white;
border-bottom:24px solid white;
z-index:-2;
}
Here is the fiddle
Note that with this solution, you have to tweak it a little with trial and error method.
UPDATE: Another simple method is using linear-gradient to generate the diagonal dynamically for the background of the div like this:
div {
width:50px;
height:50px;
border:1px solid black;
position:relative;
text-align:center;
line-height:50px;
font-size:25px;
background:linear-gradient(to bottom right, white, white 48%, black 50%, white 52%, white);
}
Here is the updated fiddle
Yes, you could do this using transform: rotate(45deg); in combination with overflow: hidden on the parent <div>, but I would highly discourage that, as It would be a disaster in terms of browser compatibility. I would just use the image.
Here is an example (note: quick and sloppy) that I tested in chrome that works:
http://jsfiddle.net/97xsh/1/
here is one that achieves the same effect.
http://jsfiddle.net/j8USa/1/
.box{
width:40px;
height:40px;
border:1px #000 solid;
overflow:hidden;
position:relative;
text-align:center;
vertical-align:middle;
}
.strike{
position:absolute;
width:60px;
height:1px;
border-top:1px #000 solid;
margin-top:20px;
margin-left:-10px;
-webkit-transform:rotate(-45deg);
-moz-transform:rotate(-45deg);
transform:rotate(-45deg);
}
.box span{
vertical-align:middle;
font-size: 26pt;
color:red;
}

Making a rhombus shape using background images

I'm using the following test code to try create a rhombus type shape. The span is a standard oblong, and the 2 sides will make it appear as a rhombus
**********
* *
******
However, the before and after selectors don't seem to render anything. I'm not sure if I'm doing it wrong or if I'd just be better off positioning them absolutely.
Any ideas?
<style>
span {
width:50px;
height:20px;
color:white;
background-color:red;
padding:10px;
}
span:before {
background: url('left_side.png') left center no-repeat;
height:43px; width:22px;
}
span:after {
background: url('right_side.png') right center no-repeat;
height:43px; width:22px;
}
</style>
<html>
<body>
<span>
Some text goes here
</span>
</body>
</html>
#demo { border-top: 100px solid red;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
height: 0; width: 100px; }
do it without images why people made css3
Demo : http://jsfiddle.net/sahilpopli/dRyLg/
The content property is mandatory, even if left empty :
span:before {
content : "";
display:inline-block;
background: url('left_side.png') left center no-repeat;
height:43px; width:22px;
}
span:after {
content : "";
display:inline-block;
background: url('right_side.png') right center no-repeat;
height:43px; width:22px;
}
Edit : added display:inline-block; for dimension properties to actually work with span, see this example http://jsfiddle.net/3nvhb/
Try this:
span:before {
content: url('left_side.png');
height:43px; width:22px;
}
span:after {
content: url('right_side.png');
height:43px; width:22px;
}

Resources