CSS Button to top-right corner of image (Gallery) - html

I am trying to position a close button (x) to the top-right corner of an image.
That's just before the footer of my page:
<div class="modal" id="modal">
<span class="close" id="close">✖</span>
<img class="modal-content" id="modal-content">
</div>
How I show the modal:
function showModal(name) {
modal.style.display = "block";
modalImg.src = document.getElementById(name).src;
}
And here is my styling:
/* Background when image is shown */
#modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(119, 119, 119); /* Fallback color */
background-color: rgba(119, 119, 119, 0.9); /* Black w/ opacity */
}
/* Image */
#modal-content {
/* Horizontally center image */
margin: auto;
/* Sizing */
display: block;
max-width: 90%;
max-height: calc(100vh * 0.5);
width: auto;
/* Zoom (image gets bigger) on open */
animation-name: zoom;
animation-duration: 0.6s;
/* Style */
border: 10px solid #ffffff;
box-shadow: rgba(0, 0, 0, 0.54) 0px 0px 7px 4px;
/* Vertically center image */
position: relative;
top: 40%;
transform: translateY(-40%);
}
#keyframes zoom {
from {
transform: scale(0)
}
to {
transform: scale(1)
}
}
/* Close Button */
#close {
/* Position */
position: absolute;
top: 10px;
right: 10px;
/* Style */
color: #ffffff;
font-size: 20px;
font-weight: bold;
transition: 0.3s;
background-color: #000000;
border: 3px solid #ffffff;
box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 25px 3px;
/* Makes the Button round */
border-radius: 50%;
padding-left: 7px;
padding-right: 7px;
padding-bottom: 3px;
}
/* Change cursor when pointing on button */
#close:hover,
#close:focus {
text-decoration: none;
cursor: pointer;
}
/* 100% image width on smaller screens */
#media only screen and (max-width: 700px) {
.modal-content {
width: 100%;
}
}
The problem is that
position: absolute;
top: 10px;
right: 10px;
positions the close button in the top-right corner of the page, not at the top right corner of the image.
How can I fix that?

The close element it's positioning relative to the closest positioned ancestor, in your case the modal div instead of the modal-content (as you wanted).
I recomend you to wrap either the modal-content and close "button" in a (relative) div, like this:
<div class="modal" id="modal">
<div id='modal-content' class='modal-content">
<span class="close" id="close">✖</span>
<img> //make img height/width to 100%
</div>
</div>
This should position the close button in the top-right position of the absolute div and the image inside this div.
If the close button doesn't appear, make sure it has a higher z-index than the image.
I made a codepen: https://codepen.io/jpaulet/pen/RwGxpxy

Related

Make CSS transition left to right

I am trying to make a menu bar open and close from right to left. I have looked at documentation and other posts and have not been able to get it to work.
As you can see the menu is on the right of the screen but opens from the wrong direction, I tried changing it to relative and changing all the values to no avail.
function openNav() {
document.getElementById("mySidebar").style.width = "250px";
document.getElementById("main").style.marginRight = "250px";
}
function closeNav() {
document.getElementById("mySidebar").style.width = "0";
document.getElementById("main").style.marginRight = "0";
}
#import url("https://fonts.googleapis.com/css?family=Nunito+Sans:900");
* {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
}
body {
font-family: "Nunito Sans";
overflow-x: hidden;
font-size: 60px;
}
video{
width: 100vw;
height: 100vh;
object-fit: cover;
top: 0;
left: 0;
}
.header {
position: absolute;
font-size: 130px;
color: #2C3939;
top: 50%;
left: 50%;
transform: translate(-0%, -50%);
}
.header2 {
position: absolute;
z-index: 1;
font-size: 30px;
color: #2C3939;
top: 40%;
left: 61%;
transform: translate(-0%, -50%);
}
/* The sidebar menu */
.sidebar {
height: 100%; /* 100% Full-height */
width: 0; /* 0 width - change this with JavaScript */
position: fixed; /* Stay in place */
z-index: 1; /* Stay on top */
top: 0;
left: 1200px;
background-color: #111; /* Black*/
overflow-x: hidden; /* Disable horizontal scroll */
padding-top: 60px; /* Place content 60px from the top */
transition: 0.5s; /* 0.5 second transition effect to slide in the sidebar */
}
/* The sidebar links */
.sidebar a {
float:right;
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #818181;
display: block;
transition: 0.3s;
}
/* When you mouse over the navigation links, change their color */
.sidebar a:hover {
color: #f1f1f1;
}
/* Position and style the close button (top right corner) */
.sidebar .closebtn {
position: relative;
top: 0;
right: 25px;
font-size: 36px;
margin-right: 50px;
}
/* The button used to open the sidebar */
.openbtn {
position: fixed;
top: 5%;
left: 95%;
transform: translate(-50%, -50%);
font-size: 80px;
cursor: pointer;
color: 2C3939;
padding: 10px 15px;
border: none;
z-index: 1;
}
.openbtn:hover {
background-color: #444;
}
/* Style page content - use this if you want to push the page content to the right when you open the side navigation */
/* On smaller screens, where height is less than 450px, change the style of the sidenav (less padding and a smaller font size) */
#media screen and (max-height: 450px) {
.sidebar a {font-size: 18px;}
}
<div id="mySidebar" class="sidebar">
×
About
Services
Clients
Contact
</div>
<div id="body">
<button class="openbtn" onclick="openNav()">
<img src="assets/SidebarIcon.png" width="26.25" height="43.75">
</button>
</div>
you need to set the container position to absolute, and give it :
right:0
top:0
.sidebar {
height: 100%; /* 100% Full-height */
width: 0; /* 0 width - change this with JavaScript */
z-index: 1; /* Stay on top */
position: absolute; /* Stay in place */
top: 0;
right: 0;
background-color: #111; /* Black*/
overflow-x: hidden; /* Disable horizontal scroll */
padding-top: 60px; /* Place content 60px from the top */
transition: 0.5s; /* 0.5 second transition effect to slide in the sidebar */
}
replace this with your sidebar class

