I've noticed that there are slight visible breaks in the CSS border image when rotating. Is there a way to prevent this or another method to achieve the same solution?
.box {
margin: 150px;
width: 250px;
height: 250px;
background: lightGray;
border: 20px solid blue;
border-image: linear-gradient(to right, #3acfd5 0%, #3a4ed5 100%);
border-image-slice: 1;
transform: rotate(45deg);
display: flex;
align-items: center;
justify-content: center;
}
.r45 {
transform: rotate(-45deg);
color: red;
}
<div class="box">
<p class="r45">Hello</p>
</div>
Another method to achieve the same solution is using pseudo:after as shown in the below working example, hope it helps :)
.box {
margin: 150px;
width: 250px;
height: 250px;
background: linear-gradient(to right, #3acfd5 0%, #3a4ed5 100%);
transform: rotate(45deg);
display: flex;
align-items: center;
justify-content: center;
position: relative;
}
.box:after {
left: 20px;
right: 20px;
top: 20px;
bottom: 20px;
content: '';
background: lightGray;
position: absolute;
}
.r45 {
transform: rotate(-45deg);
color: red;
position: relative;
z-index: 1;
}
<div class="box">
<p class="r45">Hello</p>
</div>
You can use background and adjust background-clip and you will avoid the strange rendering of border
.box {
margin: 80px;
width: 250px;
height: 250px;
background:
linear-gradient(lightGray,lightGray) padding-box,
linear-gradient(to right, #3acfd5 0%, #3a4ed5 100%) border-box;
border: 20px solid transparent;
display: flex;
align-items: center;
justify-content: center;
transform: rotate(45deg);
}
.r45 {
transform: rotate(-45deg);
color: red;
}
<div class="box">
<p class="r45">Hello</p>
</div>
Related
I know there are many different ways to draw in CSS but I want to draw this shape using CSS ::before and ::after pseudo-elements.
Only the yellow part I could not draw it.
.body{
width:100%;
height:100%;
background:#191919;
display: flex;
justify-content: center;
align-items: center;
}
.circle {
position: relative;
width: 160px;
height: 160px;
background: #824B20;
border-radius: 50%;
}
.circle::before{
content: "";
width: 100px;
height: 100px;
background: #E08027;
position: absolute;
border-radius: 50%;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
.circle::after{
content:"";
/*color : #FFF58F */
}
<div class="body"><div class="circle";div><div><div>
An idea using only gradients:
.box {
width: 200px;
aspect-ratio:1;
border-radius: 50%;
background:
radial-gradient(circle at 78% 50%, yellow 4%,#0000 4.5%),
radial-gradient(circle at 22% 50%, yellow 4%,#0000 4.5%),
radial-gradient(at top,#0000 33%,yellow 34% 45%,#0000 46%)
bottom/100% 50% no-repeat,
radial-gradient(#E08027 40%,#824B20 41%);
}
<div class="box"></div>
.body {
width: 100%;
height: 100vh;
background: #191919;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
.circle {
box-sizing: border-box;
position: relative;
width: 160px;
height: 160px;
background: #E08027;
border: 30px solid #824B20;
border-radius: 50%;
}
.half-circle {
position: absolute;
width: 85px;
height: 85px;
border: 14px solid #FFF58F;
border-top-color: transparent;
border-left-color: transparent;
border-radius: 50%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) rotate(45deg);
}
.half-circle::before,
.half-circle::after {
content: "";
position: absolute;
top: 69px;
width: 14px;
height: 14px;
border-radius: 50%;
background: #FFF58F;
}
.half-circle::before {
left: 0;
}
.half-circle::after {
left: 71px;
transform: translate(-2px, -70px);
}
<div class="body">
<div class="circle">
<div class="half-circle"></div>
</div>
</div>
I did something like this for the level system. But I think I did something wrong because of my carelessness. As an example, I showed the number 10, but this number is 1-2-3, etc. it breaks down when we do. Can you help please
.box {
position: relative;
width: 50px;
height: 50px;
border-radius: 50%;
background: linear-gradient(40deg, #ffffff, #0c8a86 50%, #ffffff);
animation: rotate 12s linear infinite;
display: inline-grid;
top: 15px;
margin-left: 10px;
position: absolute;
}
.box:before,
.box:after {
content: " ";
position: absolute;
inset: 5px;
background: linear-gradient(#1c1734, #534770);
border-radius: inherit;
}
.box:before {
background: linear-gradient(45deg, #ffffff, #ffffff 40%, #ffffff);
filter: blur(8px);
}
#keyframes rotate {
100% {
transform: rotate(360deg);
/*filter: hue-rotate(360deg);*/
}
}
.circle-num {
color: white!important;
position: relative;
place-self: center!important;
display: inline-flex;
font-size: 25px!important;
top: 17.51px;
left: 21.5px;
}
<div class="box"></div>
<div class="circle-num">10</div>
i know I shouldn't do it with the position, but how would the solution to this be?
Set a container with relative to contain the elements inside so that you can set an absolute positioned element (for the numbering).
With a fixed width and height of 50px and some calculation on any existing margin/padding you can easily position your number with flex and align it vertical and horizontally centered with align-items and justify-content.
.container{
position: relative;
display: block;
}
.box {
position: relative;
width: 50px;
height: 50px;
border-radius: 50%;
background: linear-gradient(40deg, #ffffff, #0c8a86 50%, #ffffff);
animation: rotate 12s linear infinite;
display: inline-grid;
top: 15px;
margin-left: 10px;
position: absolute;
}
.box:before,
.box:after {
content: " ";
position: absolute;
inset: 5px;
background: linear-gradient(#1c1734, #534770);
border-radius: inherit;
}
.box:before {
background: linear-gradient(45deg, #ffffff, #ffffff 40%, #ffffff);
filter: blur(8px);
}
#keyframes rotate {
100% {
transform: rotate(360deg);
/*filter: hue-rotate(360deg);*/
}
}
.circle-num {
color: white !important;
position: absolute;
display: flex;
font-size: 25px !important;
width: 50px;
height: 50px;
text-align: center;
margin: 15px 10px;
top: 0px;
left: 0px;
align-items: center;
justify-content: center;
}
<div class="container">
<div class="box"></div>
<div class="circle-num">1</div>
</div>
I'm trying to achieve the shape as shown in this image:
To have 2 rectangle divs with cut corners , and 1 div positioned behind another div.
But the corners seems incorrect and I can't find the way to show the borders of the shapes.
.wrapper {
display: flex;
justify-content: center;
}
.connect {
width: 254px;
height: 50px;
background: red;
background: #FF2D5069;
border-top: 2px solid #FF2175;
position: absolute;
bottom: 0;
z-index: 5;
}
.connect::before {
content: '';
position: absolute;
bottom: 0;
right: -2px;
border-top: 52px solid white;
border-left: 42px solid transparent;
}
.connect::after {
content: '';
position: absolute;
bottom: 0;
left: -2px;
border-top: 52px solid white;
border-right: 42px solid transparent;
}
.connect-behind {
width: 300px;
height: 44px;
background: red;
background: #FF2D5069;
border-top: 2px solid #FF2175;
position: absolute;
bottom: 0;
}
.connect-behind::before {
content: '';
position: absolute;
bottom: 0;
right: -2px;
border-top: 46px solid white;
border-left: 26px solid transparent;
}
.connect-behind::after {
content: '';
position: absolute;
bottom: 0;
left: -2px;
border-top: 46px solid white;
border-right: 26px solid transparent;
}
<div class="wrapper">
<div class="connect"></div>
<div class="connect-behind"></div>
</div>
I took reference from other threads to use behind and after for the solution but it doesn't seem working correct for my problem. Please help, thanks.
You could use perspective and transform:
possible example (for infos : with grid instead absolute) :
.wrapper {
display: grid;
justify-content: center;
align-items: end;
height: 300px;
perspective: 50px;
}
.connect,
.connect-behind {
transform: rotatex(50deg);
background: red;
margin: 0 auto;
background: #FF2D5069;
border-top: 2px solid #FF2175;
grid-row: 1;
grid-column: 1;
transform-origin: bottom center;
}
.connect-behind {
width: 300px;
height: 44px;
}
.connect {
width: 254px;
height: 50px;
;
}
<div class="wrapper">
<div class="connect"></div>
<div class="connect-behind"></div>
</div>
to draw a border around the shape, drop-shadow could be usefull
.wrapper {
display: grid;
justify-content: center;
align-items: end;
height: 300px;
perspective: 50px;
filter:
drop-shadow( 1px 0px 0 )
drop-shadow(-1px 0px 0 )
drop-shadow( 0px 1px 0 )
drop-shadow( 0px -1px 0 );
}
.connect,
.connect-behind {
transform: rotatex(50deg);
background: red;
margin: 0 auto;
background:white;
grid-row: 1;
grid-column: 1;
transform-origin: bottom center;
background:#ffa500;
}
.connect-behind {
width: 254px;
height: 50px;
border-left:solid 2px;
border-right:solid 2px;
}
.connect {
background:#ed1c24;
width: 300px;
height: 44px;
;
}
<div class="wrapper">
<div class="connect"></div>
<div class="connect-behind"></div>
</div>
You can use clip-path for things like this. Works well in a ( I think ) most browsers. Some, like ie11 and older browsers won't render it correctly, though, so you may need a fallback for those cases.
body {
overflow: hidden;
}
.wrapper {
display: flex;
justify-content: center;
}
.connect {
width: 254px;
height: 80px;
background: red;
background: #FF2D5069;
border-top: 2px solid black;
position: absolute;
bottom: 0;
z-index: 5;
clip-path: polygon(20% 0%, 80% 0%, 100% 100%, 0% 100%);
}
.connect-border-left {
height: 80px;
width: 2px;
background: black;
left: calc(50% - 131px);
position: absolute;
bottom: -12px;
transform: rotate(34deg) translateX(-50%);
display: inline-block;
}
.connect-border-right {
height: 80px;
width: 2px;
background: black;
right: calc(50% - 131px);
position: absolute;
bottom: -12px;
transform: rotate(-34deg) translateX(-50%);
display: inline-block;
}
.connect-behind {
width: 300px;
height: 60px;
background: red;
background: #FF2D5069;
border-top: 2px solid black;
position: absolute;
bottom: 0;
clip-path: polygon(14% 0%, 86% 0%, 100% 100%, 0% 100%);
}
.connect-behind-border-right {
height: 100px;
width: 2px;
background: black;
right: calc(50% - 103px);
position: absolute;
bottom: -11px;
transform: rotate(-32deg) translateX(-50%);
display: inline-block;
}
.connect-behind-border-left {
height: 100px;
width: 2px;
background: black;
left: calc(50% - 103px);
position: absolute;
bottom: -11px;
transform: rotate(32deg) translateX(-50%);
display: inline-block;
}
<div class="wrapper">
<div class="connect"></div>
<div class="connect-border-left"></div>
<div class="connect-border-right"></div>
<div class="connect-behind"></div>
<div class="connect-behind-border-left"></div>
<div class="connect-behind-border-right"></div>
</div>
an idea with skew transformation, clip-path and multiple background:
.box {
--b:3px; /* border width */
--t:20px; /* top part width */
--s:30px; /* side part width */
margin:10px;
display:inline-block;
width:250px;
height:150px;
position:relative;
}
.box::before,
.box::after {
content:"";
position:absolute;
top:0;
bottom:0;
left:0;
width:50%;
border-style:solid;
border-width:var(--b) 0 0 var(--b);
background:
linear-gradient(black 0 0) 0 var(--t)/100% var(--b),
linear-gradient(black 0 0) var(--s) 0/var(--b) 100%,
linear-gradient(red 0 0) left/var(--s) 100%,
orange;
background-repeat:no-repeat;
transform-origin:bottom right;
transform:skew(-20deg);
clip-path:polygon(0 calc(var(--t) + var(--b)), calc(var(--s) + var(--b)) calc(var(--t) + var(--b)),calc(var(--s) + var(--b)) 0,60% 0,100% 100%,0 100%);
}
.box::after {
transform:scale(-1,1) skew(-20deg);
}
<div class="box"></div>
<div class="box" style="--b:2px;--t:30px;--s:15px;"></div>
I'm trying to get 4 circles within in each other (that don't have a background colour, just a border colour) with text inside the last one using CSS.
Example: http://imgur.com/a/5vUKI
Any idea on how this can be done?
Here you go. This should help you get started.
.circle {
border-radius: 50%;
background: transparent;
border: 2px solid red;
width: 500px;
height: 500px;
margin: 0 auto;
display: flex;
justify-content: center;
align-items: center;
}
.c2 {
width: 400px;
height: 400px;
border-color: blue;
}
.c3 {
width: 300px;
height: 300px;
border-color: yellow;
}
.c4 {
width: 200px;
height: 200px;
}
<div class="circles">
<div class="circle c1">
<div class="circle c2">
<div class="circle c3">
<div class="circle c4"></div>
</div>
</div>
</div>
</div>
It's a styling, so don't mess with inner HTML code. CSS Gradients can do this well. it's even animatable
.container {
display: inline-block;
height: 12em;
width: 12em;
padding: 4em;
text-align: center;
background: radial-gradient(circle closest-side,
hsla( 0, 80%, 80%, 0) 0%,
hsla( 0, 80%, 80%, 0) 78%,
hsla( 0, 80%, 80%, 1) 79%,
hsla( 0, 80%, 80%, 1) 82%,
hsla( 0, 80%, 80%, 0) 83%,
hsla(100, 80%, 80%, 0) 87%,
hsla(100, 80%, 80%, 1) 88%,
hsla(100, 80%, 80%, 0) 89%,
hsla(200, 80%, 80%, 0) 92%,
hsla(200, 80%, 80%, 1) 93%,
hsla(200, 80%, 80%, 0) 94%,
hsla(300, 80%, 80%, 0) 97%,
hsla(300, 80%, 80%, 1) 98%,
hsla(300, 80%, 80%, 0) 99%
)
;
}
<div class="container">
My inner text is here
</div>
Simply position all the circles on top of each other.
#outer-circle {
border: 1px solid red;
border-radius: 50%;
height: 500px;
width: 500px;
position: relative;
text-align: center;
}
#inner-circle {
position: absolute;
border: 1px solid red;
border-radius: 50%;
height: 480px;
width: 480px;
top: 50%;
left: 50%;
margin: -240px 0px 0px -240px;
}
#inner-circle2 {
position: absolute;
border: 1px solid red;
border-radius: 50%;
height: 460px;
width: 460px;
top: 50%;
left: 50%;
margin: -230px 0px 0px -230px;
}
#inner-circle3 {
position: absolute;
border: 1px solid red;
border-radius: 50%;
height: 440px;
width: 440px;
top: 50%;
left: 50%;
margin: -220px 0px 0px -220px;
}
#text {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-o-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
<div id="outer-circle">
<div id="inner-circle">
<div id="inner-circle2">
<div id="inner-circle3">
<div id="text">Breathe out</div>
</div>
</div>
</div>
</div>
Here's my version.
My logic was divided into 2 steps:
Step One :
The .circle-1 is set as relative to be the container of the child's div.
Step Two
The rest of the div's is set as absolute and has a smallest padding that their father, for their parent aways be bigger than the son.
The align in x-axis is set by the left and right as 0 and margin as 0 auto.
The align in y-axis is set by the top:50% and transform:translateY(-50%).
div{
position: absolute;
border: 3px solid;
border-radius: 50%;
width: 150px;
height: 150px;
left:0;
right:0;
top: 50%;
transform: translateY(-50%);
margin:0 auto;
}
.circle-1{
top: 200px;
padding: 40px;
position: relative;
}
.circle-2{
padding: 30px;
border-color: blue;
}
.circle-3{
padding: 20px;
}
.circle-4{
padding: 10px;
}
<div class="circle-1">
<div class="circle-2">
<div class="circle-3">
<div class="circle-4"></div>
</div>
</div>
</div>
Messing around with this as I procrastinated.
Vertically responsive, basic hover effect.
html, body {
display: flex;
justify-content: center;
height: 100vh;
margin: 0;
padding: 0;
background-color: gray;
}
div {
display: flex;
flex-grow: 1;
background-color: hsla(0, 0%, 0%, 0.0);
border-style: solid;
border-color: white;
border-width: 5px;
border-radius: 100%;
padding: 5px;
overflow: hidden;
transition: all 0.1s linear;
box-sizing: border-box;
}
.ring1 {
height: 100vh;
width: calc(100vh);
}
.ring2 {
border-color: royalblue;
}
.ring4 {
justify-content: center;
align-items: center;
text-align: center;
font-size: 28px;
font-variant: small-caps;
font-weight: bold;
color: royalblue;
background-color: salmon;
}
.ring1:hover, .ring1:hover div {
padding: 3px;
font-size: 32px;
border-width: 3px;
}
<div class="ring1">
<div class="ring2">
<div class="ring3">
<div class="ring4">
Breathe Out
</div>
</div>
</div>
</div>
fiddle
https://jsfiddle.net/Hastig/9v4mLdep/
How do I make half a hexagon shape with a border and over top a rectangle shape with a border and an image inside the half hexagon shape using CSS and HTML5
I have no code for this as I have tried but cannot figure out how to do it
I added an image of what I would like to be able to do.
You can create a trapezoid fairly easily with a rectangle and 2 CSS triangles made with some transparent borders using :before and :after.
Working Example:
body {
background: black;
}
.rectangle {
background: #ECECEC;
height: 20px;
}
.trapezoid {
width: 50px;
height: 50px;
position: relative;
margin: 0 auto;
background: #ECECEC;
}
.trapezoid:before,
.trapezoid:after {
content: '';
display: block;
position: absolute;
top: 0;
border: 25px solid transparent;
border-top-color: #ECECEC;
}
.trapezoid:before {
right: 100%;
border-right-color: #ECECEC;
}
.trapezoid:after {
left: 100%;
border-left-color: #ECECEC;
}
<div class="rectangle">
<div class="trapezoid"></div>
</div>
updated with shape and border-colors
div {
margin-top:1em;;
text-align: center;
padding: 0.5em;
border-top:1px solid lightgray;
background: linear-gradient(to bottom, #ECECEC 50%, lightgray 50%, lightgray 51%, transparent 52%);
}
img {
position: relative;
display: block;
margin: 10px auto;
z-index: 1;
}
span {
text-align: center;
display: inline-block;
width:320px;
position: relative;
overflow: hidden;
border-top:1px solid lightgray;
background: linear-gradient(to left, lightgray, lightgray) bottom center, linear-gradient(40deg, transparent 50px, lightgray, 50px, lightgray 52px, #ECECEC 52px)bottom left, linear-gradient(-40deg, transparent 50px, lightgray, 50px, lightgray 52px, #ECECEC 52px)bottom right;
background-repeat: no-repeat;
background-size: 50% 2px, 50% 100%, 50% 100%;
}
<div>
<span>
<img src="http://lorempixel.com/55/46/technics/1" alt="ico"/>
</span>
</div>
older codes
a single pseudo and overflow:hidden, can do it too:
div {
text-align: center;
padding: 0.5em;
background: linear-gradient(to bottom, gray 50%, black 50%);
}
img {
position: relative;
display: block;
padding: 0.5em 0;
z-index: 1;
}
span {
text-align: center;
display: inline-block;
padding: 0 3em;
position: relative;
overflow: hidden;
}
span:before {
position: absolute;
content: '';
bottom: 0;
left: 50%;
margin-left: -75px;
height: 150px;
width: 150px;
background: gray;
transform: rotate(45deg);
}
<div>
<span>
<img src="http://lorempixel.com/40/50/nature/3" alt="ico"/>
</span>
</div>
or a gradient (easier probably to draw borders or shadows if needed)
div {
text-align: center;
padding: 0.5em;
background: linear-gradient(to bottom, gray 50%, black 50%);
}
img {
position: relative;
display: block;
padding: 0.5em 0;
z-index: 1;
}
span {
text-align: center;
display: inline-block;
padding: 0 3em;
position: relative;
overflow: hidden;
background: linear-gradient(40deg, transparent 1.5em, gray 1.5em)bottom left, linear-gradient(-40deg, transparent 1.5em, gray 1.5em)bottom right;
background-repeat: no-repeat;
background-size: 50% 100%;
}
<div>
<span>
<img src="http://lorempixel.com/40/50/nature/3" alt="ico"/>
</span>
</div>
Here is a solution using pseudo elements with skew. The image can be overlayed without problems
.rect {
width: 100%;
height: 20px;
background-color: lightgrey;
border-bottom: 1px solid grey;
position: relative;
}
.hex {
width: 200px;
height: 40px;
position: absolute;
left: 50%;
transform: translateX(-50%);
}
.hex:before, .hex:after {
content: "";
position: absolute;
width: 200px;
height: 40px;
border-style: solid;
border-color: grey;
border-width: 0px 0px 1px 0px;
transform-origin: bottom center;
background-color: lightgrey;
}
.hex:before {
transform: skew(10deg);
border-left-width: 1px;
}
.hex:after {
transform: skew(-10deg);
border-right-width: 1px;
}
<div class="rect">
<div class="hex"></div>
</div>
You can create half octagon using :after.
.halfOctagon {
width: 100px;
height: 50px;
background: #f35916;
position: relative;
top:25px;
left:50px;
}
.halfOctagon:after {
content: "";
position: absolute;
bottom: 0;
left: 0;
border-top: 29px solid #f35916;
border-left: 29px solid #eee;
border-right: 29px solid #eee;
width: 42px;
height: 0;
}
you can try live example in https://jsfiddle.net/kb2tzxq4/
To move the half octagon adjust top and left in css for .halfOctagon