I have an element (bar) positioned over an iframe, if i set an opacity on that element it stays under the iframe, even if that item has a bigger z-index than the iframe.
However, if i create a container (foo) around that element and the iframe, and set the opacity there, the (bar) element stays in front of the iframe like intended.
CSS:
#bar {
width:100px;
opacity:0.5;
height: 150px;
position:relative;
top:100px;
z-index:2;
background:red
}
#foo {
/* opacity:0.5; */
}
HTML
<div id="foo">
<div id="bar">
<ul>
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
</ul>
</div>
<iframe src="http://www.adelaide.edu.au/myuni/tutorials/docdesign/guides/docDesignGuide_KeepPDFsmall.pdf" width="200px" height="200px" frameborder="0" style="z-index:-1"></iframe>
</div>
Creating that container would solve my problem, but i cannot do that because my current markup doesn't allow it. I would need the opacity to stay in the bar element.
This only happens in Firefox, and the content of the iframe is a .pdf file.
How can i get the bar element to stay on top of the iframe while maintaining its opacity setting?
fiddle here
UPDATE:
It seems the problem is related to the fact that i'm sourcing a pdf file instead of a webpage in the iframe.
updated fiddle
Thanks in advance
If you use background: rgba(255,255,255,0.5) other element will not be effected by the translucent background.
In the example that I provided the rgb color(255,255,255) is white when you use rgba the last digit is use to set the opacity, .5 would be 50% translucent.
#foo {
background: rgba(255,255,255,0.5);
}
Look at those links. I think that is a discussion of your problem:
StackOverflow and Adobe statement for this problem
I found one more theme to discuss this. As your case they use pdf iframe:
Link here
from what i understand, you want the text to be above the picture, and transparent?
i did something like this on the cover page one of my older sites, chadwaddell.info.
I made a container div, and then put the picture in its own div, and the text in its own div.
set the container position to relative, and the picture position to absolute. also, i would use rgba to do the opacity like this
#bar {
width:100px;
opacity:0.5;
height: 150px;
position:relative;
top:100px;
color: rgba(3,3,3,0.5)
background:rgba(255,0,0,0.5)
}
i went onto your fiddle, and did what i was trying to say, hope this helps http://jsfiddle.net/N9cZp/23/
Related
I have a navbar with links using a 1px wide, no-repeat, right-aligned background image as a divider, but for some reason the background image doesn't appear for one of the links in Chrome - in this case between "Athletics" and "Bowling".
It works in Firefox and Explorer, when zooming in and out in Chrome, when changing the font-size, when reducing the character length of the link, etc. so I believe it has something to do with how Chrome renders the background image.
I have tried different suggestions such as setting the background-size to contain/cover/100% and image-rendering to pixelated (supposedly this only targets regular images and not background images), but I can't get it to work.
How can I ensure that all background images are displayed correctly in Chrome?
CSS
ul {
display:flex;
list-style:none;
}
ul a {
background:url(sports-div.png) right bottom no-repeat;
display:inline-block;
font-family:sans-serif;
font-size:13px;
padding:5px;
}
HTML
<ul>
<li>Football</li>
<li>Basketball</li>
<li>Tennis</li>
<li>Ice hockey</li>
<li>Volleyball</li>
<li>Badminton</li>
<li>Snooker</li>
<li>Athletics</li>
<li>Bowling</li>
<li>Cycling</li>
</ul>
http://jsfiddle.net/zc29b8no/1/
The technical explanation is rather long and boring.
But, the gist of it is: it has to do with subpixel rendering.
Your anchors' dimensions are not clear cut pixels and the browser needs to approximate what to render in each pixel. Your 1px image falls on the wrong side of rounding. To make sure it renders inside the element's painted background, you need to replace the right alignment in background-position (which translates to 100%) with calc(100% - 1px):
ul {
display:flex;
list-style:none;
}
ul a {
background:url(https://i.imgur.com/mCra304.png) calc(100% - 1px) bottom no-repeat;
display:inline-block;
font-family:sans-serif;
font-size:13px;
padding:5px;
}
<ul>
<li>Football</li>
<li>Basketball</li>
<li>Tennis</li>
<li>Ice hockey</li>
<li>Volleyball</li>
<li>Badminton</li>
<li>Snooker</li>
<li>Athletics</li>
<li>Bowling</li>
<li>Cycling</li>
</ul>
Another solution would be to make the image 2px wide, but it might still have variable width.
Can anyone give me a hint why the link in the gray box is not clickable in Internet Explorer (I'm using version 11).
http://jsfiddle.net/rk7n7xjj/1/
I tested it in any other browsers and it works fine.
HTML
<div class="gray">This link is not clickable in IE</div>
<div class="yellow">Some placeholder text</div>
CSS
.gray {
position:fixed;
z-index:-1;
top:100px;
background:gray;
height:50px;
width:200px;
}
.yellow {
margin:0 auto;
background:yellow;
height:1000px;
margin-top:400px;
}
The link is not clickable becaue of the z-index.
Actually you setting the div behind the body. You must specify the z-index of the body too. Or at least set it positiv so it's in front of the body and set other elemnts higher if you expact to display them in front of the gray div. Thats why you cant click it.
Obviously Firefox and co has no problems to identify the link when you set z-index like this.
This may helps you to understand how you can use z-index also in IE.
In your case, to get what you want, your CSS should look like:
.gray {
position:fixed;
z-index: 1;
top:100px;
background:gray;
height:50px;
width:200px;
}
.yellow {
position:relative;
z-index: 2;
margin:0 auto;
background:yellow;
height:1000px;
margin-top:400px;
}
Actually you dont need the z-index on the gray in your case but if you plan to may display something behind the gray div than you may need it.
The link is not clickable because IE is taking it behind the body. If you notice, even the text of the link is not selectable. Try setting a z-index: 1 to the body or any parent container. That ways you are first telling the browser to take all the elements inside the container to a higher z-index and then move the link behind that raised set of elements (But the movement of the link is done only within the parent's context i.e. the raised level. Read about stacking context). Thus the link now becomes clickable.
Alternate Solution
If you just want the yellow div over the gray div, then give a positive z-index to the yellow div only. Remove the z-index property from the gray div. If no z-index value is present, 0 is taken as the default. It will always stay behind the yellow div.
.yellow {
position: relative;
z-index: 1;
/* other styles */
}
Hoping for some advice around a CSS issue - I have a layout where I'm absolutely positioning link text above a background image, but cannot get the link to expand to the height of the container (in IEx, works fine in Chrome)
<div>
<img />
<a />
</div>
The containing div has a background colour, and the image has its opacity reduced - on hovering the image, the opacity reduces further, leaking more of the background color. At the same time, the opacity of the link changes from 0 to 100. I'm using a few CSS transitions as well, just to prettify it.
I know that positioning the link absolutely removes it from the flow, so setting height to 100% won't work, but shouldn't I be able to set it explicitly? Doing so works in Chrome but not IE. Problem is related to the image, as the link behaves correctly if it is removed.
Example:http://jsfiddle.net/thSCJ/8/ (includes just enough detail to highlight my problem. In IE, hovering the top left of the image reveals the link. In Chrome, any hover on the image reveals the link).
Any suggestions?
You need to have the <a> tag wrapping the image and the text:
<a href="#">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR6kpJ562NTt7Vkya4ocQ3Aq7mVqNB04ccB9XNCr-b4mPdYU6Y5Yg" width=200 height=200/>
<span>Link text</span>
</a>
Here is the CSS:
a {
width:200px;
height:200px;
background:#cccccc;
}
a:hover > span {
display: inline;
}
span {
display: none;
position:absolute;
top:0;
left:0;
width:200px;
height:200px;
color:red;
}
Fiddle: http://jsfiddle.net/thSCJ/12/
Instead of changing the opacity, simple change the font-size property and put the entire thing in the <a> tag.
See this JSFiddle.
I want to create a layout where I want to display an image to the left and content on the right. The image should stay constant when the content scrolls.
The css I'm using:
<style type="text/css">
#page-container
{
margin:auto;
width:900px;
background-color:Black;
}
#header
{
height:150px;
width:650px;
}
#main-image
{
float:left;
width:250px;
height:500px;
background-image:url('../images/main-image.png');
position:fixed;
}
#content
{
margin-left:250px;
padding:10px;
height:250px;
width:630px;
background-color:Teal;
}
</style>
The HTML:
<div id="page-container">
<div id="header"><img src="someimagelink" alt="" /></div>
<div id="main-image"></div>
<div id="content"></div>
</div>
Alot of time on this site and I have understood that background-attachment:fixed positions the image in the entire viewport and not the element it is applied to.
My question is how do I go about creating that kind of layout?
I do not want to give that image as a background image, as if the window is resized, it might get hidden. I want scrollbars to appear if the window size is less than 900px( my page width) so that the image can be viewed at all times.
That happens with this code, however I would like the image to start at my element instead.
How do I go about doing this??
Thanks in Advance :)
Edited:
I took the advice and added a position:fixed property to #main-image. Using the HTML and CSS as shown above.
Now, I also want to fix the header so that it does not move. Basically, only my content section should scroll.
However, if I add a position:fixed to the header, my #main-image and #content now sit on top of my header.
If I add a margin-top:150px (since my header height is 150px) to the #main-image, it works fine and moves down appropriately.
However if I add a margin-top:150px to the #content, my header moves down by 150px and still sits on top of my #content.
Can someone please explain why this is happening?
Thanks in Advance :)
Take a look at this link:
http://www.barelyfitz.com/screencast/html-training/css/positioning/
You can learn how to position Div's with it.
This will solve your problem:
#main-image {position:fixed;}
EDIT:
I'm not sure of what caused your problem but here is the solution:
#content{
position:relative;
top:150px;
}
My Guess:
I think that happened because when using position:fixed those 2 div's were positioned relative to the the browser window, while the other one was relative to the document itself.
In this link you will see more about positioning and you can test some of these features related to the position property:
http://www.w3schools.com/cssref/pr_class_position.asp
About the fact that one div was positioned over another, you should search for the 'z-index' property. Firefox has a 3D mode so you can see this more clearly:
http://www.addictivetips.com/internet-tips/browse-internet-in-3d-using-mozilla-firefox-11-tip/
Set a min-width on html and body.
Have you tried setting your #page-container to relative and your #main-image container to absolute and setting the position using top, bottom, etc. Then you should also be able to float your #content container to the right.
I have a page that holds an iframe:
<div style="position:absolute; width:80%; top:100px; left:10%; z-index:5;">
<iframe src="www.google.com" />
</div>
Note that the source of the iframe can be from another domain, so I can't change the html in it.
In addition to this ifame I have a menu and some decoration image at the bottom:
<div id="menu" style="position:absolute; width:100%; top:0px; left:0px; z-index:100;">
...
</div>
<div id="footer" style="position:absolute; width:100%; bottom:0px; left:0px; z-index:0;">
...
</div>
As you can see, I gave z-index to each div, so it should be displayed in that order: the menu on the top, followed by the div with the iframe and at the end the footer image.
What I want is that the iframe (and the div holds it) to have no background (transparent bg color if you like), so the background and the footer image behind it will be visible. Note that I want to change only background color; the text must not change or get opacity.
I managed to get to the bg image and change it (with jquery):
if ($.browser.msie == false) {
$(document.getElementById("content").contentDocument.body).
css('background', "url('transparent.png')");
}
else {
$(document.getElementById("content").Document.body).
css('background', "url('transparent.png')");
}
It works greate on the iframe, but the div that holds it somehow gets a white background.
It won't change if I set the background of the div to this 'transparent.png' image; the div will still save its white background!
If I replace the div with a table, the iframe goes behind the footer image (although it has z-index bigger).
All I want is just to see the footer image behind that iframe...
Please help, I'm quite hopeless... : (
Try:
background: transparent url('transparent.png');
One thing to note, IE6 does not support alpha transparencies for PNGs. You'll want to have an IE specific stylesheet and use an IE only hack for this.
Just to clearify, you arn't trying to get rid of the background color within the iframe itself, but just be able to see the footer and header correct? If this is the case, this should work with an HTML4.01 doctype.
<div style="position:absolute; width:80%; top:100px; left:10%; z-index:5;">
<iframe style="background-color: transparent;" src="testframe.html" allowtransparency="true"></iframe>
</div>
I tested this and was not able to duplicate the problem. Here's my primary html:
<div style="background:red;">
<div>
<iframe src="test2.html" />
</div>
</div>
And here's test2.html:
this is a test file
This displays "this is a test file" in an iframe with a red background behind the iframe. Can you post some code to clarify your problem?
did you try transparent background to the div and that semitransparent background image to the iframe?
CSS:
<style>
.hid
{
filter: alpha(opacity=70);
opacity: 0.7;
-moz-opacity: 0.7;
}
</style>
HTML:
<iframe class="hid"></iframe>
This will do the trick.
I tried it on IE6 and it works there.