Circle with transparent borders over background

How can I achieve such a thing in CSS?
I've tried so many ways but the dark background is still in the way and can't be clipped so the background image under it's invisible...
.item {
position: relative;
}
.item:before {
content: '';
size(100%);
top: 0;
left: 0;
z-index: 1;
background: rgba(0, 0, 0,0 0.1);
}
<div class="item">
<img>
<span class="rate">
<span class="amount">10</span> امتیاز
</span>
</div>
I'm looking for a way to be able to make parts of the dark background transparent, so the image can be seen.
This can be achieved using a radial gradient, (Example split onto separate lines to make it easier to read)
background-image: radial-gradient(
/* Position the circle at the center, 40px from the top */
circle at center 40px,
/* The center of the radius should be dark */
rgba(0,0,0,0.4) 0%,
/* This is the inner edge of the circle, we transition from dark-transparent between pixels 30 and 31 */
rgba(0,0,0,0.4) 30px, rgba(0,0,0,0) 31px,
/* This is the outer edge of the circle, we transition back from transprent-dark between pixels 34 and 35*/
rgba(0,0,0,0) 34px, rgba(0,0,0,0.4) 35px,
/* Everything outside of the circle should be dark */
rgba(0,0,0,0.4) 100%
);
Where circle at center 40px defines the position of the circle relative to the parent element (Horizontally centred, an 40px down from the top) bare in mind this is the position for the centre of the circle so you do need to account for it's radius.
And we use very small steps between the gradient to make it look like a solid line rather than a blurred gradient (I find that a 1px difference helps prevent aliasing on the line and makes everything look much smoother)
You can adjust the size of the circle or the thickness of the line by changing the 30px, 31px, 34px and 35px values in the gradient.
Working example:
.item {
position: relative;
width: 200px;
height: 200px;
background: url(https://picsum.photos/seed/picsum/200/200);
}
.item:before {
position: absolute;
content: '';
top: 0;
left: 0;
bottom: 0;
right: 0;
z-index: 1;
/* This is the ring itself, you can adjust it's size using the pixel values, leaving 1px differnce usually leaves the best result for smooth edges */
background-image: radial-gradient(circle at center 40px, rgba(0, 0, 0, 0.4) 0%, rgba(0, 0, 0, 0.4) 30px, rgba(0, 0, 0, 0) 31px, rgba(0, 0, 0, 0) 34px, rgba(0, 0, 0, 0.4) 35px, rgba(0, 0, 0, 0.4) 100%);
}
<div class="item"></div>
(This method is browser compatible with pretty much every browser released since 2010)
Infinite box-shadow with overflow: hidden; I don't know if it would work for you, I just tried-
<style>
.item img {
max-width: 100%;
vertical-align: top;
}
.item {
font-family: 'Amiri', serif;
width: 300px;
margin: 20px auto;
overflow: hidden; /* STEP-1 */
position: relative;
}
.rate {
position: absolute;
width: 100px;
height: 100px;
border-radius: 100%;
background: rgba(0,0,0,.7);
top: 80px;
left: 50%;
transform: translatex(-50%);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: 22px;
color: #fff;
}
.rate::before {
position: absolute;
content: '';
width: calc(100% + 10px);
height: calc(100% + 10px);
top: -5px;
left: 50%;
transform: translatex(-50%);
border-radius: 100%;
box-shadow: 0 0 0 100vh rgba(0,0,0,.7); /* STEP-2 */
}
.amount {
font-size: 20px;
font-weight: 700;
display: block;
}
</style>
<link href="https://fonts.googleapis.com/css2?family=Amiri:wght#400;700&display=swap" rel="stylesheet">
<div class="item">
<img src="https://images.pexels.com/photos/4888690/pexels-photo-4888690.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940" alt="Card title">
<span class="rate">
<span class="amount">١٠</span> امتیاز
</span>
</div>
You could use a few divs with position: absolute:
body {
margin: 0;
}
.container {
display: flex;
justify-content: center;
align-items: center;
}
.bg {
height: 100vh;
width: 100%;
background-image: url('https://i.ytimg.com/vi/fqumdSlyLxg/maxresdefault.jpg');
filter: brightness(0.4);
}
.circle {
position: absolute;
height: 150px;
width: 150px;
border-radius: 50%;
backdrop-filter: brightness(5);
-webkit-backdrop-filter: brightness(5);
z-index: 0;
}
.inner-circle {
position: absolute;
height: 142px;
width: 142px;
border-radius: 50%;
backdrop-filter: brightness(0.2);
-webkit-backdrop-filter: brightness(0.2);
z-index: 1;
}
.rate {
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-evenly;
position: absolute;
height: 142px;
color: white;
z-index: 2;
}
.amount {
font-size: 30px;
border-radius: 50%;
text-shadow: 0px 0px 5px #fff;
}
<div class="container">
<div class="bg"></div>
<div class="circle"></div>
<div class="inner-circle"></div>
<div class="rate">
<span class="amount">10</span>
<span class="amount">امتیاز</span>
</div>
</div>
Use the backdrop-filter property to set the brightness and display: flex on the container to center everything, then for the text use text-shadow to make it luminous.
As an alternative, I made .item and its child elements Flexbox containers for easy positioning.
The circle is simply a circular element with a border.
All you have to do now is fiddle with sizes, colors and tranparency.
For the fun of it I added some :hover effects...
snippet with comments
/* All are FBL containers, for easy positioning */
.item, .item>*, .rate {
display: flex;
justify-content: center; align-items: center;
}
.rate { flex-direction: column }
/* item content */
.item {
position: relative; /* position child elements to this parent */
width: 400px;
height: 600px;
/* set image to background of item */
background-image: url("https://i.ytimg.com/vi/fqumdSlyLxg/maxresdefault.jpg");
background-repeat: no-repeat;
background-size: cover; /* clip/stretch when too large/small */
background-color: rgba(0,0,0,0.3); /* some tranparent black */
background-blend-mode: overlay; /* mix bg-color with image */
/* eye-candy */
margin: 5rem auto; /* center */
font-size: 1.5em;
font-weight: bold;
color: rgba(255,255,255,.6);
border-radius: 12px;
}
.item>* {
position: absolute; /* position child inside parent */
width : 100px; height: 100px;
opacity: 0.7;
}
.rate { text-shadow: 0px 0px 7px rgba(255,255,255,.8) }
.circle {
border: 5px solid rgba(255,255,255,.3);
border-radius: 50%;
filter: blur(1px);
}
/******************************/
/* HOVER eye-candy, demo only */
/******************************/
.item:hover {
background-blend-mode: normal;
color: rgba(255,255,255,1);
}
.item:hover>* {
opacity: 1;
}
.item:hover .circle {
border-color: rgba(255,255,255,.8);
}
/* demo eye-candy */
.item {
/* GMC elevation 1dp */
box-shadow: 0px 2px 1px -1px rgba(0,0,0,.20),
0px 1px 1px 0px rgba(0,0,0,.14),
0px 1px 3px 0px rgba(0,0,0,.12);
}
.item:hover {
transform: scale(1.01);
/* GMC elevation 3dp */
box-shadow: 0px 3px 3px -2px rgba(0,0,0,.20),
0px 3px 4px 0px rgba(0,0,0,.14),
0px 1px 8px 0px rgba(0,0,0,.12);
}
/*.item:active:not(:focus) { transform: scale(1) }/* enable for some animation */
<div class="item">
<div class="circle"></div>
<div class="rate">
<span class="amount">10</span>
<span>text</span>
</div>
</div>

How to fix Sidenav showing in Chrome but not Safari - (Angular 7/Bootstrap project)

My side-nav appears and functions perfectly in Chrome but not in Safari. Trying to find the code that is making it break. Here are some photos that show the two side-navs. Chrome is the one that works and Safari is the blank one.
I've already tried going into dev tools on both Safari and Chrome to check if any CSS styling attributes have been crossed out but they all seem to be there.
<div id="mySidenav" class="sidenav custom-underline">
×
<div class="nav-items">
Home
Videos
Art
Graphic Design
Contact
</div>
</div>
and CSS
.nav-items a:hover{
background-color: rgb(214, 0, 0);
}
i{
color: white;
}
/* The side navigation menu */
.sidenav {
height: 100%; /* 100% Full-height */
width: 0; /* 0 width - change this with JavaScript */
position: fixed; /* Stay in place */
z-index: 1; /* Stay on top */
top: 0; /* Stay at the top */
left: 0;
background-color: rgb(0, 0, 0); /* Black*/
overflow-x: hidden; /* Disable horizontal scroll */
padding-top: 60px; /* Place content 60px from the top */
transition: 0.5s; /* 0.5 second transition effect to slide in the sidenav */
}
/* The navigation menu links */
.sidenav a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #818181;
display: block;
transition: 0.3s;
}
/* When you mouse over the navigation links, change their color */
.sidenav a:hover {
color: #f1f1f1;
}
/* Position and style the close button (top right corner) */
.sidenav .closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 36px;
margin-left: 50px;
}
.nav-logo{
height: 200px;
display: block;
margin: auto;
margin-bottom: 50px;
}
.closebtn{
margin-top: 8px;
}
#video-icon{
float:left;
margin-right:10px;
position: relative;
top:9px;
}
/* Style page content - use this if you want to push the page content to the right when you open the side navigation */
#main {
transition: margin-left .5s;
padding: 20px;
color: black;
background-color: rgb(0, 0, 0);
height: 200px;
}
/* On smaller screens, where height is less than 450px, change the style of the sidenav (less padding and a smaller font size) */
#media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}

