Design polygon shape using CSS - html

I want to design following shape using CSS. I don't want to use svg or canvas for this.
How can I design it. Any help would be greatly appreciated.

You can divide whole background in different parts and draw each with :before and :after pseudo element.
HTML:
<div class="box">
<div class="holder">
// content will go here...
</div>
</div>
* {box-sizing: border-box;}
body {
background: linear-gradient(orange, red);
min-height: 100vh;
margin: 0;
}
.box {
position: relative;
overflow: hidden;
padding: 10px;
width: 250px;
height: 300px;
margin: 20px;
}
.box:before {
position: absolute;
background: green;
border: 2px solid black;
z-index: -1;
content: '';
bottom: 0;
top: 20px;
right: 0;
left: 0;
}
.box:after {
border: solid black;
border-width: 2px 0 0 2px;
position: absolute;
background: green;
height: 30px;
content: '';
right: 50px;
z-index: -1;
left: 0;
top: 0;
}
.holder:before {
border-top: 2px solid black;
margin: -10px 14px 0 25px;
transform: rotate(52deg);
transform-origin: 0 0;
background: green;
float: right;
height: 30px;
content: '';
width: 26px;
}
<div class="box">
<div class="holder">
Lorem ipsum dolor sit sit amet, dolor sit sit amet, lorem ipsum dolor sit amet, lorem ipsum dolor sit amet ...
</div>
</div>

you can do that using 3 <div> tags
initially create a larger div
then create two smaller div with absolute position and set their background white
#border{
position:relative;
width:300px;
height:200px;
border:3px solid #000;
box-shadow:0px 0px 1px 3px #3dd7cf;
background:#304e4b;
border-bottom-width:5px;
}
#triangle{
position: absolute;
top: -31px;
right: 7px;
width: 50px;
height: 50px;
background: #fff;
border-bottom: 3px solid #3dd7cf;
transform: rotate(45deg);
box-shadow: 0px 2px 0px 0px #000;
z-index:990;
overflow:hidden;
}
#sqr{
position: absolute;
top: -22px;
right: -7px;
width: 40px;
height: 50px;
border-bottom: 4px solid #3dd7cf;
box-shadow: 0px 2px 0px 0px #000;
background: #fff;
z-index: 999;
}
<div id="border">
<div id="triangle"></div>
<div id="sqr"></div>
</div>

Related

Custom CSS chat bubble

I created a chat bubble using CSS. But I did not get the output I want. Here is my code,
body{
background-color: lightgreen;
}
.bubble {
margin: 100px;
display: inline-block;
position: relative;
width: 300px;
height: auto;
background-color: white;
}
.border{
border: 2px solid red;
}
.border-radius{
border-radius: 10px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
}
.triangle-right.border.right-top:before {
content: ' ';
position: absolute;
width: 0;
height: 0;
left: auto;
right: -26px;
top: -2px;
bottom: auto;
border: 25px solid;
border-color: red transparent transparent transparent;
}
.triangle-right.right-top:after{
content: ' ';
position: absolute;
width: 0;
height: 0;
left: auto;
right: -22px;
top: -0.3px;
bottom: auto;
border: 25px solid;
border-color: white transparent transparent transparent;
}
.chat{
padding: 6px;
}
<div class="bubble triangle-right border-radius border right-top">
<div class="chat">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit,</p>
</div>
</div>
Output I Get:
Output I Want:
How can I get the output in the second picture. I want to get a curve like effect on top right corner (just like in the second image). thanks.
You can try a radial-gradient() to draw the curve :
possible example
body{
background-color: lightgreen;
}
.bubble {
margin: 100px;
display: inline-block;
position: relative;
width: 300px;
height: auto;
background-color: white;
}
.border{
border: 2px solid red;
}
.border-radius{
border-radius: 10px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
}
.triangle-right.right-top:before{
content: ' ';
position: absolute;
border-top:2px red solid;
width:6px;
top:-2px;
right:0;
height:10px;
background:white;
}
.triangle-right.right-top:after{
content: ' ';
position: absolute;
width: 30px;
height: 40px;
left: auto;
right: -30px;
top: -2px;
background:radial-gradient(ellipse at bottom right, transparent 28px, red 29px , red 30px , white 31px);
border-top:solid red 2px;
}
.chat{
padding: 6px;
}
<div class="bubble triangle-right border-radius border right-top">
<div class="chat">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit,</p>
</div>
</div>
tweek size and position to your needs.

