I am trying to place an image(which is a close button) on iframe at the top-right corner, the iframe and image are loaded from js function in angular, I have placed it correctly by some CSS but the issue is when the screen is responsive or on the tab or mobile view it doesn't appear in the correct place
Below is the Html code:
<div style="
position: fixed;
width: 100%;
height: 100%;
top: 0px;
left: 0px;
transition: all 0.3s ease-in-out 0s;
z-index: 100;
background: rgba(0, 0, 0, 0.7);
">
<iframe style="
display: inherit;
z-index: 10001;
position: absolute;
transition: transform 0.5s ease-in-out 0s;
transform: scale(1);
opacity: 1;
top: 40px;
left: 50%;
margin-left: -200px;
background-color: rgb(255, 255, 255);
" src="test.html" id="iframe-overlay" title="iframe">
</iframe>
<img style="
transition: all 0.5s ease-in-out 0s;
opacity: 1;
float: left;
position: absolute;
top: 23% !important;
left: 48% !important;
transform: translate(-50%, -50%) !important;
z-index: 99999999;
margin-left: 192px;"
id="close-overlay"
" src="assets/images/pink_hair_sml.png" />
</div>
The image should be placed at the marked position even if the screen gets minimized or maximized the image should be placed at the same position.
here is how it should look
but when I reduce the screen to 75%
this is how it looks
I am able to fix it for each screen but still when the screen gets minimized or maximized position is not placed correctly
here is parent of the element
If you add a div that wraps the 2, you can position that using flex in relation to your to div like so:
<div style="
position: fixed;
width: 100%;
height: 100%;
top: 0px;
left: 0px;
transition: all 0.3s ease-in-out 0s;
z-index: 100;
background: rgba(0, 0, 0, 0.7);
display: flex;
justify-content: center;
">
<div style="position: relative; max-width: 50%">
<iframe style="
display: inherit;
z-index: 10001;
transition: transform 0.5s ease-in-out 0s;
transform: scale(1);
opacity: 1;
background-color: rgb(255, 255, 255);
" src="test.html" id="iframe-overlay" title="iframe">
</iframe>
<img style="
transition: all 0.5s ease-in-out 0s;
opacity: 1;
float: left;
position: absolute;
top: 0px;
right: 0px;
transform: translate(-50%, -50%) !important;
z-index: 99999999;
id="close-overlay"
" src="assets/images/pink_hair_sml.png" />
</div>
</div>
Alternatively, positioning the wrapping element itself which means you don't have to add a new div, see below. The disadvantage of this is that there's then space not covered by the div itself and so whatever's underneath then shows through.
<div style="
position: fixed;
width: 50%;
height: 100%;
top: 0px;
left: 25%;
transition: all 0.3s ease-in-out 0s;
z-index: 100;
background: rgba(0, 0, 0, 0.7);
">
<iframe style="
display: inherit;
z-index: 10001;
transition: transform 0.5s ease-in-out 0s;
transform: scale(1);
opacity: 1;
background-color: rgb(255, 255, 255);
width: 100%;
" src="test.html" id="iframe-overlay" title="iframe">
</iframe>
<img style="
transition: all 0.5s ease-in-out 0s;
opacity: 1;
float: left;
position: absolute;
top: 10px;
right: 10px;
z-index: 99999999;
id="close-overlay"
" src="assets/images/pink_hair_sml.png" />
</div>
The positioning of the two elements (iframe and img) is pretty straightforward as we know the width of the iframe (it is picking up the default which is set at 300px by browsers see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe ).
However it is rendered somewhat complex by the rather strange set of styles applied inline to the iframe and (worse) to the img where a couple are set !important and therefore not overwritable by our own CSS.
This snippet just gets rid of all the inline styling on those two elements using Javascript and starts again.
It positions each element independently. The iframe is centered and set at 40px from the top of its positioned parent. The img is positioned to just after the right hand edge of the iframe, and then transitioned back by half its width and height to get the overlap.
<!doctype html>
<html>
<head>
</head>
<body>
<div id="GlobalPayments-overlay-02d30efa" style="
position: fixed;
width: 100%;
height: 100%;
top: 0px;
left: 0px;
transition: all 0.3s ease-in-out 0s;
z-index: 100;
background: rgba(0, 0, 0, 0.7);
">
<iframe style="
display: inherit;
z-index: 10001;
position: absolute;
transition: transform 0.5s ease-in-out 0s;
transform: scale(1);
opacity: 1;
top: 40px;
left: 50%;
margin-left: -200px;
background-color: rgb(255, 255, 255);
" src="test.html" id="iframe-overlay" title="iframe">
</iframe>
<img style="
transition: all 0.5s ease-in-out 0s;
opacity: 1;
float: left;
position: absolute;
top: 23% !important;
left: 48% !important;
transform: translate(-50%, -50%) !important;
z-index: 99999999;
margin-left: 192px;" id="close-overlay" " src="assets/images/pink_hair_sml.png " />
</div>
<style>
body {
width: 100vw;
}
#GlobalPayments-overlay-02d30efa {
--iframeW: 300px; /*the defaults set by browsers https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe*/
--iframeH: 150px;
}
#GlobalPayments-overlay-02d30efa iframe {
transition: transform 0.5s ease-in-out 0s;
transform: scale(1);
opacity: 1;
background-color: rgb(255, 255, 255);
top: 40px;
margin: 0;
padding: 0;
left: calc(50% - (var(--iframeW) / 2));
position: absolute;
}
#GlobalPayments-overlay-02d30efa img {
position: absolute;
top: 40px;
left: calc(50% + (var(--iframeW) / 2));
transform: translate(-50%, -50%);
margin: 0;
padding: 0;
width: 16px;
height: 16px;
}
</style>
<script>
const iframe = document.querySelector('iframe');
const img = document.querySelector('img');
iframe.style = '';
img.style = '';
</script>
</body>
After all your comments that finally explains that you cannot change the HTML code we start to understand what you need!
You have to override the inline CSS rules with the help of the !important operator. The big problem will be on the close image
because it already has some !important rules in the inline CSS, which is bad news for us... But you can use JavaScript to correct
the horrible HTML generated.
For the CSS itself, I prefer putting all items in position fixed and use % to position them.
The close image should not be set from the left but from the right. But as said before this will be tricky because the inline CSS already has some !important rules. But at least we can remove the float and left margin. Finally, after overriding during the battle, the simpliest was just to remove the inline style attribute with JS.
You'll have to find if you can hook somewhere in the JS library. If you cannot then you could run the JS every half a second until it finds the close image, like I did (but it's not a nice solution).
By the way, it would be good to set the image size in the CSS so that it displays at the correct place and size before the image itself is downloaded.
/*
In your case, you'll have to run this once the
iframe is visible. See if you can hook somewhere.
Look at the JS library you are using or if you can
then replace it by one not generating all this
horrible HTML with inline styles.
Here, just for the demo, I finally find a solution
to run it once the document is loaded and also each
time a change is detected, typically the case of the
user clicking on a button or link to display the
iframe overlay. This avoids the solution of a timer
running all the time.
*/
/**
* Correct the close button of the iframe displayed on overlay.
*/
function correctIframe() {
let closeImg = document.querySelector('#iframe-overlay ~ img:not(.cleaned)');
if (closeImg) {
closeImg.setAttribute('style', '');
closeImg.setAttribute('class', 'cleaned');
}
}
// Once the document is loaded we can try to see if there's
// already an iframe overlay to correct it.
document.addEventListener('DOMContentLoaded', correctIframe);
// Each time the document changes (typically if some JS does
// something such as triggering an Ajax call, loading new HTML,
// or simply displaying the iframe overlay) then we also have
// to correct it.
let domInsertionObserver = new MutationObserver((mutation) => {
correctIframe();
});
domInsertionObserver.observe(document, { childList: true });
#iframe-overlay {
z-index: 1000 !important;
position: fixed !important;
top: 10% !important;
left: 10% !important;
width: 80% !important;
height: 80% !important;
margin: 0 !important;
}
/* An image tag just after the iframe. */
#iframe-overlay ~ img {
visibility: hidden; /* To avoid seeing it at bad position. */
z-index: 1001 !important;
position: fixed !important;
/*
We cannot override the left attribute
because it has !important in the inline
rule! Bad! We cannot override the transform
either! Even worth! So JavaScript can only
save us by deleting the inline style attribute.
*/
top: 10% !important;
right: 10% !important;
/* Adjust to the image size to avoid image
being resized during the download step. */
width: 30px;
height: 30px;
/* Move half of the image size to right and down. */
transform: translate(50%, -50%) !important;
}
#iframe-overlay ~ img.cleaned {
visibility: visible;
}
<div style="
position: fixed;
width: 100%;
height: 100%;
top: 0px;
left: 0px;
transition: all 0.3s ease-in-out 0s;
z-index: 100;
background: rgba(0, 0, 0, 0.7);
">
<iframe style="
display: inherit;
z-index: 10001;
position: absolute;
transition: transform 0.5s ease-in-out 0s;
transform: scale(1);
opacity: 1;
top: 40px;
left: 50%;
margin-left: -200px;
background-color: rgb(255, 255, 255);
" src="test.html" id="iframe-overlay" title="iframe">
</iframe>
<img style="
transition: all 0.5s ease-in-out 0s;
opacity: 1;
float: left;
position: absolute;
top: 23% !important;
left: 48% !important;
transform: translate(-50%, -50%) !important;
z-index: 99999999;
margin-left: 192px;"
id="close-overlay"
" src="assets/images/pink_hair_sml.png" />
</div>
I would like to know if it is possible to move div along the circular path with fixed angle. E.g. moving div only 45 degrees of circular path and than make it to come back to starting point, like effect similar to pendulum.
Hope, that attached picture will make sense to what I meant.
Many thanks for all help.
Looking forward,
As per your updated requirement (that the object itself should always be vertical while rotating), I have modified my previous code.
There may be another approach but I could think of this only at the moment. Here, I have wrapped our original 'ball' element inside another div. Now, the outer div does the normal pendulum animation. But, in addition, the inner object also does a counter-rotating animation which keeps it vertically straight at all points during the animation.
Please notice that the inner object has its transform-origin as default which is center center, because it needs to rotate around its own axis only.
#container
{
background-color: #777;
border-radius: 50%;
height: 20px;
margin: 0 auto;
margin-top: 150px;
position: relative;
width: 20px;
}
#ball
{
animation: swing 1s ease 0s infinite;
background-color: green;
height: 50px;
left: -15px;
position: absolute;
top: -150px;
transform-origin: center 150px;
width: 50px;
}
#keyframes swing{
0%{transform: rotate(-22.5deg);}
50%{transform: rotate(22.5deg);}
100%{transform: rotate(-22.5deg);}
}
#main-content
{
animation: innerswing 1s ease 0s infinite;
background-color: red;
display: block;
height: 100%;
width: 100%;
}
#keyframes innerswing{
0%{transform: rotate(22.5deg);}
50%{transform: rotate(-22.5deg);}
100%{transform: rotate(22.5deg);}
}
<div id="container">
<div id="ball">
<div id="main-content"></div>
</div>
</div>
You can do this using css animation alone. First you should shift the transform origin to a point that will server as the center of the pendulum. Now, you can simply define the angles for rotation as being 45 degree apart. Please check below code as an example:
#container
{
background-color: #777;
border-radius: 50%;
height: 20px;
margin: 0 auto;
margin-top: 150px;
position: relative;
width: 20px;
}
#ball
{
animation: swing 1s ease 0s infinite;
background-color: orange;
border-radius: 50%;
height: 50px;
left: -15px;
position: absolute;
top: -150px;
transform-origin: center 150px;
width: 50px;
}
#keyframes swing{
0%{transform: rotate(-22.5deg);}
50%{transform: rotate(22.5deg);}
100%{transform: rotate(-22.5deg);}
}
<div id="container">
<div id="ball"></div>
</div>
HTML:
<div class="wrap">
<span class="button"></span>
<div class="element"></div>
</div>
JS:
$('.button').on('mouseenter', function () {
$('.element').addClass('active');
}).on('mouseleave', function () {
$('.element').removeClass('active');
});
$('.element').on('mouseenter', function () {
$('.element').addClass('active');
}).on('mouseleave', function () {
$('.element').removeClass('active');
});
http://jsfiddle.net/e4p98cwb/1/
When you hover on the black element the blue one enters the screen. After that if you hover for a sec on empty space the blue one starts to escape the screen, but if you hover fast on the empty space that it occupied before two things might happen:
1. The blue one returns fully shown on screen
or
2. Jumps once or twice and proceeds to leave the screen
The same happens on hover and mouseover events as well. Why is this happening and is there a way around this behavior ?
The easiest way to get around any issues with JS is to just let CSS take care of it. If you add this to the :hover state it will work:
.button:hover + .element,
.element:hover {
-webkit-transform: translateX(0);
transform: translateX(0);
}
See below for an implementation. This saves you a ton of JS as well.
.wrap {
position: relative;
width: 600px;
height: 600px;
overflow: hidden;
border: 2px solid red;
}
.button{
width: 100px;
height: 50px;
display: block;
background: #333;
}
.element {
position: absolute;
top: 0;
right: 0;
z-index: 99999;
width: 500px;
height: 630px;
background: blue;
-webkit-transform: translateX(630px);
transform: translateX(630px);
-webkit-transition: all .3s ease-in-out;
transition: all .3s ease-in-out;
}
.button:hover + .element,
.element:hover {
-webkit-transform: translateX(0);
transform: translateX(0);
}
<div class="wrap">
<span class="button"></span>
<div class="element"></div>
</div>
Update
The reason this is happening is because the element itself is still occupying the same space. This has to do with translation not actually moving the element, but transforming it. Once you move your cursor off any of the activatable elements, it will retract, but as it's animating it still occupies that same space, making it possible to hover on that space and retrigger the animation. I believe it's because this transform is only fully applied after completing the animation. Let's test this theory:
.wrap {
position: relative;
width: 600px;
height: 600px;
overflow: hidden;
border: 2px solid red;
}
.button{
width: 100px;
height: 50px;
display: block;
background: #333;
}
.element {
position: absolute;
top: 0;
right: 0;
z-index: 99999;
width: 500px;
height: 630px;
background: blue;
right: -100%;
-webkit-transition: all .3s ease-in-out;
transition: all .3s ease-in-out;
}
.button:hover + .element,
.element:hover {
right: 0;
}
<div class="wrap">
<span class="button"></span>
<div class="element"></div>
</div>
In this one we are simply using absolute positioning and the issue goes away, meaning that the tranform is actually causing the element to still occupy the same space. Until animation concludes.
This question already has answers here:
Transparent arrow/triangle indented over an image
(4 answers)
Closed 8 years ago.
I am trying to achieve this effect using HTML/CSS:
What I have until now is this
http://jsfiddle.net/zxq91ok0/
.wrap {
position: relative;
overflow: hidden;
width: 100%;
height:250px;
margin: 0 auto;
background-color:#B2C2CC;
}
.wrap img {
width: 100%;
height: auto;
display: block;
}
.wrap:before, .wrap:after {
content:'';
position: absolute;
bottom: 0;
width: 50%;
background-color: inherit;
padding-bottom:3%;
}
.wrap:before {
right: 50%;
-ms-transform-origin: 100% 100%;
-webkit-transform-origin: 100% 100%;
transform-origin: 100% 100%;
-ms-transform: skewX(45deg);
-webkit-transform: skewX(45deg);
transform: skewX(45deg);
}
.wrap:after {
left: 50%;
-ms-transform-origin: 0 100%;
-webkit-transform-origin: 0 100%;
transform-origin: 0 100%;
-ms-transform: skewX(-45deg);
-webkit-transform: skewX(-45deg);
transform: skewX(-45deg);
}
The problem I face is that instead of plain background color I have another image as a background so I can't figure out how to get rid of the light blue background.
Can you help me accomplish the effect shown on the first image?
Thanks!
I think you can't add a triangle in your shape and use it as a mask like that. You need to use SVG shapes and masks or the CSS mask-image property (example - beware that's not supported by all browsers).
In the example below I will show you a sample of what I have right now and you will notice when you hover over the black box a transition occurs and slides in my tooltip. My problem is that I want that tooltip to only appear when I hover over the black box. In the example you will notice if you hover over the black or anywhere within 180px right of the black box the transition still occurs( this is because my graphic is 180px wide)! I want to restrict the hover effect to only the black box! Please help!
HTML
<div id="sidemenu">
<div id="regionsContainer">
<div id="regionsUnitedStates">
<div id="regionsUnitedStatesTooltip"></div>
</div>
</div>
</div>
CSS
#sidemenu {
width: 60px;
height: 100%;
min-width: 60px;
height: 100vh;
max-width: 60px;
background-color: #383D3F;
background-size: 100% 100%;
background-attachment: fixed;
position: absolute;
left:-60px;
transition: left ease-in-out 0.5s;
}
#sidemenu.show {
left: 0;
}
#regionsContainer {
width: 60px;
height: 481px;
min-height: 481px;
min-width: 60px;
max-width: 60px;
max-height: 481px;
background-color: #383D3F;
position: relative;
top: 25%;
bottom: 25%;
}
#regionsUnitedStates {
width: 60px;
height: 60px;
background: #000;
}
#regionsUnitedStatesTooltip {
opacity:0;
background: #555;
height:60px;
width:180px;
left:100px;
position:absolute;
transition:all ease-in-out 0.25s;
top:0;
}
#regionsUnitedStates:hover #regionsUnitedStatesTooltip{
left: 60px;
opacity:1;
}
Example:
JSFIDDLE
Best way I can see is to make it so you can't hover over the tooltip when it's not visible.
I achieved this by setting it initially to height: 0. Here's the changes
#regionsUnitedStatesTooltip {
height: 0;
transition: opacity ease-in-out 0.25s, left ease-in-out 0.25s;
}
#regionsUnitedStates:hover #regionsUnitedStatesTooltip{
height: 60px;
}
Demo ~ http://jsfiddle.net/pTMCP/3/
Update
Even simpler, add these two lines...
#regionsUnitedStatesTooltip {
visibility: hidden; /* add this */
}
#regionsUnitedStates:hover #regionsUnitedStatesTooltip{
visibility: visible; /* and this */
}
Demo ~ http://jsfiddle.net/pTMCP/5/