create shapes with css - html

.shape {
width: 200px;
height: 50px;
background-color: green;
border-radius: 10px 10px 0 30px;
transform: skewX(0);
}
<div class="shape">Hello World!</div>
We have two following shapes in jpg format. But on certain condition background and border color needs to change to some different color. So idea is to create those images with CSS transform Property (if possible).
{ width: 200px;
height: 50px;
background-color: green;
border-radius: 10px 10px 0 30px;
transform: skewX(0);
}

Using SVG
.a {
fill: #ef0c4d;
stroke: #999;
stroke-miterlimit: 10;
stroke-width: 7px;
}
.a:hover {
fill: green;
stroke: blue;
}
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 680.4 240.3">
<path class="a" d="M135,113.1s7.7,123.6,13.5,164.4c6.3,44.5,13,64,168,64h490L737.7,184.3a5.6,5.6,0,0,0-4.2-3.2L140.1,108.2A4.5,4.5,0,0,0,135,113.1Z" transform="translate(-131.4 -104.7)"/>
</svg>
Using CSS
.rect {
width: 230px;
height: 100px;
overflow: hidden;
position: relative;
}
.rect:before {
content: " ";
position: absolute;
width: 200px;
height: 50px;
background: #dedede;
border-bottom-left-radius: 26px;
right: 30px;
bottom: 0;
}
.rect:after {
content: " ";
position: absolute;
width: 250px;
height: 50px;
background: #dedede;
transform: rotate(10deg) skew(30deg);
bottom: 20px;
left: -38px;
}
<div class="rect"></div>

It will be easier to go with SVG than pure CSS, here is an example:
path {
fill:pink;
}
path:hover {
fill:red;
stroke:#000;
}
<svg
xmlns='http://www.w3.org/2000/svg'
viewBox='0 0 64 64'
width='200' >
<path d='M18 48 L56 48 L46 30 L12 16 C8 14 8 16 8 18 L8 40 C8 44 10 48 14 48 Z' />
</svg>
You may consider this link to easily adjust the shape http://jxnblk.com/paths/?d=M18 48 L56 48 L46 30 L12 16 C8 14 8 16 8 18 L8 40 C8 44 10 48 14 48 Z

What are the 'certain conditions'? If you wanted to change the image color on hover with pure CSS an easy way would be to set the image as a background of a div element. You would then create a second identical image (with new color) to change to.
HTML -
<div id="color-1"></div>
and the CSS
#color-1 {
width:500px;
height:200px;
background-image:url('some/image/path');
}
#color-1:hover {
background-image:url('some-other/image/path');
}

Related

How to create a Cross Curved Box using div [duplicate]

This question already has answers here:
'Inverted' border-radius possible? [duplicate]
(3 answers)
Closed 2 months ago.
I want to create a box like this:
It's not looking like that curved. I tried but don't know how to make it. Please help me with some solutions.
.test {
width: 300px;
height: 50px;
background-color: #EFB046;
border-radius: 20px;
display: flex;
justify-content: center;
align-items: center;
}
<div class="test"></div>
You can use gradient like below:
.box {
--r: 40px; /* control the curvature*/
--g: #0000 98%,#EFB046; /* the color here */
width: 250px;
height: 80px;
background:
radial-gradient(var(--r) 100% at var(--r) 0 ,var(--g)) calc(-1*var(--r)) 0,
radial-gradient(var(--r) 100% at var(--r) 100%,var(--g)) calc(-1*var(--r)) 100%;
background-size: 100% 50%;
background-repeat: repeat-x;
}
body {
background: #000;
}
<div class="box"></div>
The trick is used ::before and ::after. In my code you can add border-radius in the CSS.
.pointed {
position: relative;
width:200px;
height:40px;
margin-left:40px;
color:#FFFFFF;
background-color:#c08457;
text-align:center;
line-height:40px;
}
.pointed:before {
content:"";
position: absolute;
right: 100%;
top:0px;
width:0px;
height:0px;
border-top:20px solid transparent;
border-right:40px solid #8d4e24;
border-bottom:20px solid transparent;
}
.pointed:after {
content:"";
position: absolute;
left: 100%;
top:0px;
width:0px;
height:0px;
border-top:20px solid transparent;
border-left:40px solid #8d4e24;
border-bottom:20px solid transparent;
}
<div class="pointed"> Text Content </div>
This question here details what you are requesting
Please Read it and its various answers.
In short it looks like there are 2 approaches.
One is to create 4 elements to block out the content of the main element, the downside to this approach is you will not be able to see any content underneath it incase there is any
The second would be to create an SVG to put in a path element. This would allow you to create the cutout you are looking for. an example could look like as such
Shown below are the HTML and CSS for the 2 possible solutions. Note the path was drawn poorly using a free SVG editor but gives the general idea of what can be done
HTML
<div id="four-element">
<p class="SpanText">Hello World</p>
<div class="top left"></div>
<div class="top right"></div>
<div class="bottom left"></div>
<div class="bottom right"></div>
</div>
<div id="svg">
<svg width="100%" height="270px" \>
<path d="M 52 20 C 53 75 10 135 0 135 C 10 135 55 142 57 272 L 268 270 C 269 180 267 163 304 145 C 266 134 246 62 245 19 L 52 20 Z" fill="blue"/>
<text x="145" y="145" text-anchor="middle" alignment-baseline="middle">
Hello World
</text>
</svg>
</div>
CSS
#four-element {
margin: 40px;
height: 100px;
width: 100px;
background-color: #004C80;
position: relative;
overflow: hidden;
}
#four-element div {
position: absolute;
width: 20px;
height: 20px;
border-radius: 100%;
background-color: #FFFFFF;
}
.SpanText{
position: absolute;
top: 25%;
left: 25%;
}
.top { top: -10px; }
.bottom { bottom: -10px; }
.left { left: -10px; }
.right { right: -10px; }