How to give shadow to a pointer of Tooltip> In HTML

I know I can absolute position the pointer of the Tooltip but how can I add the blur effect to the pointer? Because if I put blur effect to it, the blur will not only be shown on the bottom triangle of pointer, but also on the upper half of it.
You can try drop-shadow filter css effect.
.pointer {
width: 200px;
padding: 10px;
position: relative;
filter: drop-shadow(0px 0px 10px #b2b2b2);
background: #fff;
}
.pointer:after {
content: "";
position: absolute;
border: 20px solid;
border-color: #fff transparent transparent;
bottom: -40px;
left: calc(50% - 20px);
}
<div class="pointer">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam convallis interdum cursus.</div>
Check filter cross browser support
Also you can achieve this by using box-shadow and z-index css property. In this you will need to make an extra block to cover the upper part of shadow using :before/:after.
.pointer {
width: 200px;
padding: 10px;
position: relative;
box-shadow: 0px 0px 10px #b2b2b2;
background: #fff;
z-index: 1;
}
.pointer:after {
content: "";
position: absolute;
width: 30px;
height: 30px;
box-shadow: 0px 0px 10px #b2b2b2;
bottom: -15px;
left: calc(50% - 15px);
background: #fff;
transform: rotate(45deg);
z-index: -2;
}
.pointer:before {
content: "";
width: 60px;
height: 30px;
position: absolute;
background: #fff;
left: calc(50% - 30px);
bottom: 0;
z-index: -1;
}
<div class="pointer">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam convallis interdum cursus.</div>
You can use this code
body {
margin: 0;
padding: 0;
}
.example {
background: rgba(219,224,223,0.5);
margin-bottom: 20px;
padding: 20px;
text-align: center;
width: auto;
}
.example-with-box-shadow {
box-shadow: rgba(0,0,0,0.3) 0 2px 10px;
}
.example-with-arrow, .example-with-box-shadow, .example-with-drop-shadow {
background: white;
display: inline-block;
margin-bottom: 5px;
padding: 5px;
position: relative;
width: 200px;
}
.example-with-arrow::after, .example-with-box-shadow::after, .example-with-drop-shadow::after {
border: 10px solid;
border-top-color: currentcolor;
border-right-color: currentcolor;
border-bottom-color: currentcolor;
border-left-color: currentcolor;
border-color: white transparent transparent;
content: "";
left: 50%;
margin-left: -10px;
position: absolute;
top: 100%;
}
<div class="example">
<div class="example-with-box-shadow">Tooltip with box-shadow</div>
</div>
body {
background-color: #888;
}
.triangle {
position: relative;
margin: 3em;
padding: 1em;
box-sizing: border-box;
background: #bada55;
box-shadow: 0px 3px 3px 0 rgba(0, 0, 0, 0.4);
}
.triangle::after{
content: "";
position: absolute;
width: 0;
height: 0;
margin-left: -0.5em;
bottom: -2em;
left: 50%;
box-sizing: border-box;
border: 1em solid black;
border-color: transparent transparent #bada55 #bada55;
transform-origin: 0 0;
transform: rotate(-45deg);
box-shadow: -3px 3px 3px 0 rgba(0, 0, 0, 0.4);
}
<div class="triangle">This is a CSS3 triangle with a proper box-shadow!</div>

Turning a vertical CSS timeline into a horizontal one

I need to make some changes to this vertical timeline, which has been made with simple HTML and CSS.
Now, my problem is: how can I turn the timeline (and the related divs) horizontal rather than vertical, without using the transform: rotate(270deg); command?
Also, the dots on the timeline do not perfectly keep their position when resizing the browser window, but so far I haven't found any better solution than using margin-left: 39.5% for keeping them on the timeline.
Anyone can help me?
Link: Here's the fiddle
.timeLine {
position: relative;
padding: 70px 0px;
text-align: center;
width: 100%;
overflow: hidden;
}
.timeLine .lineHeader:after {
content: '';
width: 3px;
position: absolute;
top: 35px;
bottom: 35px;
left: 80%;
border-radius: 50px;
background-color: #405461;
z-index: 9999;
}
.timeLine .lineFooter:before {
position: absolute;
bottom: 0;
margin: auto;
content: "\f103";
font-family: FontAwesome;
color: #405461;
font-size: 36px;
margin-left: -10px;
left: 80%
}
.timeLine .item {
float: left;
margin-bottom: 2%;
padding: 0px;
clear: left;
width: 80%;
}
.timeLine .item:before {
content: '';
width: 15px;
height: 15px;
border: 3px solid darkred;
background-color: white;
border-radius: 50%;
position: absolute;
z-index: 10000;
margin-left: 39.5%;
margin-top: -6px;
}
.timeLine .item .caption {
margin: 0px 0px 20px 100px;
width: auto;
background: #F0F0F0;
min-height: 60px;
position: relative;
color: #333;
border: 2px solid darkred;
border-right: none;
box-shadow: 2px 2px 10px 1px rgba(0, 0, 0, 0.5);
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="timeLine">
<div class="lineHeader"></div>
<div class="lineFooter"></div>
<div class="item">
<div class="caption"></div>
</div>
<div class="item">
<div class="caption"></div>
</div>
<div class="item">
<div class="caption"></div>
</div>
</div>
I refactored your code a littble bit as using too high z-index value is not a good practive. It's better that you learn how z-index works than trying very high value that nobody can control.
The script is just to make dynamic position for elements.
$(document).ready(function() {
var items = $(".item");
for (var i = 0; i < items.length; i++) {
var left = $(items[i]).data('left') + 'px';
$(items[i]).css('left', left);
};
});
.timeLine {
position: relative;
text-align: center;
width: 100%;
height: 500px;
top: 40px;
}
.timeLine:after {
content: '';
height: 3px;
width: calc(80%);
position: absolute;
left: 10%;
border-radius: 50px;
background-color: #405461;
}
.timeLine:before {
position: absolute;
right: 7%;
content: "\f103";
font-family: FontAwesome;
color: #405461;
font-size: 36px;
transform: rotate(270deg);
line-height: 3px;
}
.timeLine .item {
margin-bottom: 2%;
padding: 0px;
width: 80%;
}
.timeLine .item:before {
content: '';
width: 15px;
height: 15px;
border: 3px solid darkred;
background-color: white;
border-radius: 50%;
position: absolute;
left: -7.5px;
top: -7.5px;
z-index: 1;
}
.timeLine .item {
margin: 0px 0px 20px 100px;
width: 60px;
background: #F0F0F0;
min-height: 100px;
position: relative;
color: #333;
border: 2px solid darkred;
border-top: none;
box-shadow: 2px 2px 10px 1px rgba(0, 0, 0, 0.5);
position: absolute;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="timeLine">
<div class="item" data-left="0">
<div class="caption">Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum</div>
</div>
<div class="item" data-left="100">
<div class="caption">Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum</div>
</div>
<div class="item" data-left="200">
<div class="caption">Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum</div>
</div>
</div>

div with right arrow

I have this div:
I need css that do exacly that, the div and the arrow to the right like that.
Alos, i need a random text (length is changing, and we are talking responsive) in it and i want the text always to be in the middle of things... what is the best way to do so?
Here's a great generator to get you started and then you can customize it a little more to get your desired result
http://cssarrowplease.com/
To get something similar to what you showed, try
.arrow_box {
position: relative;
background: #3abc3d;
min-height: 80px;
border-radius: 10px;
padding: 20px;
}
.arrow_box:after {
left: 100%;
top: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
border-color: rgba(58, 188, 61, 0);
border-left-color: #3abc3d;
border-width: 20px;
margin-top: -20px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
<div class="col-xs-5 col-sm-4 col-md-4 col-lg-2">
<div class="arrow_box">
Message for everything
</div>
</div>
And on your arrow box, using bootstrap or whatever grid system you are using, attach the sizing for responsiveness.
Example 1
.block {
background: green;
border-radius: 10px;
padding: 20px;
position: relative;
color: #fff;
max-width: 200px;
margin: 0 auto;
}
.block:after {
content: '';
position: absolute; right: -20px; top: 50%;
border: 10px solid transparent;
border-left: 10px solid green;
-webkit-transform: translate(0,-50%);
-ms-transform: translate(0,-50%);
transform: translate(0,-50%);
}
<div class="block">
Block
</div>
Example 2
.block {
background: green;
border-radius: 10px;
padding: 20px;
position: relative;
color: #fff;
max-width: 200px;
margin: 0 auto;
}
.block:after{
content: '';
position: absolute; right: -10px; top: 50%;
background: green;
width: 20px; height: 20px;
margin-top: -10px;
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
}
<div class="block">
Block
</div>
Something like this,
Reference
<style>
.arrow-right {
width: 0;
height: 0;
border-top: 60px solid transparent;
border-bottom: 60px solid transparent;
border-left: 60px solid green;
}
</style>
<div class="arrow-right"></div>
Please try this
.box {
width: 200px;
padding: 10px;
background: green;
border-radius: 5px;
position: relative;
}
.box p {
margin: 0;
color: #fff;
}
.box::after {
position: absolute;
content: "";
border-style: solid;
border-width: 20px;
border-color: transparent transparent transparent green;
left: 100%;
top: 50%;
margin-top: -20px;
}
<div class="box">
<p>orem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque in fermentum risus. Donec malesuada, risus id vulputate varius, diam enim elementum sem.</p>
</div>

CSS how can I add border also to triangle? [duplicate]

This question already has answers here:
CSS triangle custom border color
(5 answers)
Closed 8 years ago.
In my case i have something following this:
http://jsfiddle.net/pyx3zx25/12/
and the question is how can i add the border also to triangle.
My css:
.slide{
position: relative;
padding: 15px;
}
.arrow {
max-width: 300px;
background-color: #E01616;
position: absolute;
top: -10px;
left: -10px;
margin: 5px 0 0 5px;
border: 3px solid black;
}
.arrow:after {
left: 100%;
bottom: 0px;
content: "";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
border-width: 15px;
border-bottom: 30px solid #E01616;
border-right: 30px solid transparent;
}
Use the :before pseudo-element to create a like-for-like triangle with just a few adjustments, to make it seem like your :after element has a border:
.slide{
position: relative;
padding: 15px;
}
.arrow {
max-width: 300px;
background-color: #E01616;
position: absolute;
top: -10px;
left: -10px;
margin: 5px 0 0 5px;
border: 3px solid black;
}
.arrow:after {
left: 100%;
bottom: 0px;
content: "";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
border-width: 15px;
border-bottom: 30px solid #E01616;
border-right: 30px solid transparent;
}
.arrow:before {
left: 100%;
bottom: -3px;
content: "";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
border-width: 15px;
border-bottom: 37px solid #000;
border-right: 37px solid transparent;
}
<div class="slide">
<div class="arrow">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer scelerisque ex eget ultricies blandit.</p>
</div>
</div>
You can't use border because you use it already.
Try it.
UPDTATE
.arrow:before{
border-bottom: 40px solid #000;
border-right: 37px solid transparent;
border-width: 0 37px 40px 0;
bottom: 0;
content: "";
left: 100%;
position: absolute;
top: 55px;
}
jsfiddle - jsfiddle
HTML
<div class="slide">
<div class="arrow">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer scelerisque ex eget ultricies blandit.</p>
</div>
</div>
CSS
.slide{
position: relative;
padding: 15px;
}
.arrow {
max-width: 300px;
background-color: #E01616;
position: absolute;
top: -10px;
left: -10px;
margin: 5px 0 0 5px;
border: 3px solid black;
}
.arrow:after {
left: 100%;
bottom: 0px;
content: "";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
border-width: 15px;
border-bottom: 30px solid #E01616;
border-right: 30px solid transparent;
box-shadow: 0px 3px 0px 0px #000;
}
.arrow:before{
content: "";
right: -30px;
bottom: 0px;
height: 3px;
width: 30px;
position: absolute;
background: #000;
pointer-events: none;
transform: rotate(45deg) translate(-8px,-11px) scale(1.45);
}