How to make a border overlay child div? - html

I have to make a border overlay it's content to match the looking of this image:
And I got the big picture of it:
And I need to make that border overlay the green content. How can I accomplish it? I can't use z-index for this, as I researched. The HTML and CSS code follows:
.box-border a {
color: white;
text-transform: uppercase;
font-weight: bold;
font-size: 16px;
}
.box-border a:hover {
text-decoration: none;
color: white;
cursor: pointer;
}
.box-border-participe {
position: relative;
float: right;
margin-right: 30%;
border: 4px solid white;
}
.box-participe {
background-color: #94C120;
padding: 10px 40px;
margin-left: 5px;
margin-top: 5px;
margin-bottom: -20px;
margin-right: -20px;
}
body {
background:grey;
}
<div class="box-border box-border-participe">
<div class="box-participe">
<a>Participe</a>
</div>
</div>

You can consider the use of pseudo element to create the border and avoid extra markup. You can also easily control its position/size:
body {
background: grey;
}
.button {
background: #94c120;
width: 200px;
height: 50px;
margin: 50px;
position: relative;
}
.button:before {
content: "";
position: absolute;
top: -15px;
left: -15px;
width: 100%;
height: 100%;
border: 5px solid #fff;
box-sizing: border-box;
}
<div class="button">
some text
</div>
Here is also another idea using linear-gradient and multiple background:
body {
background:grey;
}
.button {
width: 200px;
height: 80px;
margin: 50px;
padding:20px 0 0 20px;
box-sizing:border-box;
background:
linear-gradient(to right,#fff 5px,transparent 5px calc(100% - 5px),#fff calc(100% - 5px)) 0 0/ calc(100% - 10px) calc(100% - 10px),
linear-gradient(to bottom,#fff 5px,transparent 5px calc(100% - 5px),#fff calc(100% - 5px)) 0 0/ calc(100% - 10px) calc(100% - 10px),
linear-gradient(#94c120,#94c120) 15px 15px;
background-repeat:no-repeat;
}
<div class="button">
some text
</div>
Another syntax with gradient:
body {
background:grey;
}
.button {
width: 200px;
height: 80px;
margin: 50px;
padding:20px 0 0 20px;
box-sizing:border-box;
background:
linear-gradient(#fff,#fff) left -10px top 0 /100% 5px,
linear-gradient(#fff,#fff) top -10px left 0 /5px 100%,
linear-gradient(#fff,#fff) left -10px bottom 10px/100% 5px,
linear-gradient(#fff,#fff) top -10px right 10px/5px 100%,
linear-gradient(#94c120,#94c120) 20px 20px;
background-repeat:no-repeat;
}
<div class="button">
some text
</div>
Another idea using background and box-shadow:
body {
background:grey;
}
.button {
width: 200px;
height: 80px;
margin: 50px;
padding:15px 0 0 15px;
box-sizing:border-box;
background: #94c120 content-box;
border:5px solid #fff;
box-shadow: 20px 20px 0px #94c120; /* value of padding + border*/
}
<div class="button">
some text
</div>

Related

making the border for the radial gradient also

How can i make the border to apply for the radial gradient so that the dotted line will apply for the curve at left and right not as a straight line
.container {
width: 160px;
height: 58px;
border: 1px dotted red;
background: radial-gradient(15px at left, #fff 98%, red) left,
radial-gradient(15px at right, #fff 98%, red) right;
background-size: 51% 100%;
background-repeat: no-repeat;
}
<div class='container'>
</div>
I played around with your code and here is what I came up with. This is a tricky one but it works. I added 2 half circle then hide them. I don't know where are you going to use this but an image will be a good idea as well for this.
.container {
width: 160px;
height: 58px;
border: 1px dotted red;
background: radial-gradient(15px at left, #fff 98%, red) left,
radial-gradient(15px at right, #fff 98%, red) right;
background-size: 51% 100%;
background-repeat: no-repeat;
}
.half-circle-left, .half-circle-right {
width: 30px;
height: 30px;
z-index:1;
background-color: white;
vertical-align:middle;
margin-top:8%;
overflow: overlay;
}
.half-circle-left {
float: left;
margin-left: -15px;
overflow: hidden;
border-radius: 0px 15px 15px 0px;
border-right: 1px dotted red;
}
.half-circle-right {
float:right;
margin-right: -15px;
border-radius: 15px 0px 0px 15px;
border-left: 1px dotted red;
}
<div class='container'>
<div class="half-circle-left">
</div>
<div class="half-circle-right">
</div>
MY TEXT HERE! Please put more text here
</div>
As I know it is not possible, instead of using a dotted border you can use box-shadow to act like a solid border and use a pseudo-elements :after :before to draw the circle in both sides.
Here is the code:
<div class='container'>
</div>
.container {
position: relative;
overflow: hidden;
width: 160px;
height: 58px;
background: red;
box-shadow: inset 0 0 0 2px #000;
}
.container: after, .container:before {
content: '';
position: absolute;
inset-inline-start: 0;
width: 30px;
aspect-ratio: 1;
background: #ffffff;
border-radius: 100%;
inset-block-start: 50%;
transform: translateY(-50%) translateX(-50%);
box-shadow: inset 0 0 0 2px #000;
}
.container: before {
inset-inline: auto 0;
transform: translateY(-50%) translateX(50%);
}

Using background-clip on a gradient overlay

What I'm trying to achieve:
Both elements (the arrow container + full width bar) share the same gradient. What I've tried is to make both elements separately and just apply the gradient to both of them, but for obvious reasons it looks clipped:
Codepen: https://codepen.io/sigurdmazanti/pen/bGarpvJ
Snippet:
.container {
background: white;
width: 100%;
height: 71px;
}
.arrow-container {
height: 34px;
width: 118px;
border-radius: 15px 15px 0 0;
text-align: center;
margin: 0 auto;
color: white;
background: transparent linear-gradient(180deg, #415fb4 0%, #0e2460 100%) 0 0 no-repeat padding-box;
}
.bar {
height: 37px;
background: transparent linear-gradient(180deg, #415fb4 0%, #0e2460 100%) 0 0 no-repeat padding-box;
}
<div class="container">
<div class="arrow-container">↑</div>
<div class="bar"></div>
</div>
I then got the idea of using a full width + full height overlay with the gradient, and then using background-clip to clip the two elements, so they both share the gradient. But I'm struggling a bit with it, and it seems like I'm using it the wrong way around.
Codepen: https://codepen.io/sigurdmazanti/pen/popryWz
Snippet:
.container {
overflow: hidden;
background: white;
width: 100%;
height: 71px;
}
.bg-gradient {
background: transparent linear-gradient(180deg, #415fb4 0%, #0e2460 100%) 0 0 no-repeat padding-box;
background-clip: content-box;
width: 100%;
height: 100%;
}
.arrow-container {
height: 34px;
width: 118px;
border-radius: 15px 15px 0 0;
text-align: center;
margin: 0 auto;
background-color: red;
}
.bar {
height: 37px;
background-color: red;
}
<div class="container">
<div class="bg-gradient">
<div class="arrow-container">↑</div>
<div class="bar"></div>
</div>
</div>
I cannot use ::after & ::before pseudo-elements, they need to be two separate elements as the arrow-element needs an eventhandler.
Am I on the right path, or is this even achievable?
Thank you!
Make the height of the gradient equal to the sum of both element then control the size:
.container {
background: white;
height: 71px;
}
.arrow-container {
height: 34px;
width: 118px;
border-radius: 15px 15px 0 0;
text-align: center;
margin: 0 auto;
color: white;
background:
linear-gradient(180deg, #415fb4 0%, #0e2460 100%) top/100% 71px;
}
.bar {
height: 37px;
background:
linear-gradient(180deg, #415fb4 0%, #0e2460 100%) bottom/100% 71px;
}
<div class="container">
<div class="arrow-container">↑</div>
<div class="bar"></div>
</div>
Or do it like below using pseudo element:
.container {
background: white;
height: 71px;
position:relative; /* relative here */
z-index: 0;
}
.arrow-container {
height: 34px;
width: 118px;
border-radius: 15px 15px 0 0;
text-align: center;
margin: 0 auto;
color: white;
}
.bar {
height: 37px;
}
.arrow-container,
.bar {
-webkit-mask:linear-gradient(#000 0 0); /* clip the gradient to the element area */
}
/* your gradient here */
.arrow-container:before,
.bar:before {
content:"";
position:absolute;
inset:0;
background: linear-gradient(180deg, #415fb4 0%, #0e2460 100%);
z-index:-1;
}
<div class="container">
<div class="arrow-container">↑</div>
<div class="bar"></div>
</div>

CSS-only ribbon with skewed bottom corner

What i'm trying to achieve is to create a purely-CSS ribbon which will:
adapt to the included text (working),
floated to the left of container (working),
have a skewed bottom right corner like on below img:
This is my code - HTML:
<div class="container">
<div class="ribbon left_ribbon"><h2>Testing</h2></div>
</div>
and CSS:
.container {
width:80%;
background:grey;
display:block;
min-height:500px;
margin:0 auto;
}
.ribbon{
color: #fff;
margin: 30px 0 50px;
position: relative;
text-transform: uppercase;
background: rgb(0, 164, 239);
box-shadow: 0px 1px 3px rgba(0,0,0,.2);
padding: 10px 15px;
clear: both;
}
div.left_ribbon{
color: #000;
margin-left: -10px;
float: left;
}
div.left_ribbon h2{
margin: 0 12px;
color:#fff;
}
div.left_ribbon::before{
display: block;
width: 10px;
height: 0px;
position: absolute;
bottom: -10px;
left: -10px;
content: "";
border-bottom: 10px solid transparent;
border-right: 10px solid rgb(0, 80, 116);
}
is it doable via CSS or I have to use SVG file?
clip-path can do it easily:
.box {
width:200px;
height:100px;
margin:50px;
position:relative;
background:grey;
}
.box:before {
content:"Ribbon";
font-size:25px;
padding:5px 25px 10px;
position:absolute;
top:10px;
left:-5px;
background:
linear-gradient(#000 0 0) bottom/100% 5px no-repeat
#00a4ef;
clip-path:polygon(0 0,100% 0,80% calc(100% - 5px),5px calc(100% - 5px),5px 100%,0 calc(100% - 5px))
}
<div class="box">
</div>
With some CSS variables to easily control:
.box {
--s:10px; /* skewed part */
--o:5px; /* offset part */
--c:#00a4ef; /* color */
width:200px;
height:100px;
display:inline-block;
margin:5px;
position:relative;
background:grey;
}
.box:before {
content:attr(data-text);
font-size:25px;
padding:5px calc(10px + var(--s)) calc(5px + var(--o)) calc(10px + var(--o));
position:absolute;
top:10px;
left:calc(-1*var(--o));
background:
linear-gradient(#000 0 0) bottom/100% var(--o) no-repeat
var(--c);
clip-path:polygon(0 0,100% 0,calc(100% - var(--s)) calc(100% - var(--o)),var(--o) calc(100% - var(--o)),var(--o) 100%,0 calc(100% - var(--o)))
}
<div class="box" data-text="test"></div>
<div class="box" data-text="another test" style="--c:red;--o:10px;--s:25px"></div>
<div class="box" data-text="another one" style="--c:yellow;--o:0px;--s:40px"></div>
Please modify your CSS as below. pseudo after CSS added making it skewed form bottom right corner and, modified box-shadow from .ribbon for removing visible shadow of skewed area.
.container {
width:80%;
background:grey;
display:block;
min-height:500px;
margin:0 auto;
}
.ribbon{
color: #fff;
margin: 30px 0 50px;
position: relative;
text-transform: uppercase;
background: rgb(0, 164, 239);
box-shadow: 0px 1px 3px rgb(0 0 0 / 0%);
padding: 10px 15px;
clear: both;
}
div.left_ribbon{
color: #000;
margin-left: -10px;
float: left;
}
div.left_ribbon h2{
margin: 0 12px;
color:#fff;
}
div.left_ribbon::before{
display: block;
width: 10px;
height: 0px;
position: absolute;
bottom: -10px;
left: -10px;
content: "";
border-bottom: 10px solid transparent;
border-right: 10px solid rgb(0, 80, 116);
}
div.left_ribbon::after{
content: '';
position: absolute;
top: 0;
right: 0;
border-bottom: 47px solid grey;
border-left: 23px solid rgb(0, 164, 239);
width: 0;
}
<div class="container">
<div class="ribbon left_ribbon"><h2>Testing</h2></div>
</div>

How to create a full width triangle at the bottom?

I want just to do that:
However I have a lot of troubles to do it with css... Someone can help me?
This is my better try:
.flag.vertical {
background-color: #dd7758;
height: 0;
padding-bottom: 25px;
text-align: center;
color: white;
border-style: solid;
border-width: 0 10px 10px 10px;
border-color: transparent transparent white transparent;
}
<div class="flag-wrapper"><span class="flag vertical">-5%</span></div>
My doubts are about to make this white triangle on the bottom. Doesn't matter here the vertical align of the text and the font family.
Set the width to 0
.flag-wrapper{ background-color: #dd7758;
height: 0;
padding-bottom: 25px;
text-align: center;
color: white;
border-style: solid;
border-width: 20px 20px 20px 20px;
border-color: transparent transparent white transparent;
width: 0;
}
span{
margin-left:-10px
}
<div class="flag-wrapper"><span>-5%</span></div>
You can user after element for a triangle
Edit: You can use clip-path to make a shape as you want
This also solves your Another question that maybe do you know. If I want to add this div over an image, is it possible that the triangle will be transparent instead of white? comment
.flag.vertical {
background-color: #dd7758;
padding: 10px 10px 25px;
text-align: center;
color: white;
display: inline-block;
clip-path: polygon(0% 0%, 100% 0%, 100% 100%, 50% 70%, 0% 100%);
}
<div class="flag-wrapper"><span class="flag vertical">-5%</span></div>
Here is an idea with gradient where it will be responsive and you will have better support than clip path:
.flag-wrapper {
background-color: #dd7758;
padding:10px 5px 30px;
margin:10px;
text-align: center;
color: white;
display:inline-block;
background:
linear-gradient(to top left,transparent 48%,#dd7758 50%) bottom left/50% 15px,
linear-gradient(to top right,transparent 48%,#dd7758 50%) bottom right/50% 15px,
linear-gradient(#dd7758,#dd7758)top/100% calc(100% - 15px);
background-repeat:no-repeat;
}
body {
background:#ccc;
}
<div class="flag-wrapper">-5%</div>
<div class="flag-wrapper">-25%</div>
<div class="flag-wrapper">-100%</div>
You can also make it working with image as background but you lose transparency:
.flag-wrapper {
background-color: #dd7758;
padding:10px 5px 30px;
margin:10px;
text-align: center;
color: white;
display:inline-block;
background:
linear-gradient(to bottom right,transparent 48%,#ccc 50%) bottom left/50.1% 15px,
linear-gradient(to bottom left,transparent 48%,#ccc 50%) bottom right/50.1% 15px,
url(https://picsum.photos/200/300?image=1069)center/cover;
background-repeat:no-repeat;
}
body {
background:#ccc;
}
<div class="flag-wrapper">-5%</div>
<div class="flag-wrapper">-25%</div>
<div class="flag-wrapper">-100%</div>
Use the following code, you'll also be able to add enough content in your div
* {
box-sizing: border-box;
}
.flag {
width: 110px;
height: 56px;
margin: 0 auto;
padding-top: 15px;
position: relative;
background: hotpink;
color: white;
font-size: 11px;
letter-spacing: 0.2em;
text-align: center;
text-transform: uppercase;
}
.flag:after {
content: ' ';
position: absolute;
left: 0;
bottom: 0;
width: 0;
height: 0;
border-bottom: 13px solid white;
border-left: 55px solid transparent;
border-right: 55px solid transparent;
}
<div class="flag">
5 Items
</div>
You may hide bottom triangle with another div
HTML:
<div class="flag-wrapper">
-5%
<div class="pointer">
</div></div>
CSS:
.flag-wrapper{
text-align: center;
padding-top: 10px;
background-color: #dd7758;
width:50px;
height:65px;
}
.pointer{
content: ' ';
position: absolute;
width: 45px;
height: 45px;
left: 10px;
top: 54.5px;
background-color: #fcfcfc;
transform: rotate(45deg) skew(5deg, 5deg);
-moz-transform: rotate(45deg) skew(5deg, 5deg);
-ms-transform: rotate(45deg) skew(5deg, 5deg);
-o-transform: rotate(45deg) skew(5deg, 5deg);
-webkit-transform: rotate(45deg) skew(5deg, 5deg);
}

Background outside CSS Bottom Border

first question here so please be kind! I am designing a website and I've been asked to frame pictures in sine-like borders. So far I've gotten around to it by creating a container div with 3 divs: the first for the downward bend, the second is just straight (I'm considering the idea of removing it later on) and the third one does the upward bend.
Here's a screenshot of the current state
So this is the the current code:
.border {
overflow: hidden;
align-items: center;
height: auto;
width: 100%;
display: flex;
}
.bord1 {
margin-top: 4vh;
height: 4vh;
flex: 1;
border-top: solid 5px;
border-color: #e4ae03 rgba(0, 0, 0, 0) transparent transparent;
border-radius: 100% 0 0 0;
z-index: 999;
}
.bord2 {
margin-top: 4vh;
flex: 1;
display: inline;
height: 4vh;
border-top: 5px solid #e4ae03;
}
.bord3 {
margin-top: -4vh;
flex: 1;
height: 4vh;
display: block;
border-bottom: 5px solid;
border-color: transparent transparent #e4ae03 transparent;
border-radius: 0 0 100% 0;
}
<div class="border">
<div class="bord1 top top-bord"></div>
<div class="bord2 top top-bord"></div>
<div class="bord3 bottom"></div>
</div>
I'm really trying to figure out how to get the last segment white, as it's created by rounding the bottom right corner, so the white background would have to be "outside" the div.
I know this might be a stupid question, but here it is! Thanks!
*Edit: Sorry everyone, here is an image of what I'm trying to do]2
It would need minor adjustments to the spacing, but something along these lines? (I used black/white backgrounds to show the sections, but these could be swapped or even made transparent.
body{background-color:black;}
.border{
overflow: hidden;
align-items: center;
height: auto;
width: 100%;
display: flex;
background-color:white;
}
.bord1{
margin-top: 4vh;
height: 4vh;
flex:1;
border-top: solid 5px;
border-color:#e4ae03 rgba(0,0,0,0) transparent transparent;
border-radius: 100% 0 0 0;
z-index: 999;
background-color:black;
}
.bord2 {
margin-top: 4vh;
flex: 1;
display: inline;
height: 4vh;
border-top: 5px solid #e4ae03;
background-color:black;
}
.bord3{
border-bottom: 5px solid;
border-color: transparent transparent #e4ae03 transparent;
border-radius: 0 0 100% 0;
background-color:white;
height:4vh;
}
.bord3-layer{
flex: 1;
height: 9vh;
display: block;
background-color:black;
}
<!DOCTYPE html>
<HTML>
<head>
<style>
</style>
</head>
<body>
<div class="border">
<div class="bord1 top top-bord"></div>
<div class="bord2 top top-bord"></div>
<div class="bord3-layer">
<div class="bord3 bottom"></div>
</div>
</div>
</body>
</HTML>
Ok, in the end I was able to fix the layout using a system of inner divs, here is how I handled it:
.container {
line-height: 1.5rem;
margin-top: -5vh;
padding: 0px 0px 0px;
padding-top: 5vh;
padding-bottom: 0px;
z-index: 0;
color: #b3b5b3;
background: -webkit-linear-gradient(left, #1b2716, #000000 80%);
background: -o-linear-gradient(left, #1b2716, #000000 80%);
background: -moz-linear-gradient(left, #1b2716, #000000 80%);
background: linear-gradient(left, #1b2716, #000000 80%);
min-height: 75vh;
}
.top {
box-shadow: inset 0 6px 0 0px #243c51;
}
.bottom {
box-shadow: 0 6px 0 0px #243c51;
}
.border{
overflow: hidden;
align-items: center;
height: auto;
width: 100%;
display: flex;
}
.bord1{
margin-top: 4vh;
height: 4vh;
flex:1;
border-top: solid 5px;
border-color:#e4ae03 rgba(0,0,0,0) transparent transparent;
border-radius: 100% 0 0 0;
z-index: 999;
}
.bord1-bot{
background: white;
}
.bord2 {
margin-top: 4vh;
flex: 1;
display: inline;
height: 4vh;
border-top: 5px solid #e4ae03;
}
.bord2-bot {
background: white;
margin-bottom: 4vh;
flex: 1;
display: inline;
height: 4vh;
border-bottom: 5px solid #e4ae03;
}
.bord3{
flex: 1;
height: 4vh;
display: block;
border-bottom: 5px solid;
border-color: transparent transparent #e4ae03 transparent;
border-radius: 0 0 100% 0;
}
.bord3-top {
margin-top: 0vh;
background: black;
}
.bord3-bot {
margin-top: 0vh;
background: white;
}
.bord3-bottom {
background: white;
}
.bord3-layer-top{
flex:1;
height: 8.5vh;
display: block;
background-color: white;
}
.bord3-layer-bot{
flex:1;
height: 8.5vh;
display: block;
}
.bord1-layer-top{
flex:1;
height: 8.5vh;
display: block;
background-color: white;
}
.bot-bord {
background: -webkit-linear-gradient(left, #1b2716, #000000 240%);
}
.text-con {
padding: 2vw;
z-index: 2;
}
.image-within {
display: block;
background: yellow;
height: 200px;
z-index: 10;
}
.top-bord {
background: white;
}
<div class="container">
<div class="border">
<div class="bord1 top top-bord"></div>
<div class="bord2 top top-bord"></div>
<div class="bord3-layer-top">
<div class="bord3 bottom bord3-top"></div>
</div>
</div>
<div class="image-within">
</div>
<div class="border">
<div class="bord1-layer-top"><div class="bord1 top bot-bord"></div></div>
<div class="bord2-bot bottom"></div>
<div class="bord3-layer-bot">
<div class="bord3 bottom bord3-bot"></div>
</div>
</div>
</div>
The CSS is really messy at the moment, so I'll have to clean it up a bit and work on keeping all the items constantly aligned, but it's looking pretty good right now! Thanks LegendaryJLD!