I'm building a website with a lot of images. The concept is of a galaxy so you can imagine I have a number of round planets and I want to make them clickable buttons.
These planets are in PNG format with transparent background and I want the clickable area to only be the non-transparent area (which is the shape of a circle). However, I have not found a possible solution to do this.
I have also tried to put a transparent circle on top of the image, and put <a href> on the transparent circle instead of on the image, but this does not seem to work either.
What makes it worse is that I have overlapping images which might cause some of the solutions I found not working. For example I have two or three overlapping images and I want them all to be a button (linking to different pages) (and I have another image in its background) so I don't know what's going to happen if I click at the intersection of these buttons.
Some of the solutions I've tried are:
http://jsfiddle.net/josedvq/Jyjjx/45/
http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_areamap
http://jsfiddle.net/DsW9h/
http://bryanhadaway.com/how-to-create-circles-with-css/
A snippet of my code:
HTML
<div>
<a href="~/SomePage">
<img draggable="false" class="AIcon" src="~/Content/Aicon.png" id="AI">
</a>
</div>
CSS
.AIcon{
position:absolute; left: 50%; top: 40%; width: 2.5%; height:5%; opacity: 1;
-webkit-animation: AAAIcon .5s linear 0s 1 normal forwards running;
}
#-webkit-keyframes AAAIcon {
0% {left: 50%; top: 40%; width: 2.5%; height:5%; opacity: 0; z-index:4;}
100% {left: 78%; top: 20%; width: 32%; height:32%; opacity: 1; z-index:4;}
}
As it is now the image is clickable within the whole square of the image, including the transparent area, but not all of the area is clickable (there are some patches in the image where it's just not clickable).
This is driving me nuts. Any pointers would be extremely helpful.
You have three ways to do it:
1- In the following snippet, I have used a css circle inside an image div on the first moon.
2- Alternatively, got the same result on the second moon placing the circle on div:after.
3- A third method is simply the opposite of the second: create a transparent circle and let the moon image on :after.
The first and third methods allow you to use the moon as a link with onclick javascript mouse event. The red element is set with pointer-events: none; so it have no effect on the moons' hovers.
body {
margin:0px;
background: black;
overflow: hidden;
}
#circle1 {
width: 200px;
height: 200px;
background: purple;
-moz-border-radius: 100px;
-webkit-border-radius: 100px;
border-radius: 100px;
cursor: pointer;
opacity: 0.2;
}
#image1 {
display: inline-block;
width: 200px;
height: 200px;
position: relative;
background: url('http://i.imgur.com/YAWvTuu.png');
background-repeat: no-repeat;
background-size: 100% 100%;
}
#image2 {
display: inline-block;
width: 200px;
height: 200px;
position: relative;
background: url('http://i.imgur.com/YAWvTuu.png');
background-repeat: no-repeat;
background-size: 100% 100%;
}
#image2:after {
content:"";
display: inline-block;
width: 200px;
height: 200px;
background: orange;
-moz-border-radius: 100px;
-webkit-border-radius: 100px;
border-radius: 100px;
cursor: pointer;
opacity: 0.2;
}
#inactive {
background: tomato;
position:absolute;
top:50px;
left: 50px;
height:50px;
width: 400px;
pointer-events: none;
opacity: 0.9;
}
#third {
position:absolute;
display: inline-block;
width: 200px;
height: 200px;
background: transparent;
-moz-border-radius: 100px;
-webkit-border-radius: 100px;
border-radius: 100px;
cursor: pointer;
}
#third::after {
content: url('http://i.imgur.com/YAWvTuu.png');
cursor: auto;
pointer-events: none;
}
<div id="image1" alt=image><div id="circle1" onClick="window.location.href = 'http://www.google.com'"></div></div>
<div id="image2" alt=image></div><div id=third class="circle" alt=image onClick="window.location.href = 'http://www.google.com'"></div>
<div id=inactive></div>
I'm not sure if I've interpreted your question properly, but look into z-index. If there's elements overlapping each other, this will be a reason why they're not able to be clicked.
So, you can wrap the planet or circle in an <a> tag, border-radius that <a> element to be 100% which makes it a full circle and then hide the overflow.
See this: https://jsfiddle.net/xcqy7r14/2/
Markup:
<a href="#">
<canvas></canvas>
</a>
<br><br>
<a href="#">
<canvas></canvas>
</a>
CSS:
a {
border-radius: 100%;
overflow: hidden;
display: inline-block;
}
canvas {
width: 100px;
height: 100px;
display: inline-block;
background: #f00;
border-radius: 100%;
}
Related
I want to create a landing page like a game. The visitor gets the option either to chose "Professioneel" or "Speels".
Telling it is easy but programming it is hard for me, so this is what I want:
2 div's with 2 different background-image when someone hover over one of the divs I want the background-image to scale (ONLY THE IMAGE) and the opacity placed on the div to change from 50% to 80%.
And a really nice future would be to display a snow falling gif over the image.
This is what I want to create:
Before
After:
What I have achieved till now is making the 2 divs with a background-image and I'm not even sure if that is the right way.
Can someone please help me out?
This is what happens when I hover with my current code: (the whole div scales, not only the image)
As an user asked, here some code:
#containerEntree {
height: 100vh;
width: 1920px;
padding-left: 0;
padding-right: 0;
}
#professioneelContainer {
background-color: red;
text-align: center;
width: 1920px;
height: 475px;
}
#speelsContainer {
background: red;
width: 100%;
height: 475px;
text-align: center;
}
.entreeTekst:hover {
transform: scale(1.2);
}
.entreeTekst {
width: 100%;
height: 100%;
position: relative;
transition: all .5s;
margin: auto;
}
.entreeTekst > span {
color: white;
/* Good thing we set a fallback color! */
font-size: 70px;
position: absolute;
}
<div class="container" id="containerEntree">
<div id="professioneelContainer">
<div class="entreeTekst">
<span>professioneel</span>
<img src="img/professioneel.jpg" />
</div>
</div>
<div id="speelsContainer">
<div class="entreeTekst">
<span>Speels</span>
<img src="img/speels.jpg" />
</div>
</div>
</div>
Please note that I'm still working on it so don't say that this (of course) won't work.
You can do this by using 2 divs with background images and use padding on the div to replicate the aspect ratio of the background image. Scale the image using background-size on :hover. Then use a pseudo element to create the color overlay and transition the opacity on :hover, then use the other pseudo element on top of that with the text and the "snow" gif as a background.
body {
width: 600px;
max-width: 80%;
margin: auto;
}
div {
background: url('https://static.tripping.com/uploads/image/0/5240/towns-funny-names-us_hero.jpg') center center no-repeat / 100%;
height: 0;
padding-bottom: 33.33333%;
position: relative;
transition: background-size .25s;
}
.speel {
background-image: url('http://www.luketingley.com/images/large/The-Punchbowl-Web-Pano.jpg');
}
div::after, div::before {
content: '';
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
}
div::before {
opacity: .5;
transition: opacity .25s;
}
.pro::before {
background: blue;
}
.speel::before {
background: red;
}
div::after {
display: flex;
align-items: center;
justify-content: center;
color: #fff;
font-family: sans-serif;
font-size: 1.5em;
font-weight: bold;
}
.pro::after {
content: 'PROFESSIONEEL';
}
.speel::after {
content: "SPEELS";
}
div:hover::after {
background: url('https://media.giphy.com/media/26BRyql7J3iOx875u/giphy.gif') center center no-repeat / cover;
}
div:hover::before {
opacity: 0.8;
}
div:hover {
background-size: 150%;
}
<div class="pro">
</div>
<div class="speel">
</div>
You can simply increase the background-size: height width; and opacity: value; property when you hover over an element. You can, if you want to, add some transition to make it smooth. This only scales the background image, not the div itself.
#d {
background-image: url(https://cdn.pixabay.com/photo/2016/10/29/20/52/cincinnati-1781540_960_720.png);
height: 200px;
width: 200px;
background-size: 100px 100px;
background-repeat: no-repeat;
background-position: center;
/*To make the transistion smooth*/
-o-transition:.5s;
-ms-transition:.5s;
-moz-transition:.5s;
-webkit-transition:.5s;
transition:.5s;
opacity: 0.5;
}
#d:hover {
background-size: 110px 110px;
opacity: 0.8;
}
<div id='d'>
</div>
I'm not even sure this is possible, I'm looking to make a see-trough "border"/cut-out around an element. Like in the image below, the point is to make the background show between the magenta element in the centre and the grey elements.
So far all I have managed is a solid colour border around the magenta element. Using the following class, this gives me the desired result but only on a white background.
.app.center {
height: 40px;
width: 28px;
z-index: 5000;
border-radius: 3px;
box-shadow: 0 0 0 3px white;
}
See this fiddle for my entire CSS.
Setting a transparent border as suggested in the comments does not solve my problem (tested in FF40). I am trying to create a transparent gap around my middle div element (the magenta one). Setting a transparent border on this element does not work.
I am looking for a way to clip the sibling divs that fall behind the middle div so a small piece of the background is visible on either side of the middle element that follows the edge/shape of the centre element.
Yes, this is basically impossible. That's why I am trying to provide an answer :-)
My solution will not work on IE, and limits you to use primary colors in the elements. As far as I know, it's the only way to get this result.
The trick is to use a blend mode, that translates gray into transparent. And the borders of the element will be gray, so will show the underlying background
.bkg {
width: 200px;
height: 200px;
border: solid 1px black;
background-image: repeating-linear-gradient(45deg, white 0px, lightblue 40px);
}
.button {
width: 100px;
height: 100px;
border-radius: 20%;
border: solid 10px gray;
position: absolute;
font-size: 80px;
}
#bt1 {
left: 40px;
top: 20px;
background-color: red;
}
#bt2 {
left: 80px;
top: 90px;
background-color: rgb(255,0,255);
}
.panel {
position: absolute;
top: 0px;
width: 200px;
height: 200px;
mix-blend-mode: hard-light;
}
<div class="bkg"></div>
<div class="panel">
<div class="button" id="bt1">-1-</div>
<div class="button" id="bt2">-2-</div>
</div>
If your purpose could be met with a "faux"-transparency, then you could make use of the border-image. However, this is not a true solution. Also, you would lose border-radius when you use a border-image.
The trick is to use as border-image the same image that you use for your background-image on lower-layer div or body. This will give the "illusion" of transparency clipping through the sibling divs which are at a lower-level.
Example:
* { box-sizing: border-box; }
body { background-image: url(http://i.stack.imgur.com/lndoe.jpg); }
.sphere {
position: relative; background-color: #444;
left: 200px; top: 100px; height: 100px; width: 200px;
border-top-right-radius: 100px; border-top-left-radius: 100px;
text-align: center; padding-top: 10px; color: white;
}
.app {
position: absolute; transform-origin: center 75px; background: #cc4489;
border-radius: 5px; left: 72px; top: -72px; height: 64px; width: 52px;
}
div.sphere > .app:first-child {
transform: scale(0.9) rotate(-30deg);
background: #adabae; top: -72px;
}
div.sphere > .app:last-child {
transform: scale(0.9) rotate(30deg);
background: #79787a; top: -72px;
}
.app.center {
height: 64px; width: 52px; z-index: 5000;
background-clip: padding-box; background-origin: padding-box;
border-image: url(http://i.stack.imgur.com/lndoe.jpg) 10;
border-width: 5px;
}
<div class=" sphere">
<div class="app"></div>
<div class="app center">3</div>
<div class="app"></div>
</div>
Fiddle: http://jsfiddle.net/abhitalks/aoh8vc8v/
As applied to your fiddle: http://jsfiddle.net/abhitalks/L6deaazy/3/
Disclaimer: This is faux clipping. clip-path and mask could be better put to use.
I have 3 overlapping html divs, one next to another, colored: red, green and blue. All elements have opacity 0.5. First two divs (red and green) I want to summate color (creates something between red and green) - standard behaviour, without changes here.
My problem is how to prevent summating colors only between green and blue divs?
It would be great if we could do this without additional elements.
html:
<div id="d0"></div>
<div id="d1"></div>
<div id="d2"></div>
css:
div {
position: absolute;
opacity: 0.5;
}
#d0 {
top: 60px;
height: 100px;
left: 50px;
width: 100px;
background-color: red;
}
#d1 {
height: 150px;
left: 130px;
top: 50px;
width: 200px;
background-color: green;
}
#d2 {
height: 100px;
left: 300px;
top: 80px;
width: 120px;
background-color: blue;
}
EDIT:
I forgot about: http://plnkr.co/edit/5MIduRMFo0dZ54xqzpAa?p=preview
It should look likt this (fourth element is to show that blue also has opacity):
If you want to keep opacity of all divs to be still 0.5. Then here is your pure CSS solution. No additional elements added.
Here is a fiddle for that.
http://jsfiddle.net/tdh7ks2x/2/
**HTML**
<div id="d0"></div>
<div id="d1"></div>
<div id="d2"></div>
<div id="d4"></div>
**CSS**
#d2 {
opacity: 1;
height: 100px;
width: 120px;
left: 300px;
top: 80px;
}
#d2:before,
#d2:after{
content: "";
position :absolute;
left: 0;
top: 0;
height: 100px;
background-color: blue;
}
#d2:before{
width: 30px;
z-index: 2;
opacity: 0.99999999;
background-color: #7F7FFF;
}
#d2:after{
width: 120px;
z-index: 1;
opacity: 0.5;
}
#d4 {
width: 200px;
height: 80px;
left: 400px;
top: 90px;
background-color: red;
}
Just added this CSS instead of #d2, rest all your CSS is fine. Let me know if this resolves your issue.
Pick the color of the div with opacity and use it in the ":before" div.
You can use z-index property to bring a div to front or back. Higher the value of z-index to move it to the top and decrease it to move it back.
Moreover you have used opacity:0.5 due to which you will see the back colors at the intersection. You must increase the opacity to see the exact colors there
div {
position: absolute;
opacity: 0.5;
}
#d0 {
top: 60px;
height: 100px;
left: 50px;
width: 100px;
background-color: red;
z-index:2
}
#d1 {
height: 150px;
left: 130px;
top: 50px;
width: 200px;
background-color: green;
}
#d2 {
height: 100px;
left: 300px;
top: 80px;
width: 120px;
background-color: blue;
}
<div id="d0"></div>
<div id="d1"></div>
<div id="d2"></div>
css:
Basically, this problems occurs due to overlapping transparent colors. Example is rgba(255,255,255,0.3) overlapping with rgba(255,255,255,0.3) to form a brighter color.
If your design can do without transparent colors, you can easily solve this by converting your transparent colors (rgba) to fully opaque ones (hex) for related elements.
You will need the background color to help compute a fully opaque hex from rgba or just use a color picker browser extension after rendering.
I have the following fiddle. I am trying to set the background-image of a div as follows:
.close-button{
position: absolute;
width: 25px;
height: 25px;
background-image: url('https://cdn4.iconfinder.com/data/icons/brightmix/128/monotone_close_exit_delete_small.png');
z-index: 1;
cursor: pointer;
background-color: blue;
}
here's the div:
<div class="close-button" data-dismiss="modal" aria-hidden="true"></div>
why is this not working?
You would need to use background-size i.e background-size:25px; or background-size:contain; to your image since it is much bigger than your div's dimensions.
.close-button {
position: absolute;
width: 25px;
height: 25px;
background-image: url('https://cdn4.iconfinder.com/data/icons/brightmix/128/monotone_close_exit_delete_small.png');
background-size:25px;
z-index: 1;
cursor: pointer;
background-color: blue;
}
Demo
On a side note this image is too big to be an icon, you can try considering the usage of image sprites to consolidate all your icons to one image file and just use css background position to select them.
You image is bigger than your div. Change the width and height of the div, you will see the background image. Or you have to use a smaller background image.
.close-button
{
position: absolute;
width: 128px;
height: 128px;
background-image: url('https://cdn4.iconfinder.com/data/icons/brightmix/128/monotone_close_exit_delete_small.png');
z-index: 1;
cursor: pointer;
background-color: blue;
}
http://jsfiddle.net/2LTYY/4/
I am trying to add a "plus sign" (its a .png file) to my portfolio section. My goal is to make this "plus sign" visible only when customers are hovering with mouse pointer over my projects but in the same time I want to keep the background-color property which I already set up.
However, my plus sign doesn't show up!? How can I do that???
On this website you can see the similar effect: http://bjorsberg.se/
Here is my JSFiddle: http://jsfiddle.net/L8HX7/
This is a part of my CSS (from JSFiddle) that needs to be fixed:
.plus{
width: 100px;
height: 100px;
position: absolute;
left: 50%;
top: 50%;
margin: -49px 0 0 -56px;
background: url(img/plus.png) center center no-repeat;
}
Here is example of a plus sign I want to add: http://icons.iconarchive.com/icons/visualpharm/icons8-metro-style/512/Very-Basic-Plus-icon.png
Here is a really broken down example.
http://jsfiddle.net/sheriffderek/UVvWm/
CSS
.block {
position: relative; /* so the .plus knows what to be relative to */
display: block;
width: 10em;
height: 10em;
background-color: red;
}
.overlay {
position: absolute;
width: 100%;
height: 100%;
top: 0; left: 0;
}
.block:hover .overlay {
background-color: rgba(0,0,0,.5);
}
.block .plus {
display: none;
}
.block:hover .plus {
display: block;
}
/* to position the .plus */
.plus {
position: absolute;
left: 50%;
top: 50%;
margin-left: -50px;
margin-top: -50px;
}
HTML
<a href="#"class="block">
<div class="overlay"></div>
<img class="plus" src="http://placehold.it/100x100" />
</a>
You could use an :after psuedo element for the overlay - but I wanted to keep it simple. Keep in mind that CSS declarations read from right to left .... "any .plus - do this, when .block:hover" etc ----
The style obviously has to be applied on hover.
Just replace the background-color in .projectshot a .over:hover{ by the appropriate background. You don’t need the div.plus at all, and neither do you need div.inner (you can remove those from the HTML!):
.projectshot a .over:hover{
position: absolute;
background: url(img/plus.png) center center no-repeat rgba(51, 51, 51, 0.6);
border-radius: 8px;
height: 150px;
width: 200px;
margin: 10px;
}
Here’s the updated Fiddle: http://jsfiddle.net/L8HX7/8/