how do style an achor tag active state wrapped around an image tag

I want to code the active state of the anchor tag to change the overlay class opacity to 1.
I am only able to do that using the :hover pseudo with the image to achieve this. Once try to use the link (anchor tag) in styling the image doesn't appears as a link anymore.
.card{
order: -1;
justify-content: center;
position: relative;
}
.card > a{
display: block;
position: relative;
}
.card a img{
display: block;
max-width: 100%;
width: 90%;
height: 50%;
border-radius: 20px;
/* align-self: center; */ /* centert the image cross-wise (horizontally) */
padding: 12px;
/* margin-top: 12px;*/
}
.overlay {
position: absolute;
top: 12px;
bottom: 12;
left: 12px;
right: 12;
height: 92%;
width: 90%;
opacity: 0;
transition: .5s ease;
background-color: #00FFF8;
border-radius: 13px;
}
.card > a:active .overlay{
opacity: 0.6;
}
<body>
<section id="card_details">
<h1>Equilibruim #3429</h1>
<p>Our Equilibruim collections promotes balance and calm.</p>
<div class="card">
<img src="images/nft.jpg" alt="" class="image">
<div class="overlay">
<div class="eye">
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48"><g fill="none" fill-rule="evenodd"><path d="M0 0h48v48H0z"/><path d="M24 9C14 9 5.46 15.22 2 24c3.46 8.78 12 15 22 15 10.01 0 18.54-6.22 22-15-3.46-8.78-11.99-15-22-15Zm0 25c-5.52 0-10-4.48-10-10s4.48-10 10-10 10 4.48 10 10-4.48 10-10 10Zm0-16c-3.31 0-6 2.69-6 6s2.69 6 6 6 6-2.69 6-6-2.69-6-6-6Z" fill="#FFF" fill-rule="nonzero"/></g></svg>
</div>
</div>
</div>
The only way I'm getting the overlay to work is with this css below;
.card:hover .overlay{
opacity: 0.6;
}
Below is the live link for the outcome
Your active state css doesn't work since .overlay is not a child of .cardlink.
.card{
order: -1;
justify-content: center;
position: relative;
max-width:25%;
}
.card > a{
display: block;
position: relative;
}
.card a img{
display: block;
max-width: 100%;
width: 90%;
height: 50%;
border-radius: 20px;
/* align-self: center; */ /* centert the image cross-wise (horizontally) */
padding: 12px;
/* margin-top: 12px;*/
}
.overlay {
position: absolute;
top: 12px;
bottom: 12;
left: 12px;
right: 12;
height: 92%;
width: 90%;
opacity: 0;
transition: .5s ease;
background-color: #00FFF8;
border-radius: 13px;
}
.card > a:active+.overlay{
opacity: 0.6;
}
.overlay{
user-select:none;
pointer-events: none;
}
<div class="card">
<div class="overlay">
<div class="eye">
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48">
<g fill="none" fill-rule="evenodd">
<path d="M0 0h48v48H0z" />
<path d="M24 9C14 9 5.46 15.22 2 24c3.46 8.78 12 15 22 15 10.01 0 18.54-6.22 22-15-3.46-8.78-11.99-15-22-15Zm0 25c-5.52 0-10-4.48-10-10s4.48-10 10-10 10 4.48 10 10-4.48 10-10 10Zm0-16c-3.31 0-6 2.69-6 6s2.69 6 6 6 6-2.69 6-6-2.69-6-6-6Z" fill="#FFF" fill-rule="nonzero" />
</g>
</svg>
</div>
</div>
</div>
You will also need to disable pointer events on the overlay element – otherwise you won't get any focus on your <a> element.
.card > a:active+.overlay{
opacity: 0.6;
}
.overlay{
user-select:none;
pointer-events: none;
}

