CSS custom tag shape - extra line - html

Please refer to this link.https://codepen.io/wbeeftink/pen/dIaDH. If you zoom out or zoom in you will see that the tag has an extra line sticking out at the bottom. Please refer to the screenshot.
Could someone please let me know how this could be fixed. Or is there a different way to create such tags?
This is the code that I use
HTML
<span class="tag">HTML</span>
CSS
.tag {
background: #eee;
border-radius: 3px 0 0 3px;
color: #999;
display: inline-block;
height: 26px;
line-height: 26px;
padding: 0 20px 0 23px;
position: relative;
margin: 0 10px 10px 0;
text-decoration: none;
-webkit-transition: color 0.2s;
}
.tag::before {
background: #fff;
border-radius: 10px;
box-shadow: inset 0 1px rgba(0, 0, 0, 0.25);
content: '';
height: 6px;
left: 10px;
position: absolute;
width: 6px;
top: 10px;
}
.tag::after {
background: #fff;
border-bottom: 13px solid transparent;
border-left: 10px solid #eee;
border-top: 13px solid transparent;
content: '';
position: absolute;
right: 0;
top: 0;
}

Change style of .tag::after from right: 0 to left: 100%.
body {
font: 12px/1.5 'PT Sans', serif;
margin: 25px;
}
.tags {
list-style: none;
margin: 0;
overflow: hidden;
padding: 0;
}
.tags li {
float: left;
}
.tag {
background: #eee;
border-radius: 3px 0 0 3px;
color: #999;
display: inline-block;
height: 26px;
line-height: 26px;
padding: 0 20px 0 23px;
position: relative;
margin: 0 10px 10px 0;
text-decoration: none;
-webkit-transition: color 0.2s;
}
.tag::before {
background: #fff;
border-radius: 10px;
box-shadow: inset 0 1px rgba(0, 0, 0, 0.25);
content: '';
height: 6px;
left: 10px;
position: absolute;
width: 6px;
top: 10px;
}
.tag::after {
background: #fff;
border-bottom: 13px solid transparent;
border-left: 10px solid #eee;
border-top: 13px solid transparent;
content: '';
position: absolute;
left: 100%;
top: 0;
}
.tag:hover {
background-color: crimson;
color: white;
}
.tag:hover::after {
border-left-color: crimson;
}
<h1>Tags</h1>
<h2>Example 1</h2>
Front-end development
<h2>Example 2</h2>
<ul class="tags">
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>

Related

CSS image stuck at corner