Style tab-bar like in Chrome?

I'm trying to recreate Google Chrome's tab bar as accurately as possible with HTML/CSS. But it turns out to be quite a bit more complicated than I thought.
It already looks pretty similar, but I noticed several issues:
when the tabs are resized the angles get messed up
the z-indexing doesn't work as expected
the hover events don't work
where tabs overlap it looks bad
text is not vertically centered (in Firefox it works actually)
the tabs are lacking curves on the bottom
the x buttons don't stick to the right
Any ideas?
I tried to look at chromes source code to see if I could find the original color/transparency/curve values, but I couldn't find anything.
Before I forget, if possible in any way, I'd like this to be more or less compatible with IE8, even if that means that the tabs can't be trapezoid shaped etc.
EDIT2: Rewrote the whole thing from scratch. (Credits to Ben Rhys-Lewis for the new-tab-button)
https://jsfiddle.net/p7vxzLjq/17/
body {
background: #21C256; /* green windows theme */
/* using transparency the tabbar should automatically adjust itself to whatever color is defined here */
}
.tab-bar {
height: 23px; /* tab height */
cursor: default;
user-select: none; /* disable text selection */
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
pointer-events: none; /* disable image drag */
margin: 0;
padding: 0px 7px 0px 7px;
}
.tab {
background: #FFFFFF; /* inactive tab background color */
opacity: 0.726; /* inactive tab transparency */
width: 213px; /* tab width */
//max-width: 213px; /* messes up the trapezoid angles */
margin-left: 0px; /* tab overlap */
float: left;
overflow: hidden;
height: 100%;
/*padding-bottom: 1px;*/
border-radius: 3px; /* tab curves */
transform: perspective(100px) rotateX(20deg); /* tab shape angle */
box-shadow: 0 0 2pt 0 rgba(0, 0, 0, 0.9); /* tab outline */
white-space: nowrap;
padding-left: 8px; /* icon left side margin */
display: block;
vertical-align: middle;
z-index: -2; /* inactive tabs are generally in the background */
}
.tab:hover {
opacity: 0.8;
}
.tab-content {
transform: perspective(100px) rotateX(-20deg); /* untransform tab content (this makes stuff blurry! :( ) */
-o-transform: perspective(100px) rotateX(-20deg);
-ms-transform: perspective(100px) rotateX(-20deg);
-moz-transform: perspective(100px) rotateX(-20deg);
-webkit-transform: perspective(100px) rotateX(-20deg);
-khtml-transform: perspective(100px) rotateX(-20deg);
}
.tab-icon {
display: inline-block;
vertical-align: middle;
width: 16px;
height: 16px;
}
.tab-text {
display: inline-block;
vertical-align: middle;
font-family: arial, sans-serif; /* tab text font */
text-rendering: geometricPrecision; /* tab text improve rendering */
font-size: 12px; /* tab text size */
-webkit-mask-image: linear-gradient(to right, #000, #000, 200px, transparent); /* make text fade at the right edge (webkit only)*/
}
.tab-close {
display: inline-block;
vertical-align: middle;
width: 16px;
height: 16px;
right: 5px;
background: url(http://250kb.de/u/160430/p/YlimbFeb56qF.png);
}
.tab-close:hover {
background: url(http://250kb.de/u/160430/p/rNqZRYHpNQBr.png);
}
.active-tab {
z-index: -1; /* active tab is in front of other tabs, but still behind the content box */
background: linear-gradient(to bottom, #FFFFFF, #F8F9F9); /* active tab color */
position: relative;
opacity: 1;
padding-bottom: 2px;
}
.active-tab:hover {
opacity: 1;
}
.new-tab {
overflow: hidden;
float: left;
width: 25px; /* new-tab-button width */
height: 14px; /* new-tab-button height */
margin-top: 5px; /* to vertically center the new-tab-button */
margin-left: 7px; /* margin between tabs and new-tab-button */
box-shadow: 0 0 1pt 0 rgba(0, 0, 0, 0.9); /* new-tab-button outline */
background: #FFFFFF; /* new-tab-button color */
opacity: 0.626; /* new-tab-button transparency */
border-radius: 2px; /* new-tab-button curves */
transform: skew(20deg); /* new-tab-button shape angle */
-o-transform: skew(20deg);
-ms-transform: skew(20deg);
-moz-transform: skew(20deg);
-khtml-transform: skew(20deg);
-webkit-transform: skew(20deg);
}
.new-tab:hover {
opacity: 0.8;
}
#content {
z-index: 1; /* the content box is always in the foreground */
width: 100%;
height: 50px;
background: #F8F9F8;
border-radius: 3px;
}
<ul class="tab-bar">
<li class="tab">
<div class="tab-content">
<img class="tab-icon" src="http://amazon.com/favicon.ico"/>
<span class="tab-text">Amazon.com: Online Shopping for Electronics, Apparel, Computers, Books, DVDs & more</span>
<span class="tab-close"></span>
</div>
</li>
<li class="tab active-tab">
<div class="tab-content">
<img class="tab-icon" src="http://google.com/favicon.ico"/>
<span class="tab-text">Google</span>
<span class="tab-close"></span>
</div>
</li>
<li class="new-tab"></li>
</ul>
<div id="content">
</div>
OK here is a fiddle of a css shape like the new tab one you want.
#newtab {
width: 150px;
height: 100px;
-webkit-transform: skew(20deg);
-moz-transform: skew(20deg);
-o-transform: skew(20deg);
background: #A8D5C1;
margin-left: 20px;
border-radius: 10px;
}
https://jsfiddle.net/2p74co0q/
For the transparency values, its hard to see from your image but I guess just trial and error. Obviously how your chrome looks is different to how mine looks because of the theme you are using.
Had to change many things for it to work properly. Here is the Fiddle. Some notes on changes:
Hover didn't work because of pointer-events property on tab class. You can put it under tab-close class or you can use jQuery solution for it to work in old browsers.
I don't see any reason to use negative z-index. I didn't use and it seems to work.
For vertical-align to work properly, you should have a constant line-height. Added line-height property to tab class and made all sub classes inherit it so that they will be aligned to middle properly. Also had to wrap images with extra divs for them to align properly.
About the overlap, if you want a result as in Chrome tabs, you should not use opacity. No matter what you do, if you have opacity, result will look like that. You can use constant color instead.
For bottom curve and shadow added new elements. Not sure if it is a must but it looks more like Chrome tabs.
For it to work in IE8
I tested it on IE8 and it did not look pleasant. Don't know where to start. Here are some thoughts:
vertical-align will not work reliably. You can ditch everything with vertical-align and use constant absolute positioning. This means you cannot change tab sizes as you want and you must chose a constant one.
You must write filter equivalents of all transform and opacity properties. Your css will look like the darkest place of hell.
border-radius will not work. There are some dirty workarounds which I do not suggest. Same for box-shadow.
body {
background: #21C256;
/* green windows theme */
/* using transparency the tabbar should automatically adjust itself to whatever color is defined here */
}
.tab-bar {
height: 26px;
/* tab height */
line-height: 26px;
/* this is critical for vertical alligning */
cursor: default;
user-select: none;
/* disable text selection */
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
margin: 0;
padding: 0px 7px 0px 7px;
z-index: 0;
white-space: nowrap;
display: block;
overflow: hidden;
width: 100%;
margin: 0;
font-size: 0;
}
.tab-bottom-curve-left {
background: inherit;
border: inherit;
opacity: inherit;
border-left: none;
border-bottom: none;
width: 10px;
height: 4px;
position: absolute;
left: -5px;
bottom: -2px;
z-index: 5;
transform: rotate(-31deg);
}
.tab-bottom-curve-right {
background: inherit;
border: inherit;
opacity: inherit;
border-left: none;
border-bottom: none;
width: 10px;
height: 4px;
position: absolute;
right: -5px;
bottom: -2px;
transform: rotate(31deg);
/* box-shadow: inherit; */
z-index: 0;
}
.tab-icon {
pointer-events: none;
/* disable image drag */
}
.tab-text {
width: 80%;
height: 100%;
padding-left: 4px;
}
.tab {
background: #FFFFFF;
/* inactive tab background color */
opacity: 0.726;
/* inactive tab transparency */
width: 213px;
/* tab width */
margin-left: 0px;
/* tab overlap */
overflow: hidden;
height: 100%;
/*padding-bottom: 1px;*/
border-radius: 3px;
/* tab curves */
transform: perspective(100px) rotateX(20deg);
/* tab shape angle */
box-shadow: 0 0 2pt 0 rgba(0, 0, 0, 0.9);
/* tab outline */
white-space: nowrap;
padding-left: 8px;
/* icon left side margin */
vertical-align: middle;
z-index: 1;
/* inactive tabs are generally in the background */
line-height: inherit;
/* margin-left: -1px; */
/* margin-right: -1px; */
/* margin-top: -6px; */
height: 100%;
vertical-align: top;
font-size: 0;
margin-top: 1px;
overflow: visible;
position: relative;
display: inline-block;
float: left;
display: block;
}
.tab:hover {
opacity: 0.8;
}
.tab-content {
transform: perspective(100px) rotateX(-20deg);
/* untransform tab content (this makes stuff blurry! :( ) */
-o-transform: perspective(100px) rotateX(-20deg);
-ms-transform: perspective(100px) rotateX(-20deg);
-moz-transform: perspective(100px) rotateX(-20deg);
-webkit-transform: perspective(100px) rotateX(-20deg);
-khtml-transform: perspective(100px) rotateX(-20deg);
line-height: inherit;
z-index: 5;
height: 100%;
font-size: 0;
overflow: hidden;
/* position: absolute; */
}
.tab-icon {
display: inline-block;
vertical-align: middle;
width: 16px;
height: 16px;
}
.tab-text {
display: inline-block;
vertical-align: middle;
font-family: arial, sans-serif;
/* tab text font */
text-rendering: geometricPrecision;
/* tab text improve rendering */
font-size: 12px;
/* tab text size */
-webkit-mask-image: linear-gradient(to right, #000, #000, 165px, transparent);
/* make text fade at the right edge (webkit only)*/
overflow: hidden;
}
.tab-close {
display: inline-block;
height: 100%;
width: 16px;
line-height: inherit;
right: 5px;
position: absolute;
z-index: 100000;
vertical-align: middle;
}
.tab-close-img {
display: inline-block;
position: relative;
vertical-align: middle;
width: 16px;
height: 16px;
background: url(http://250kb.de/u/160430/p/YlimbFeb56qF.png);
}
.tab-close-img:hover {
background: url(http://250kb.de/u/160430/p/rNqZRYHpNQBr.png);
}
.active-tab {
z-index: 2;
/* active tab is in front of other tabs, but still behind the content box */
background: linear-gradient(to bottom, #FFFFFF, #F8F9F9);
/* active tab color */
/* position: relative; */
opacity: 1;
/* padding-bottom: 2px; */
}
.active-tab:hover {
opacity: 1;
}
.new-tab {
overflow: hidden;
width: 25px;
/* new-tab-button width */
height: 14px;
/* new-tab-button height */
/* margin-top: 7px; */
/* to vertically center the new-tab-button */
margin-left: 6px;
/* margin between tabs and new-tab-button */
vertical-align: middle;
box-shadow: 0 0 1pt 0 rgba(0, 0, 0, 0.9);
/* new-tab-button outline */
background: #FFFFFF;
/* new-tab-button color */
opacity: 0.626;
/* new-tab-button transparency */
border-radius: 2px;
/* new-tab-button curves */
transform: skew(20deg);
/* new-tab-button shape angle */
-o-transform: skew(20deg);
-ms-transform: skew(20deg);
-moz-transform: skew(20deg);
-khtml-transform: skew(20deg);
-webkit-transform: skew(20deg);
display: inline-block;
}
.new-tab:hover {
opacity: 0.8;
}
#content {
position: absolute;
z-index: 3;
/* the content box is always in the foreground */
width: 100%;
height: 50px;
background: #F8F9F8;
border-radius: 3px;
}
.tab-bottom-shadow {
/* width: 100%; */
position: absolute;
background: black;
height: 1px;
bottom: -1px;
left: 0px;
right: 0;
box-shadow: 0 0 4px black;
z-index: 5;
}
.active-tab .tab-bottom-shadow {
display: none;
}
<div class="tab-bar">
<div class="tab">
<div class="tab-content">
<span class="tab-icon-wrap"><img class="tab-icon" src="http://amazon.com/favicon.ico" /></span>
<span class="tab-text">Amazon.com: Online Shopping for Electronics, Apparel, Computers, Books, DVDs & more</span>
<span class="tab-close"><span class="tab-close-img"></span></span>
</div>
<div class="tab-bottom-curve-left"></div>
<div class="tab-bottom-curve-right"></div>
<div class="tab-bottom-shadow"></div>
</div>
<div class="tab">
<div class="tab-content">
<span class="tab-icon-wrap"><img class="tab-icon" src="http://youtube.com/favicon.ico" /></span>
<span class="tab-text">YouTube</span>
<span class="tab-close"><span class="tab-close-img"></span></span>
</div>
<div class="tab-bottom-curve-left"></div>
<div class="tab-bottom-curve-right"></div>
<div class="tab-bottom-shadow"></div>
</div>
<div class="tab active-tab">
<div class="tab-content">
<span class="tab-icon-wrap"><img class="tab-icon" src="http://google.com/favicon.ico" /></span>
<span class="tab-text">Google</span>
<span class="tab-close"><span class="tab-close-img"></span></span>
</div>
<div class="tab-bottom-curve-left"></div>
<div class="tab-bottom-curve-right"></div>
<div class="tab-bottom-shadow"></div>
</div>
<div class="new-tab"></div>
</div>
<div id="content">
</div>
Do you have to use pure CSS? Or can you use image mapping. That way, you can create links, hover events with minimal effort, which achieve the same effect.
http://www.image-maps.com/ is a great tool to use for projects like this. You could use the polygon tool to select the buttons.
Don't worry if this isn't what you're looking for.
Please use the below code. I think this is what you are looking for. Demo
body {
background: #21C256; /* green windows theme */
/* using transparency the tabbar should automatically adjust itself to whatever color is defined here */
}
.tab-bar {
height: 23px; /* tab height */
cursor: default;
display: flex;
user-select: none; /* disable text selection */
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
pointer-events: none; /* disable image drag */
margin: 0;
padding: 0px 7px 0px 7px;
}
.tab {
background: #FFFFFF; /* inactive tab background color */
opacity: 0.726; /* inactive tab transparency */
width: 213px; /* tab width */
//max-width: 213px; /* messes up the trapezoid angles */
margin-left: 0px; /* tab overlap */
float: left;
overflow: hidden;
height: 100%;
display: flex;
/*padding-bottom: 1px;*/
border-radius: 3px; /* tab curves */
transform: perspective(100px) rotateX(20deg); /* tab shape angle */
box-shadow: 0 0 2pt 0 rgba(0, 0, 0, 0.9); /* tab outline */
white-space: nowrap;
padding-left: 8px; /* icon left side margin */
display: block;
vertical-align: middle;
z-index: -2; /* inactive tabs are generally in the background */
}
.tab:hover {
opacity: 0.8;
}
.tab-content {
display: flex;
justify-content: space-between;
padding: 4px 9px 0px 0px;
transform: perspective(100px) rotateX(-20deg); /* untransform tab content (this makes stuff blurry! :( ) */
-o-transform: perspective(100px) rotateX(-20deg);
-ms-transform: perspective(100px) rotateX(-20deg);
-moz-transform: perspective(100px) rotateX(-20deg);
-webkit-transform: perspective(100px) rotateX(-20deg);
-khtml-transform: perspective(100px) rotateX(-20deg);
}
.tab-icon {
display: inline-block;
vertical-align: middle;
width: 16px;
height: 16px;
}
.tab-text {
display: inline-block;
text-align: left;
width: 76%;
vertical-align: middle;
font-family: arial, sans-serif; /* tab text font */
text-rendering: geometricPrecision; /* tab text improve rendering */
font-size: 12px; /* tab text size */
-webkit-mask-image: linear-gradient(to right, #000, #000, 200px, transparent); /* make text fade at the right edge (webkit only)*/
}
.tab-close {
display: inline-block;
vertical-align: middle;
width: 16px;
height: 16px;
right: 5px;
background: url(http://250kb.de/u/160430/p/YlimbFeb56qF.png);
}
.tab-close:hover {
background: url(http://250kb.de/u/160430/p/rNqZRYHpNQBr.png);
}
.active-tab {
z-index: -1; /* active tab is in front of other tabs, but still behind the content box */
background: linear-gradient(to bottom, #FFFFFF, #F8F9F9); /* active tab color */
position: relative;
opacity: 1;
padding-bottom: 2px;
}
.active-tab:hover {
opacity: 1;
}
.new-tab {
overflow: hidden;
float: left;
width: 25px; /* new-tab-button width */
height: 14px; /* new-tab-button height */
margin-top: 5px; /* to vertically center the new-tab-button */
margin-left: 7px; /* margin between tabs and new-tab-button */
box-shadow: 0 0 1pt 0 rgba(0, 0, 0, 0.9); /* new-tab-button outline */
background: #FFFFFF; /* new-tab-button color */
opacity: 0.626; /* new-tab-button transparency */
border-radius: 2px; /* new-tab-button curves */
transform: skew(20deg); /* new-tab-button shape angle */
-o-transform: skew(20deg);
-ms-transform: skew(20deg);
-moz-transform: skew(20deg);
-khtml-transform: skew(20deg);
-webkit-transform: skew(20deg);
}
.new-tab:hover {
opacity: 0.8;
}
#content {
z-index: 1; /* the content box is always in the foreground */
width: 100%;
height: 50px;
background: #F8F9F8;
border-radius: 3px;
}
If you want that the tabs overlap properly, you have to get remove the transparency. My solution also includes various other improvements:
body {
background: #21C256; /* green windows theme */
/* using transparency the tabbar should automatically adjust itself to whatever color is defined here */
}
.tab-bar {
height: 25px; /* tab height */
cursor: default;
user-select: none; /* disable text selection */
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
pointer-events: none; /* disable image drag */
margin: 0;
padding: 0px 7px;
}
.tab {
background: #BAF1CB; /* inactive tab background color */
opacity: 1; /* inactive tab transparency */
width: 213px; /* tab width */
margin-left: 0px; /* tab overlap */
float: left;
overflow: hidden;
height: 100%;
padding: 1px 0;
border-radius: 3px; /* tab curves */
transform: perspective(100px) rotateX(20deg); /* tab shape angle */
box-shadow: 2px -2px 2px -2px black, -2px -1px 2px -2px black; /* tab outline */
white-space: nowrap;
padding-left: 8px; /* icon left side margin */
display: block;
vertical-align: middle;
z-index: -2; /* inactive tabs are generally in the background */
}
.tab:hover {
background-color: #D0F5DB;
}
.tab-content {
padding: 2px 0;
transform: perspective(100px) rotateX(-20deg); /* untransform tab content (this makes stuff blurry! :( ) */
-o-transform: perspective(100px) rotateX(-20deg);
-ms-transform: perspective(100px) rotateX(-20deg);
-moz-transform: perspective(100px) rotateX(-20deg);
-webkit-transform: perspective(100px) rotateX(-20deg);
-khtml-transform: perspective(100px) rotateX(-20deg);
}
.tab-icon {
display: inline-block;
vertical-align: middle;
width: 16px;
height: 16px;
}
.tab-text {
display: inline-block;
vertical-align: middle;
font-family: arial, sans-serif; /* tab text font */
text-rendering: geometricPrecision; /* tab text improve rendering */
font-size: 12px; /* tab text size */
-webkit-mask-image: linear-gradient(to right, #000, #000, 200px, transparent); /* make text fade at the right edge (webkit only)*/
max-width: 170px;
overflow: hidden;
}
.tab-close {
float: right;
display: inline-block;
vertical-align: middle;
width: 16px;
height: 16px;
margin: 3px 5px 0 0;
background: url(http://250kb.de/u/160430/p/YlimbFeb56qF.png);
}
.tab-close:hover {
background: url(http://250kb.de/u/160430/p/rNqZRYHpNQBr.png);
}
.active-tab {
z-index: 1000000; /* active tab is in front of other tabs, but still behind the content box */
background: linear-gradient(to bottom, #FFFFFF, #F8F9F9); /* active tab color */
position: relative;
opacity: 1;
padding-bottom: 2px;
}
.active-tab:hover {
opacity: 1;
}
.new-tab {
overflow: hidden;
float: left;
width: 25px; /* new-tab-button width */
height: 14px; /* new-tab-button height */
margin-top: 5px; /* to vertically center the new-tab-button */
margin-left: 7px; /* margin between tabs and new-tab-button */
box-shadow: 0 0 1pt 0 rgba(0, 0, 0, 0.9); /* new-tab-button outline */
background: #FFFFFF; /* new-tab-button color */
opacity: 0.65; /* new-tab-button transparency */
border-radius: 2px; /* new-tab-button curves */
transform: skew(20deg); /* new-tab-button shape angle */
-o-transform: skew(20deg);
-ms-transform: skew(20deg);
-moz-transform: skew(20deg);
-khtml-transform: skew(20deg);
-webkit-transform: skew(20deg);
}
.new-tab:hover {
opacity: 0.8;
}
#content {
position: relative;
z-index: 2; /* the content box is always in the foreground */
width: 100%;
height: 50px;
background: #F8F9F8;
border-radius: 3px;
border: 1px solid #aaaaaa;
border-width: 1px 0 0 0;
}
<ul class="tab-bar">
<li class="tab">
<div class="tab-content">
<!-- Move the close-Button to the beginning -->
<span class="tab-close"></span>
<img class="tab-icon" src="http://amazon.com/favicon.ico"/>
<span class="tab-text">Amazon.com: Online Shopping for Electronics, Apparel, Computers, Books, DVDs & more</span>
</div>
</li>
<li class="tab active-tab">
<div class="tab-content">
<span class="tab-close"></span>
<img class="tab-icon" src="http://google.com/favicon.ico"/>
<span class="tab-text">Google</span>
</div>
</li>
<li class="new-tab"></li>
</ul>
<div id="content">
</div>

transparent shape with arrow in upper corner

Please see the image below.
I want to add an arrow to the top right of a div which I am treating as editable input box.
Please help me how I can achieve this using CSS.
I cannot use a SVG since I need this as a div to show emoticons as images over it.
<div placeholder="Your message" id="Message">
...
</div>
You can do it like in the below snippet. The method used to achieve the shape is as given below:
The main div element only has a top, bottom and left border. The right border is nullified because the element and its arrows needs to be transparent. With a transparent arrow, if a right border is present that would also get displayed.
The arrow on the right is achieved using a skewed element placed with respect to the right edge of the shape.
The right border of the shape is achieved by using another pseudo-element whose size is the same as the height of the whole container - height of the arrow pseudo-element. This element is positioned with respect to the bottom right of the shape.
You can adjust the height and border-radius as required. I have set the positioning such that even a change in height/width of parent would not affect it.
div.shape {
position: relative;
width: 300px;
height: 100px;
padding: 4px;
margin-top: 20px;
border: 2px solid gray;
border-right: none; /* not required as the shape needs to be transparent */
border-radius: 8px; /* not required as the right border is done through pseudo element */
border-top-right-radius: 0px;
border-bottom-right-radius: 0px;
}
div.shape:before {
position: absolute;
content: '';
top: -2px; /* equal to border top of parent - no need to change*/
right: -6px; /* for positioning - no need to change*/
height: 15%; /* should be changed depending on height of arrow */
width: 10%; /* should be changed depending on width of arrow */
border-top: 2px solid gray;
border-right: 3px solid gray; /* thicker border because skew makes it thin */
/* to achieve the arrow like shape */
-webkit-transform-origin: bottom right;
-webkit-transform: skew(-45deg);
-moz-transform: skew(-45deg);
transform: skew(-45deg);
}
div.shape:after {
position: absolute;
content: '';
right: -6px; /* for positioning - no need to change*/
height: 85%; /* height of parent - height of arrow */
width: 2%; /* no need to change */
bottom: -2px; /* equal to border bottom of parent - no need to change*/
border-right: 2px solid gray;
border-bottom: 2px solid gray;
border-bottom-right-radius: 8px; /* for producing curve on bottom right */
}
/* Just for demo */
body {
background: -webkit-linear-gradient(0deg, crimson, indianred, purple);
background: -moz-linear-gradient(90deg, crimson, indianred, purple);
background: linear-gradient(90deg, crimson, indianred, purple);
}
<div class="shape">
Lorem Ipsum Dolor Sit Amet...
</div>
The arrow can be added to the left side by changing the positioning attributes and the skew direction (from positive angle to negative angle) like in the below snippet.
div.shape {
position: relative;
width: 300px;
height: 100px;
padding: 4px;
margin-top: 20px;
margin-left: 20px;
border: 2px solid gray;
border-left: none; /* not required as the shape needs to be transparent */
border-radius: 8px; /* not required as the right border is done through pseudo element */
border-top-left-radius: 0px;
border-bottom-left-radius: 0px;
}
div.shape:before {
position: absolute;
content: '';
top: -2px; /* equal to border top of parent - no need to change*/
left: -6px; /* for positioning - no need to change*/
height: 15%; /* should be changed depending on height of arrow */
width: 10%; /* should be changed depending on width of arrow */
border-top: 2px solid gray;
border-left: 3px solid gray; /* thicker border because skew makes it thin */
/* to achieve the arrow like shape */
-webkit-transform-origin: bottom right;
-webkit-transform: skew(45deg);
-moz-transform: skew(45deg);
transform: skew(45deg);
}
div.shape:after {
position: absolute;
content: '';
left: -6px; /* for positioning - no need to change*/
height: 85%; /* height of parent - height of arrow */
width: 2%; /* no need to change */
bottom: -2px; /* equal to border bottom of parent - no need to change*/
border-left: 2px solid gray;
border-bottom: 2px solid gray;
border-bottom-left-radius: 8px; /* for producing curve on bottom right */
}
/* Just for demo */
body {
background: -webkit-linear-gradient(0deg, crimson, indianred, purple);
background: -moz-linear-gradient(90deg, crimson, indianred, purple);
background: linear-gradient(90deg, crimson, indianred, purple);
}
<div class="shape">
Lorem Ipsum Dolor Sit Amet...
</div>
Filter: drop-shadow()
The compatibility is limited
Yet the effect is pretty cool :P
.inputcontainer {
display: inline-block;
position: relative;
filter: drop-shadow(0px 0px 5px black);
-webkit-filter: drop-shadow(0px 0px 1px black);
}
.input {
display: inline-block;
border: none;
border-radius: 10px;
border-top-right-radius: 0px;
width: 280px;
height: 50px;
background-color: white;
padding-left: 20px;
font-size: 20px;
}
.input:focus {
outline: none;
}
.arrow {
position: absolute;
display: inline-block;
top: 0;
right: -5px;
width: 20px;
height: 20px;
background-color: white;
transform: skew(-45deg);
z-index: -1;
}
<div class="inputcontainer">
<input type="text" class="input" placeholder="Your message"/>
<div class="arrow"></div>
</div>
Box-shadow:
Here the compatibility is a lot better
.inputcontainer {
display: inline-block;
position: relative;
filter: drop-shadow(0px 0px 5px black);
}
.input {
display: inline-block;
border: none;
border-radius: 10px;
border-top-right-radius: 0px;
width: 280px;
height: 50px;
background-color: white;
padding-left: 20px;
font-size: 20px;
box-shadow: 0px 0px 0px 2px gray;
}
.input:focus {
outline: none;
}
.arrow {
position: absolute;
display: inline-block;
top: 0;
right: -8px;
width: 20px;
height: 20px;
background-color: white;
transform: skew(-45deg);
box-shadow: 2px -2px 0px 0px gray;
}
<div class="inputcontainer">
<input type="text" class="input" placeholder="Your message"/>
<div class="arrow"></div>
</div>