Create a div with a cross and a text inside with CSS - html

I'm trying to create a div with an 'x' and a text inside it, as shown on this image
Can I somehow improve this snippet?
div {
width:49px;
height:49px;
border:1px solid black;
position:relative;
text-align:center;
line-height:49px;
font-size:25px;
}
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;
}
<div>XL</div>
The snippet above is just what I've done so far, a completely different solution(as long as the outcome is as shown on the image attached) is perfectly fine

If you want to make sure the text is always centered in the div, you could use absolute positioning and apply a background
See this fiddle
.wrapper {
width:50px;
height:50px;
border:2px solid black;
position:relative;
text-align:center;
font-size:25px;
padding: 10px;
overflow: hidden;
}
.wrapper:before {
content:'';
position:absolute;
top:50%;
left: 50%;
width:0;
height:200%;
border: 1px solid black;
transform: translateY(-50%)rotate(45deg);
z-index: -3;
}
.wrapper:after {
content:'';
position:absolute;
top:50%;
left: 50%;
width:0;
height:200%;
border: 1px solid black;
transform: translateY(-50%)rotate(-45deg);
z-index: -3;
}
.wrapper > div {
background: #fff;
padding: 5px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<div class="wrapper">
<div>
XL
</div>
</div>

Use linear-gradient()
I made two choices, inspired by the answers.
I used linear-gradient (), which is another way.
.first,
.second {
width: 49px;
height: 49px;
border: 1px solid black;
position: relative;
text-align: center;
margin: 0 auto 8px auto;
line-height: 49px;
font-size: 25px;
}
.first:before,
.second:before {
content: "";
position: absolute;
height: 142%;
top: 50%;
left: 50%;
transform: translateY(-50%) rotate(45deg);
z-index: -3;
background: linear-gradient(to top, #333, #333 25%, #eee0 25%, #eee0 75%, #333 75%);
padding: 0.5px;
}
.first:after,
.second:after {
content: "";
position: absolute;
height: 142%;
top: 50%;
left: 50%;
transform: translateY(-50%) rotate(-45deg);
z-index: -3;
background: linear-gradient(to top, #333, #333 25%, #eee0 25%, #eee0 75%, #333 75%);
padding: 0.5px;
}
.second {
width: 68px;
font-size: 20px;
}
.second:after {
height: 172%;
transform: translateY(-50%) rotate(-54deg);
}
.second:before {
height: 172%;
transform: translateY(-50%) rotate(54deg);
}
<div class="first">XL</div>
<div class="second">XL</div>

wrap your text on a span tag, add background
div {
width:49px;
height:49px;
border:1px solid black;
position:relative;
text-align:center;
line-height:49px;
font-size:25px;
}
div span{
background:#fff;
}
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;
}
<div><span>XL</span></div>

Related

Center one fixed 'arrow' element inside another fixed 'circle' element

I am having trouble centering the arrow inside the red circle.
How can I center one fixed element inside another fixed element?
JsFiddle: https://jsfiddle.net/sebastian3495/xtj9cga2/4/
Code
html, body {
height: 1000px;
width: 100%;
}
#a {
width: 100%;
height: 100%;
border: 1px solid black;
position:relative;
}
#wrapper {
position: absolute;
top: 50vh;
}
#b {
width: 100px;
height: 100px;
border-radius: 50%;
background: red;
position: fixed;
}
#c {
border: solid black;
border-width: 0 3px 3px 0;
position: fixed;
width: 50px;
height: 50px;
transform: rotate(-45deg);
}
<div id="a">
<div id="wrapper">
<i id="b"></i>
<i id="c"></i>
</div>
</div>
You can simply your code like below then you can easily center your arrow and also adjust the dimension:
.arrow {
background:red;
width:100px;
height:100px;
border-radius:50%;
position:fixed;
top:100px;
left:50px;
}
.arrow::before {
content:"";
position:absolute;
top:50%;
left:50%;
width:50%;
height:50%;
border-top:3px solid;
border-right:3px solid;
/*75% instead of 50% since we need to center half the shape so 50% then 25%*/
transform:translate(-75%,-50%) rotate(45deg);
}
<div class="arrow"></div>
You can still simplify more without pseudo element:
.arrow {
width:100px;
height:100px;
padding:35px 35px 0 0;
border-radius:50%;
position:fixed;
top:100px;
left:50px;
background:
linear-gradient(#000,#000) top right/77% 3px,
linear-gradient(#000,#000) top right/3px 77%,
red;
background-repeat:no-repeat;
background-origin:content-box;
transform:rotate(45deg);
box-sizing:border-box;
}
<div class="arrow"></div>
adjust top and left position for i tag with id="c"
#c {
border: solid black;
border-width: 0 3px 3px 0;
position: fixed;
width: 50px;
height: 50px;
left:3%;
top:60vh;
transform: rotate(-45deg);
}

CSS Shapes , rectangle with curve rectangular edges

need help creating the shapes above with the curved rectangular angles...to insert images inside i can do that ...can someone help me out ...please...
I have tried using border-radius to selectively chose the edge i want rectangular
.curv {
width: 800px;
margin: 0 auto;
position: relative;
padding-top: 100px;
overflow: hidden;
}
.curv:before {
background: #333;
height: 200px;
left: -20px;
right: 0px;
top: 0px;
content: '';
position: absolute;
border-radius: 0% 0 0 0;
clip-path: polygon(53% 0, 100% 49%, 57% 100%, 0% 100%, 0 47%, 0% 0%);
}
.holder {
height: 200px;
background: #333;
position: relative;
z-index: 9999;
}
<div class="curv">
<div class="holder"></div>
</div>
I would use some pseudo element and the same background-image twice.
Here is an example (missing only one curve):
body {
background:pink;
}
.box {
margin:100px;
width:200px;
height:100px;
border-right:3px solid green;
border-bottom:3px solid green;
border-radius:0 0 10px 10px;
background:
url(https://lorempixel.com/200/150/) bottom;
position:relative;
}
.box:before {
content:attr(data-text);
color:#000;
font-weight:bold;
text-shadow:0px 0px 5px #fff;
text-align:center;
position:absolute;
height:50px;
top:-53px;
right:-3px;
width:50%;
background:
url(https://lorempixel.com/200/150/) top right;
border:3px solid green;
border-bottom:none;
border-radius:10px 10px 0 0;
}
.box:after {
content:"";
position:absolute;
left:-3px;
width:50%;
bottom:-3px;
height:100px;
border:3px solid green;
border-right:none;
border-radius:10px 0 0 10px;
}
<div class="box" data-text="SOME TEXT">
</div>

Draw dashed border inside the custom shape using HTML & CSS

I have to code a shape(below image) in HTML
And below is the code what I tried so far:
body {
font: 13px Verdana;
}
h3 {
height: 100px;
background: #72bbab;
border-radius: 50px 10px 10px 50px;
display: flex;
margin-top: 50px;
position: relative;
line-height: 100px;
color: #ffffff;
font-size: 13px;
font-weight: normal;
}
h3 i {
width: 130px;
height: 130px;
transform: translateY(-15px);
background: #71bbab;
border-radius: 50%;
position: relative;
margin-right: 20px;
}
h3:before {
content: "";
position: absolute;
border: 1px dashed #fff;
top: 5px;
bottom: 5px;
left: 20px;
right: 2px;
border-radius: 10px;
}
h3 i:before {
content: "";
position: absolute;
top: 5px;
bottom: 5px;
left: 5px;
right: 5px;
border: 1px dashed #fff;
border-radius: 50%;
}
<h3><i></i>Text</h3>
Now the issue is I am not able to remove dashed border of circle from right side. I tried border-top:0 and border-right:0 but didn't work.
Thanks in advance
Note: Don't want to use any king of image
If you need to get the output by keeping same HTML mark-up then you have to use many pseudo selectors, CSS calc() function to calculate h2 tag width and many such properties to get output using CSS.
You have too even use position and z-index to hide circle border backside of h2 tag. And using margin you could arrange the remaining, so at one point whole diagram connects.
body {
font: 13px Verdana;
}
h3{
background:#72bbab;
width:calc(100% - 95px);
height:85px;
margin-left:95px;
margin-top:21px;
display:flex;
justify-content:flex-start;
align-items:center;
border-top-right-radius:10px;
border-bottom-right-radius:10px;
padding-left:20px;
box-sizing:border-box;
color:#fff;
}
h3 i{
width:120px;
height:120px;
background:#72bbab;
border-radius:50%;
display:inline-block;
top:2px;
left:2px;
position:absolute;
z-index:-1;
overflow:hidden;
}
h3 i:before{
content:"";
width:100px;
height:100px;
border:2px dashed #fff;
position:absolute;
top:8px;
left:8px;
border-radius:50%;
}
h3:before{
content:"";
width:calc(100% - 120px);
height:65px;
border:2px dashed #fff;
position:absolute;
right:15px;
border-top-right-radius:10px;
border-bottom-right-radius:10px;
}
h3:after{
content:"";
width:3px;
height:68px;
background:#72bbab;
position:absolute;
top:28px;
margin-left:-61px;
}
<h3><i></i>Text</h3>
See if this helps.
https://jsfiddle.net/induprakash/8ofLjqxm/
I added a higher z-index to rectangle border.
body {
font: 13px Verdana;
}
h3 {
height: 100px;
background: #72bbab;
border-radius: 50px 10px 10px 50px;
display: flex;
margin-top: 50px;
position: relative;
line-height: 100px;
color: #ffffff;
font-size: 13px;
font-weight: normal;
}
h3 i {
width: 130px;
height: 130px;
transform: translateY(-15px);
background: #71bbab;
border-radius: 50%;
position: relative;
margin-right: 20px;
}
h3:before {
content: "";
position: absolute;
border: 1px dashed #fff;
top: 5px;
bottom: 5px;
left: 105px;
z-index: 10;
right: 2px;
border-radius: 0px;
border-left: 0;
}
h3 i:before {
content: "";
position: absolute;
top: 5px;
bottom: 5px;
left: 5px;
right: 5px;
border: 1px dashed #fff;
border-radius: 50%;
border-right : 1px solid #72bbab;
}
Try this one, its running as per your image. I have tried a simple and different approach.
JSFiddle Link - https://jsfiddle.net/deepak104080/uwx873x1/
.circle {
width:130px;
height:130px;
border-radius:65px;
position:absolute;
z-index:100;
background:#71bbab;
margin:0px;
padding:0px;
}
.innercircle {
width:110px;
height:110px;
border-radius:55px;
position:absolute;
top:9px;
left:9px;
z-index:100;
background:#71bbab;
border: 1px dashed #fff;
}
.tab {
height: 100px;
position:absolute;
margin-top:15px;
margin-left:105px;
z-index:1000;
width:350px;
background:#71bbab;
border-top-right-radius:10px;
border-bottom-right-radius:10px;
}
.innertab {
height: 78px;
position:absolute;
margin-top:10px;
margin-left:0px;
z-index:1000;
width:340px;
background:#71bbab;
border-top-right-radius:10px;
border-bottom-right-radius:10px;
border-top: 1px dashed #fff;
border-bottom: 1px dashed #fff;
border-right: 1px dashed #fff;
}
<div>
<div class="circle">
<div class="innercircle">
</div>
</div>
<div class="tab">
<div class="innertab">
</div>
</div>
</div>
Use the ::after pseudo for h3 element.
h3:after {
z-index: 9999;
position:absolute;
max-width: 100%;
width: 100px;
height: 87px;
background: #71bbab;
content: '';
left: 35px;
margin-top: 6px;
}
https://jsfiddle.net/apyupfwo/

How to make not fully rounded circle?

I want to do rounded circle like below image
But I am in trouble in making inner rounded one ! I tried with border-top-style & border-right-style but not getting the same yet .
.circle {
border-radius:50%;
width:100px;
height:100px;
background:#A2D36E;
text-align:center; }
.bar {
top:15px;
left:15px;
border-radius:50%;
border:1px solid white;
border-width:3px;
border-top-style:none;
border-right-style:none;
width:80px;
height:80px;
position:absolute;
}
span {
top:30%;
transform:translateY(-30%);
position:relative;
font-size:1.6rem;
color:#fff;
font-weight:bold;
}
<div class='circle'>
<div class='bar'> </div>
<span>8.8</span>
</div>
.circle {
border-radius:50%;
width:100px;
height:100px;
background:#A2D36E;
text-align:center; }
.bar {
top:15px;
left:15px;
border-radius:50%;
border:1px solid white;
border-width:3px;
border-top-style:inset;
border-right-style:inset;
border-top-color: transparent;
width:80px;
height:80px;
position:absolute;
transform: rotate(40deg);
}
span {
top:30%;
transform:translateY(-30%);
position:relative;
font-size:1.6rem;
color:#fff;
font-weight:bold;
}
<div class='circle'>
<div class='bar'> </div>
<span>8.8</span>
</div>
Try This:
.circle {
border-radius:50%;
width:100px;
height:100px;
background:#A2D36E;
text-align:center;
}
.bar {
top:15px;
left:15px;
border-radius:50%;
border:1px solid white;
border-width:3px;
width:80px;
height:80px;
position:absolute;
}
.bar:after {
width: 25px;
height: 10px;
content: '';
position: absolute;
top: -3px;
background: #A2D36E;
transform: rotate(20deg);
}
span {
top:30%;
transform:translateY(-30%);
position:relative;
font-size:1.6rem;
color:#fff;
font-weight:bold;
}
<div class='circle'>
<div class='bar'> </div>
<span>8.8</span>
</div>
The CodePen link demonstrates an SVG solution: https://codepen.io/UncaughtTypeError/pen/WXRObq
The Code Snippet below demonstrates x2 solutions you could explore:
Border Shape solution
Clip Path solution
.circle {
border-radius: 50%;
width: 100px;
height: 100px;
background: #A2D36E;
text-align: center;
position: relative;
}
.bar {
top: 0;
bottom: 0;
left: 0;
right: 0;
border-radius: 50%;
border: 1px solid white;
border-width: 3px;
margin: auto;
width: 80px;
height: 80px;
position: absolute;
}
span {
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
height: 35px;
position: absolute;
font-size: 1.6rem;
color: #fff;
font-weight: bold;
}
/* Additional */
.clip-path-solution .bar:after {
content: "";
width: 90px;
height: 90px;
position: absolute;
bottom: 0;
top: -3px;
left: -3px;
right: 0;
background: #a2d36e;
border-radius: 100%;
-webkit-clip-path: polygon(48% 48%, 100% 0%, 100% 0%, 50% 0%);
clip-path: polygon(48% 48%, 100% 0%, 100% 0%, 50% 0%);
transform: rotate(10deg);
}
.border-solution .shape {
transform: rotate(-30deg);
border-top: 10px solid transparent;
border-left: 10px solid transparent;
border-bottom: 10px solid transparent;
position: absolute;
box-sizing: border-box;
/* starting point */
/*border-right: 10px solid #d36e6e;
margin: auto;
left: 0;
right: 0;
top: 0;
bottom: 0;
width: 90px;
height: 90px;
border-radius: 100%;*/
/* adjusted accordingly for demonstration */
margin: 0;
width: 50px;
height: 50px;
top: 10px;
margin: 0;
right: 10px;
left: auto;
border-top-right-radius: 45px;
border-bottom-right-radius: 30px;
border-right: 10px solid #a2d36e;
}
<h3>Clip Path</h3>
<div class='clip-path-solution circle'>
<div class='bar'></div>
<span>8.8</span>
</div>
<h3>Border Shape</h3>
<div class='border-solution circle'>
<div class='bar'></div>
<div class='shape'></div>
<span>8.8</span>
</div>

create a css format with socil media icon [duplicate]

I'm trying to draw a line using CSS and show text/image in the middle of the line.
.featured-images {
color: #666666;
border: 2px solid #333333;
}
<p class="featured-images">Featured</p>
This is what I want to do:
and
Wrap the text inside a span and use a :pseudo-element for the line.
Position the line(:pseudo-element) behind the span using z-index: -1, so that you could move around the text without having to worry about the line.
.featured-images {
position: relative;
color: #666666;
border: 2px solid #333333;
padding: 0 10px 0 30px;
}
.featured-images span {
color: #666666;
background: white;
padding: 0 10px;
}
.featured-images:after {
content: '';
position: absolute;
width: 100%;
height: 2px;
background: #666666;
left: 0;
top: 50%;
transform: translateY(-50%);
z-index: -1;
}
<p class="featured-images"><span>Featured</span></p>
Replicating the following:
You could use repeating-linear-gradient to do this.
body {
background: #E7EAE3;
}
.featured-images {
position: relative;
color: #666666;
padding: 0 10px 0 30px;
overflow: hidden;
}
.featured-images span {
color: #517575;
background: white;
padding: 0 10px;
}
.featured-images:after {
content: '';
position: absolute;
width: 120%;
height: 100%;
background: -webkit-repeating-linear-gradient(180deg, #463A3A 10px, #F2F2F2 10px, #F2F2F2 11px, #463A3A 11px, #463A3A 20px) repeat-x;
background: -moz-repeating-linear-gradient(180deg, #463A3A 10px, #F2F2F2 10px, #F2F2F2 11px, #463A3A 11px, #463A3A 20px) repeat-x;
background-size: 10px 31px;
margin-left: -30px;
transform: skew(-45deg);
left: 0;
z-index: -1;
}
<p class="featured-images"><span>Featured</span>
</p>
Using image instead of text.
.featured-images {
position: relative;
color: #666666;
border: 2px solid #333333;
padding: 0 10px 0 30px;
}
.featured-images span {
display: block;
width: 80px;
height: 13px;
background: url(http://lorempixel.com/80/13) no-repeat white 10px 0;
padding: 0 10px;
}
.featured-images:after {
content: '';
position: absolute;
width: 100%;
height: 2px;
background: #666666;
left: 0;
top: 50%;
transform: translateY(-50%);
z-index: -1;
}
<p class="featured-images"><span></span></p>
Something like this? JSFiddle
CSS:
.featured-images {
color: #666666;
}
p span {
margin:0;padding: 0 10px;
background: #FFFFFF;
display: inline-block;
}
p {
padding-left: 20px;
position: relative;
z-index: 2;
}
p:after {
content: "";
position: absolute;
top: 50%;
left: 0;
right: 0;
border-top: solid 1px #666666;
z-index: -1;
}
Demo 1
:root{padding: 40px}
p{
position: relative;
margin:40px auto;padding:0 10px;
background:white;
display:inline-block;
}
p:before,p:after{
content:"";
position:absolute;
z-index:-1;
right:0
}
p:before{
top:-4px;
left: -24px;
height: 24px;
width: 480px;
border:solid 1px #666666
}
p:after{
top: 50%;
width: 466px;
left: -16px;
border-top: solid 1px #666666
}
<p class="featured-images">Featured</p>
Use Pseudo element
:root{padding: 40px}
p{
position: relative;
margin:40px auto;padding:0 10px;
background:white;
display:inline-block;
}
p:before,p:after{
content:"";
position:absolute;
z-index:-1;
left:-14px;
right:0;
width: 480px
}
p:before{
top:-4px;
height: 24px;
border:solid 1px #666666
}
p:after{
top:50%;
border-top:solid 1px #666666
}
<p class="featured-images">Featured</p>
Demo 2
p{
position: relative;
margin:0;padding:0 10px;
background:white;
display:inline-block;
}
p:after{
content:"";
position:absolute;
top:50%;
left:-14px;
right:0;
width: 100vw;
border-top:solid 1px #666666;
z-index:-1;
}
<p class="featured-images">Featured</p>
Update
:root{padding: 40px}
p{
position: relative;
margin:40px auto;padding:0 10px;
background:white;
display:inline-block;
}
p:before,p:after{
content:"";
position:absolute;
z-index:-1;
right:0
}
p:before{
top:-4px;
left: -24px;
height: 24px;
width: 480px;
border:solid 1px #666666;
background-color: gray;
background-image: repeating-linear-gradient(-45deg, transparent, transparent 2px, rgba(255,255,255,.5) 2px, rgba(255,255,255,.5) 6px)
}
}
p:after{
top: 50%;
width: 466px;
left: -16px;
border-top: solid 1px #666666
}
<p class="featured-images">Featured</p>
Result http://jsfiddle.net/p8jdzqvL/embedded/result/
<div style="height: 2px; background-color: black; text-align: center">
<span style="background-color: white; position: relative; top: -0.5em;">
Stay Connected
</span>
</div>