In this photo I added a div arrow using CSS I turned it into an arrow. In the center of the div/arrow i need to put an image.
This icon inside the grid is not changing the position to center without disturbing the css of the arrow created using grid.
.arrow {
position: relative;
text-indent: 30px;
text-align: center;
background-color: #E6EAEF;
display: inline-block;
zoom: 1;
*display: inline;
font-size: 1rem;
text-align: center;
padding: auto 0;
align-items: center;
height: 24px;
margin: 5px;
padding: 5px;
/* tweaked this */
font-size: 1rem;
line-height: 50px;
box-shadow: 0 8px 6px -6px black;
}
.arrow:after {
content: "";
position: absolute;
width: 0;
height: 0;
left: 0;
border-top: 17px solid transparent;
border-left: 12px solid #E6EAEF;
border-bottom: 17px solid transparent;
margin: -5px 10px 0 5px;
}
.arrow:before {
content: "";
position: absolute;
width: 0;
height: 0;
left: 0;
border-top: 17px solid transparent;
border-left: 10px solid white;
border-bottom: 17px solid transparent;
margin: -5px 0 0 0;
}
.arrow-icon {
display: inline-block;
position: relative;
margin-top: 0px;
margin-left: 0px;
padding-left: 0px;
height: 15px !important;
}
<div class="arrow">
<img class="arrow-icon" src="https://www.freeiconspng.com/uploads/magnifying-glass-icon-13.png" alt="">
</div>
`
In case the image has no action purpose, such as click events, and is for display purposes only, you can place it in the background.
.arrow {
position: relative;
text-indent: 30px;
text-align: center;
/* All background properties are combined in here. */
/* The CALC() is just to nudge it to the right so it looks better on the arrow. */
background: #E6EAEF url(https://www.freeiconspng.com/uploads/magnifying-glass-icon-13.png) calc(50% + 4px) 50% no-repeat;
background-size: 17px; /* Sets the icon size. */
display: inline-block;
zoom: 1;
*display: inline;
font-size: 1rem;
text-align: center;
padding: auto 0;
align-items: center;
height: 24px;
margin: 5px;
padding: 5px;
/* tweaked this */
font-size: 1rem;
line-height: 50px;
box-shadow: 0 8px 6px -6px black;
width: 50px;
}
.arrow::after {
content: "";
position: absolute;
width: 0;
height: 0;
right: -20px;
border-top: 17px solid transparent;
border-left: 12px solid #E6EAEF;
border-bottom: 17px solid transparent;
margin: -5px 10px 0 5px;
}
.arrow::before {
content: "";
position: absolute;
width: 0;
height: 0;
left: 0;
border-top: 17px solid transparent;
border-left: 10px solid white;
border-bottom: 17px solid transparent;
margin: -5px 0 0 0;
}
<div class="arrow">
</div>
You can set position: absolute; to .arrow-icon and then center it with top: 50%; left: 50%;. Translate is required to center the center of image.
.arrow {
position: relative;
text-indent: 30px;
text-align: center;
background-color: #E6EAEF;
display: inline-block;
zoom: 1;
*display: inline;
font-size: 1rem;
text-align: center;
padding: auto 0;
align-items: center;
height: 24px;
margin: 5px;
padding: 5px;
/* tweaked this */
font-size: 1rem;
line-height: 50px;
box-shadow: 0 8px 6px -6px black;
}
.arrow:after {
content: "";
position: absolute;
width: 0;
height: 0;
left: 0;
border-top: 17px solid transparent;
border-left: 12px solid #E6EAEF;
border-bottom: 17px solid transparent;
margin: -5px 10px 0 5px;
}
.arrow:before {
content: "";
position: absolute;
width: 0;
height: 0;
left: 0;
border-top: 17px solid transparent;
border-left: 10px solid white;
border-bottom: 17px solid transparent;
margin: -5px 0 0 0;
}
.arrow-icon {
display: inline-block;
position: absolute;
margin-top: 0px;
margin-left: 0px;
padding-left: 0px;
height: 15px !important;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 99; /*The Icon was overlapped by some part of arrow*/
}
<div class="arrow">
<img class="arrow-icon" src="https://cdn2.iconfinder.com/data/icons/ios-7-icons/50/search-512.png" alt="">
</div>
Use display:grid and place-items:center this CSS property will center the search icon.
.arrow{
margin:50px 100px;
background:#e6e9ee;
height:50px;
width:80px;
display:grid;
place-items:center;
position:relative;
padding-left:10px;
}
.arrow::after{
content:'';
position:absolute;
border-width:25px 15px;
border-style:solid;
border-color:#e6e9ee;
border-top-color:transparent;
border-right-color:transparent;
border-bottom-color:transparent;
right:-30px;
}
.arrow::before{
content:'';
position:absolute;
border-width:25px 15px;
border-style:solid;
border-color:#fff;
border-top-color:transparent;
border-right-color:transparent;
border-bottom-color:transparent;
left:0px;
}
<div class="arrow">
<img class="arrow-icon" src="https://cdn2.iconfinder.com/data/icons/ios-7-icons/50/search-512.png" height="20">
</div>

How to make an upside down triangle outline in CSS

I'm wondering if it's possible to achieve this design with CSS? I'm thinking of creating a div or span element after the text and making it a box with only two colored borders then rotating it 45 degrees? Otherwise I'm thinking of just using an image sprite.
You can use a CSS like this:
.caret.caret-reversed {
border-bottom: 10px solid #000000;
border-left: 6px solid rgba(0, 0, 0, 0);
border-right: 6px solid rgba(0, 0, 0, 0);
content: "";
display: inline-block;
height: 0;
vertical-align: top;
width: 0;
transform: rotate(180deg);
}
<span class="caret caret-reversed"></span>
Change the border-bottom colour to #fff for your solution.
Or there's another way using pseudo classes:
body {
background-color: #003;
font-family: verdana;
font-size: 10pt;
}
a {
color: #003;
background-color: #fff;
text-decoration: none;
display: inline-block;
padding: 5px;
position: relative;
z-index: 2;
border: 1px solid #f33;
}
a:after,
a:before {
top: 100%;
left: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
a:after {
border-color: transparent;
border-top-color: #fff;
border-width: 5px;
margin-left: -5px;
}
a:before {
border-color: rgba(0, 0, 51, 0);
border-top-color: #003;
border-width: 6px;
margin-left: -6px;
}
Performance
body {
background: #111842
}
li {
width: 100px;
display: inline-block;
border: 1px solid #000;
height: 30px;
line-height: 30px;
text-align: center;
position: relative;
z-index: 10;
background: #111842;
border: 1px solid #f19d47;
}
li a {
color: #fff;
text-decoration: none;
}
li:after {
content: '';
position: absolute;
top: 100%;
left: 0;
right: 0;
margin: 0 auto;
width: 1px;
z-index: 15;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-top: 10px solid #f19d47;
}
li:before {
content: '';
position: absolute;
top: 100%;
left: 0;
right: 0;
margin: 0 auto;
width: 1px;
z-index: 20;
border-left: 8px solid transparent;
border-right: 8px solid transparent;
border-top: 8px solid #111842;
}
li.active {
background: #fff;
border: 1px solid #fff;
}
.active a {
color: #000;
}
li.active:after,
li.active:before {
content: '';
border-top: 10px solid #fff;
}
<ul>
<li class="active">One
</li>
<li>One
</li>
<li>One
</li>
<li>One
</li>
<ul>

CSS: Make border on pure-CSS arrow

I have this code snippet:
.multiply-button {
display: table;
background: rgba(0, 0, 0, 0);
border: none;
color: white;
padding: 0;
}
.multiply-button-content {
display: table-cell;
background: green;
padding: 10px 9px;
border: solid 1px black;
border-right: none !important;
}
.multiply-button-arrow {
display: table-cell;
width: 0px;
height: 0px;
border-style: solid;
border-width: 20px 0 20px 12px;
border-color: transparent transparent transparent green;
}
<button id="multiply-button" class="multiply-button">
<div class="multiply-button-content">Multiply</div>
<div class="multiply-button-arrow"></div>
</button>
I need to make border on this "arrowed" button. I can easily border rectangle part (I've already did it), but how to make this border on triangle part?
The following should do what you need
.multiply-button {
display: table;
background: rgba(0, 0, 0, 0);
border: none;
color: white;
padding: 0;
}
.multiply-button-content {
display: table-cell;
background: green;
padding: 0 9px;
border: solid 1px black;
border-right: none !important;
position: relative;
vertical-align:middle;
height: 40px; /* double the border width */
box-sizing: border-box;
}
.multiply-button-content:after,
.multiply-button-content:before {
left: 100%;
top: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
border-width: 20px 0 20px 12px;
margin-top: -20px;
}
.multiply-button-content:after {
border-color: rgba(0, 128, 0, 0);
border-left-color: #008000;
margin-left: -1px;
}
.multiply-button-content:before {
border-color: rgba(0, 0, 0, 0);
border-left-color: #000000;
}
<button id="multiply-button" class="multiply-button">
<div class="multiply-button-content">Multiply</div>
</button>
This is a useful tool
div{
position: relative;
background-color: #008000;
padding: 0px 16px;
height: 40px;
line-height: 40px;
display: inline-block;
color: white;
border: 2px solid black;
border-right: none;
z-index:1;
}
div:before{
content: '';
position: absolute;
left: 100%;
z-index:-1;
width: 28px;
height: 28px;
background-color: #008000;
border-right: 2px solid black;
border-bottom: 2px solid black;
transform: rotate(-45deg) translate(-14px,-7px);
}
<div>Multiply</div>
Or much simplier :
the CSS with only one pseudo element
.multiply-button {
background: rgba(0, 0, 0, 0);
border: none;
width: 100px;
color: #FFF;
padding: 0;
overflow: hidden;
}
.multiply-button-content {
display: block;
position: relative;
background: #008000;
width: 60px;
padding: 10px 9px;
border: solid 1px #000;
border-right: none !important;
}
.multiply-button-content:before {
content: "";
position: absolute;
width: 36px;
height: 31px;
z-index: -1;
top: 0;
right: -13px;
border: 1px solid #000;
background: #008000;
transform: rotate(45deg);
}
<button id="multiply-button" class="multiply-button">
<div class="multiply-button-content">Multiply</div>
</button>
Since it only takes one pseudo element to make the 'point', you could use the other to make a border behind it (making it slightly bigger in size).
For example;
div {
height: 30px;
border: 2px solid black;
display: inline-block;
border-right: 2px solid transparent;
line-height: 30px;
text-align: center;
position: relative;
background: tomato;
color: white;
}
div:before {
content: "";
position: absolute;
border: 17px solid transparent;
border-left: 17px solid black;
right: -35px;
top: -2px;
z-index: 6;
}
div:after {
content: "";
position: absolute;
border: 15px solid transparent;
border-left: 15px solid tomato;
right: -31px;
top: 0;
z-index: 8;
}
<div>Arrow, Please!</div>
You can achieve that with :before or :after pseudo selectors. Study and adjust the example below.
.multiply-button {
display: inline;
background: rgba(0, 0, 0, 0);
border: none;
color: white;
padding: 0;
position: realtive;
}
.multiply-button-content {
display: table-cell;
background: green;
padding: 10px 9px;
border: solid 1px black;
border-right: none !important;
width: 100px;
position: relative;
}
.multiply-button-arrow {
width: 0;
height: 0px;
border-style: solid;
border-width: 20px 0 20px 12px;
border-color: transparent transparent transparent black;
position: absolute;
top: -2px;
right:-12px;
}
.multiply-button-arrow:before {
border-style: solid;
border-width: 20px 0 20px 12px;
border-color: transparent transparent transparent green;
position: absolute;
right: 1px;
top: -20px;
content: "";
}
<button id="multiply-button" class="multiply-button">
<div class="multiply-button-content">
<div class="multiply-button-arrow"></div>
Multiply</div>
</button>

CSS :hover not working after applying both :before and :after on the same element

:hover not working after applying :before and :after.
I'm checking on Chrome.
Here's my code :
<style>
* {
margin: 0px;
padding: 0px;
box-shadow: none;
}
body {
background: black;
}
#demoBoard {
position: relative;
margin: 7px auto;
width: 630px;
height: 650px;
background-color: grey;
background-image: radial-gradient(152px at 324px 50%, black, grey 99%);
opacity: 0.9;
border-radius: 10%;
}
#demoBoard h2 {
position: absolute;
color: rgb(243, 100, 20);
text-align: center;
text-shadow: 2px 2px 2px black;
top: 3px;
left: 290px;
-webkit-user-select: none;
}
#Gboard {
position: absolute;
width: 580px;
height: 580px;
background: rgba(0, 0, 0, 0.8);
position: absolute;
border: 5px solid crimson;
box-shadow: 3px 3px 4px black;
top: 34px;
left: 18px;
}
#demoBoard:before {
position: absolute;
content: "";
width: 628px;
height: 648px;
border-left: 1px solid rgb(41, 41, 51);
border-right: 1px solid rgb(41, 41, 51);
border-radius: 10%;
box-shadow: inset 10px 10px 30px black;
left: -1px;
}
#demoBoard:after {
position: absolute;
left: -1px;
top: -2px;
content: "";
width: 631px;
height: 651px;
border-bottom: 1px solid rgb(41, 41, 51);
border-top: 1px solid rgb(41, 41, 51);
border-radius: 10%;
box-shadow: inset -10px -10px 30px black;
}
#Gboard:hover {
cursor: pointer;
}
#Gboard:active {
box-shadow: 1px 1px 2px black;
cursor: pointer;
}
#options {
position: absolute;
top: 200px;
left: 180px;
color: crimson;
font: 20px bold;
background: rgba(123, 123, 123, 0.4);
border-radius: 10%;
width: 250px;
height: 300px;
}
#options:before {
content: "";
position: absolute;
box-shadow: inset 14px 14px 35px black;
border-radius: 10%;
width: 250px;
height: 300px;
}
#options:after {
content: "";
top: 2px;
position: absolute;
box-shadow: inset 0px -14px 35px black;
border-radius: 10%;
width: 250px;
height: 300px;
}
#options p {
position: absolute;
top: 12px;
left: 210px;
color: crimson;
font-size: 30px;
text-shadow: 0px 1px 1px black;
}
#options p:hover {
cursor: pointer;
}
#options ul {
list-style: none;
padding-top: 50px;
padding-left: 50px;
display: block;
}
#options ul li {
padding-bottom: 2px;
text-align: center;
border-bottom: 1px solid black;
width: 150px;
height: 30px;
text-align-last: right;
line-height: 2;
text-shadow: 0px 1px 1px black;
}
#options ul li:before {
position: absolute;
content: "";
left: 50px;
padding-bottom: 2px;
text-align: center;
border-bottom: 1px solid rgba(134, 94, 14, 0.5);
width: 150px;
height: 31px;
}
#options ul li:hover {
cursor: pointer;
padding-bottom: 5px;
font-size: 22px;
}
#options ul li:hover:before {
position: absolute;
content: "";
left: 50px;
padding-bottom: 2px;
text-align: center;
border-bottom: 1px solid green;
width: 150px;
height: 31px;
}
</style>
<div id="demoBoard">
<h2>Demo</h2>
<div id="Gboard"></div>
<div id="options" class="menu">
<p id="close">x</p>
<ul>
<li>Demo</li>
<li>Demo</li>
<li>Demo</li>
<li>Demo</li>
<li>Demo</li>
<li>Test</li>
</ul>
</div>
</div>
:hover is not working on all the elements that is applying hover.
I don't know what's going on with this code. It's working on some other test I've done.
That's because the content created by :after and :before on #demoBoard and #content is placed on top on your links, so you can't hover over them.
Add this to change the z-index of your links, essentially putting them on top of the other pseudo content.
#options ul li {
position: relative;
z-index: 2;
}
Note: if you do this, also change the left value of #options ul li:before and #options ul li:hover:before to "0", since it will now position itself relative to the list-item.
I gave the <ul> the following styles:
position: relative;
z-index: 1;
And it is working fine. A lot of the elements are positioned absolutely but the order of them is not defined.

Pure CSS Rounded Ribbon

I am trying to achieve the below using pure CSS, is it possible? If I can figure out a way to hide the bottom part to the top of the bottom rounded corner that would work. But I am lost at what would work...
.ribbon, .ribbon * {
box-sizing: border-box;
-moz-box-sizing: border-box;
}
.ribbon {
width: 600px;
margin: 40px auto 10px;
padding: 0 10px 4px;
position: relative;
color: black;
background: #eee;
}
.ribbon h3 {
display: block;
height: 40px;
width: 620px;
margin: 0;
padding: 5px 10px 5px 30px;
position: relative;
left: -30px;
color: white;
background: rgb(193,0,0);
box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.ribbon h3::before {
content: '';
display: block;
width: 0;
height: 0;
position: absolute;
bottom: -11px;
z-index: 10;
left: 0;
}
.ribbon.round h3 {
border-radius: 10px 0px 0px 0px;
}
.ribbon.round h3::before {
width: 20px;
height: 30px;
bottom: -20px;
border: none;
background: rgb(61,0,0);
border-radius: 10px 0px 0px 10px;
}
Fiddle to what I have currently
http://jsfiddle.net/yoderman94/Gdgwq/
Simply make your z-index value negative:
.ribbon h3::before {
z-index: -1;
}
That will place it under the heading.
To keep the rounded top, add another block with lower z-index, and fill it with the same background as the heading:
Example: http://jsfiddle.net/K7e96/
Here's a new fiddle, its like 99% there (only tested in Chrome), need to play with the shadows a bit more. http://jsfiddle.net/jrTAA/2/
.ribbon.round h3 {
border-radius: 5px 0px 0px 0px;
}
.ribbon.round h3::before, .ribbon.round h3::after {
width: 20px;
height: 8px;
bottom: -8px;
border: none;
border-top:2px solid rgb(193,0,0);
border-left:1px solid rgb(193,0,0);
border-bottom:1px solid rgb(193,0,0);
background: rgb(61,0,0);
border-radius: 5px 0px 0px 5px;
box-shadow: 0 1px 2px rgba(0,0,0,0.3), inset 2px 1px 2px rgba(0,0,0,0.3);
}
The fiddle:
http://jsfiddle.net/aleation/gCrhQ/
The code:
.ribbon, .ribbon * {
box-sizing: border-box;
-moz-box-sizing: border-box;
}
.ribbon {
width: 600px;
margin: 40px auto 10px;
padding: 0;
position: relative;
color: black;
background: #eee;
}
.ribbon h3 {
display: block;
height: 40px;
width: 100%;
margin: 0;
padding: 9px 0 0 10px;
color: white;
background: rgb(193,0,0);
box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.ribbon h3::before,
.ribbon p::before{
content: '';
display: block;
width: 0;
height: 0;
position: absolute;
bottom: -11px;
z-index: 10;
left: 0;
width: 14px;
}
/* Round */
.ribbon.round h3::before{
height: 45px;
top: 0px;
left: -14px;
border: none;
background: rgb(193,0,0);
border-top-left-radius: 7px 4px;
}
.ribbon.round p::before{
height: 7px;
top: 40px;
left: -14px;
border: none;
background: rgb(61,0,0);
border-top-left-radius: 7px 4px;
border-bottom-left-radius: 7px 4px;
}
.ribbon p{
margin: 0;
padding: 20px;
}