How to design a image through css [duplicate]

This question already has answers here:
Wave (or shape?) with border on CSS3
(5 answers)
Closed 6 years ago.
How to design This Image
I want to design this type image.
.container {
background: #fff;
padding: 20px;
}
.round {
width: 100px;
height: 100px;
border: solid 2px #000;
position: relative;
}
.round:before {
content: '';
width: 20px;
height: 20px;
background: #fff;
border-bottom: solid 2px #000;
position: absolute;
top: -12px;
left: -11px;
transform: rotate(315deg);
}
.round:after {
content: '';
width: 20px;
height: 20px;
background: #fff;
border-top: solid 2px #000;
position: absolute;
bottom: -12px;
right: -11px;
transform: rotate(315deg);
}
<div class="container">
<div class="round"></div>
</div>
hat do you think?
Perhaps look at using an inline svg image, this would give you control over background image, and would allow for the shape to "scale", and if you like, change the background color (fill) when you like.
HTML
<div class="cornered-box">
<div class="svg-cont">
<svg width="200px" height="200px" viewBox="635 375 202 202" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<polygon id="path-1" points="675.163277 376 836 376 836 535.221624 796.221624 575 636 575 636 414.163277"></polygon>
</defs>
<use stroke="#000000" stroke-width="2" fill="transparent" xlink:href="#path-1"></use>
</svg>
</div>
<div class="cornered-box-content">
<p>
Some content for the box
</p>
</div>
</div>
CSS
.cornered-box{
height:200px;
width:200px;
position: relative;
padding:20px 5px;
box-sizing:border-box;
}
.cornered-box .svg-cont{
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
z-index:-1;
}
.cornered-box .svg-cont svg{
height:100%;
width:100%;
}
.cornered-box .svg-cont svg use{
fill:transparent;
transition: fill 0.2s ease-in-out;
}
.cornered-box:hover .svg-cont svg use{
fill:#F00;
}
JSFIDDLE
Link to SVG

How to transform block in css?

How to transform block in CSS? Pseudo-elements is need or not? I try to create block look like block on the picture below. I can't create such block as on the picture below.
This is my code:
.transform_items {
width: 40%;
height: 80px;
position: relative;
margin: 0 auto;
perspective: 600px;
margin-top: 150px;
left: 50px;
}
.block,
.block::before{
display: block;
position: absolute;
margin: 0 auto;
}
.block {
border: 5px solid transparent;
width: 350px;
height: 60px;
}
.block::before {
content: '';
border: 5px solid #52B352;
transform: rotateY(30deg);
top: -5px;
right: -5px;
bottom: -5px;
left: -35px;
}
.block a {
font-size: 24px;
}
<div class="transform_items">
<div class="block"><a>Block</a></div>
</div>
The expected result:
If you can use SVG (1), it could be like this
codePen
svg #block {
stroke: orange;
fill: none;
stroke-width: 5
}
svg text {
font-size: 25px
}
<svg version="1.1" x="0px" y="0px" width="274px" height="84px" viewBox="0 0 274 84">
<polygon id="block" points="33,13 245,24 245,60 29,64 " />
<text x="100" y="50">BLOCK</text>
</svg>
You can also save the svg code as a .svg file,without the text element, and use it as background-image for the div that contains your text
Read this to learn how to use svg in different ways: https://css-tricks.com/using-svg/
(1) Browser support for SVG is a little better than browser support for transform, caniuse: SVG

Quarter of a ring with CSS and HTML

I'm trying to create a ring shape in css, divided into 4 quarters.
Each quarter will represent a button.
I've been playing around with the following code:
#quarterCircleTopLeft{
width:100px;
height:100px;
border:1px solid #000;
background: orange;
border-radius: 90px 0 70px 0;
-moz-border-radius: 90px 0 70px 0;
-webkit-border-radius: 90px 0 70px 0;
}
Which produces this (disregard the grey lines):
Obviously, I want the border at the right bottom to be inverted. However, since this is a button I cannot use another shape to produce a cutout (as this would overlap with other buttons of the menu). I've added a red line to show approx how I would want the border to go. Sorry, my paint skills are bad :-P
How can I invert the border or in another way produce the shape I want?
I'd do something like:
http://dabblet.com/gist/5476973
In short, lots of border radius + a white circle on top of everything.
On my example, I'd then bind click events onto the divs using javascript, or just make them all <a> elements instead and add a display:block;.
/**
* Quarter Circles
*/
.main {
position: relative;
width: 200px;
height: 200px;
margin: 0 auto;
}
.quarter {
position: absolute;
width: 50%;
height: 50%;
transition: background-color 0.2s ease-in-out;
}
.quarter:hover {
background-color: pink;
}
.quarter1 {
top: 0;
left: 0;
background-color: red;
border-radius: 100% 0 0 0;
}
.quarter2 {
top: 0;
right: 0;
background-color: blue;
border-radius: 0 100% 0 0;
}
.quarter3 {
bottom: 0;
left: 0;
background-color: orange;
border-radius: 0 0 0 100%;
}
.quarter4 {
bottom: 0;
right: 0;
background-color: green;
border-radius: 0 0 100% 0;
}
.cutout {
width: 50%;
height: 50%;
background-color: white;
position: absolute;
top: 25%;
left: 25%;
border-radius: 50%;
pointer-events: none;
}
<div class="main">
<div class="quarter quarter1"></div>
<div class="quarter quarter2"></div>
<div class="quarter quarter3"></div>
<div class="quarter quarter4"></div>
<div class="cutout"></div>
</div>
Here is an <svg> solution.
Svg has its own <a> element svg.
Just press the corners and you will find some amazing documentation ;)
Jokes aside The a link works on the shape so the shape gets the link.
This leaves the space empty space inside the shape that will show any thing behind it.
<svg width="150px" height="150px" viewbox="-1 -1 102 102">
<a xlink:href="https://developer.mozilla.org/en-US/docs/SVG">
<path stroke="tomato" fill="orange" d="M10 50 0 50 C 0 16 16 0 50 0 V0 20
C 31 20 20 31 20 50Z" />
</a>
<a xlink:href="https://developer.mozilla.org/en-US/docs/SVG">
<path stroke="darkRed" fill="red" transform="translate(100, 0) rotate(90)" d="M10 50 0 50 C 0 16 16 0 50 0 V0 20
C 31 20 20 31 20 50Z" />
</a>
<a xlink:href="https://developer.mozilla.org/en-US/docs/SVG">
<path stroke="DarkBlue" fill="blue" transform="translate(100, 100) rotate(180)" d="M10 50 0 50 C 0 16 16 0 50 0 V0 20
C 31 20 20 31 20 50Z" />
</a>
<a xlink:href="https://developer.mozilla.org/en-US/docs/SVG">
<path stroke="darkGreen" href="#" fill="green" transform="translate(0, 100) rotate(-90)" d="M10 50 0 50 C 0 16 16 0 50 0 V0 20
C 31 20 20 31 20 50Z" />
</a>
</svg>
i have been able to enhance the 1st answer and avoid getting the ring respond when mouse is on cutoff area.
http://codepen.io/a-zaki/pen/rLRyAm
/**
* Quarter Circles
*/
.main {
position: relative;
width: 300px;
height: 300px;
margin: 0 auto;
}
.quarter {
position: absolute;
width: 50%;
height: 50%;
transition: background-color 0.2s ease-in-out;
z-index: 1;
}
.quarter:hover {
background-color: pink;
}
.quarter1 {
top: 0;
left: 0;
background-color: red;
border-radius: 100% 0 0 0;
}
.quarter2 {
top: 0;
right: 0;
background-color: blue;
border-radius: 0 100% 0 0;
}
.quarter3 {
bottom: 0;
left: 0;
background-color: orange;
border-radius: 0 0 0 100%;
}
.quarter4 {
bottom: 0;
right: 0;
background-color: green;
border-radius: 0 0 100% 0;
}
.cutout {
width: 50%;
height: 50%;
background-color: white;
position: absolute;
top: 25%;
left: 25%;
border-radius: 50%;
border: 3px solid #000;
z-index: 2;
}
<div class="main">
<div class="quarter quarter1"></div>
<div class="quarter quarter2"></div>
<div class="quarter quarter3"></div>
<div class="quarter quarter4"></div>
<div class="cutout"></div>
</div>
On Safari this should work:
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 40px;
height: 40px;
border: solid;
border-radius: 100px 0 0 0;
border-width: 30px 30px 0;
border-right: hidden;
}
</style>
<title>Quatre Circle Outline</title>
</head>
<body>
<div></div>
</body>
</html>