z-index not working as expected (Chrome and Opera) - html

I have a div with class "opaque" and another with class "product-info", which are both on the same level.
The code is as follows:
<div class="opaque"></div>
<div class="product-info">
<img class="product-image" src="/Images/D3.jpg" />
fsdfdsfsdfs
</div>
.opaque
{
background-color: White;
-moz-opacity:.60; filter:alpha(opacity=60); opacity:.60;
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
z-index: 1;
}
.product-info
{
padding: 5px;
text-align: center;
z-index: 2;
}
Note that product-info is set to z-index 2 and opaque has z-index 1. Therefore product-info should be displayed over opaque so should not be faded. However the image within product-info (and text) is faded. This happens in both Chrome and Opera, therefore I expect this is what should be happening since they are not IE!
There are lots of bits of HTML code as shown above, each nested in lis which are set to float left with width of 33%. When the page is fully loaded ($(window).load()) I use jQuery to detect the maximum height of all the products and apply that height to all the rest. I have tried removing all the jQuery in case this is affecting the z-index, but I get the same result only with an untidy look and feel.
I have tried using Google Chromes Inspect Element tool and the elements in question are showing the correct characteristics.
Can anyone see what I am doing wrong here? I have been trying to solve this for a couple of days now and would like to find out what is going on.
Thank you.
Regards,
Richard
Full code as requested:
I think this is all that is required. I will create a page with just this code in a few minutes, to see if it reproduces the problem.
<div id="BodyTag_ContentPanel">
<div class="overlay-background"></div>
<div class="scroll-pane">
<div>
<ul class="product-list">
<li class="product">
<div class="spacer">
<div class="opaque"></div>
<div class="product-info">
<img class="product-image" src="/Images/D3.jpg" />
<div class="enlarge">
<div class="image-enlargement">
<span class="close"><img src="/Images/close.jpg" /></span>
<div class="enlargement">
<div class="image-container"><img src="/Images/D3.jpg" /></div>
<div class="product-code"><span class="text-container">D3</span></div>
</div>
</div>
</div>
</div>
<div class="product-code">D3</div>
<div class="clear"></div>
</div>
</li>
</ul>
</div>
</div>
</body>
.product-list
{
list-style: none;
padding: 0;
width: 100%;
}
.product
{
width: 33%;
height: 25%;
float: left;
position: relative;
}
.product .spacer
{
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
margin: 10px;
padding: 5px;
border: 4px solid #C47F50;
position: relative;
}
.product .opaque
{
background-color: White;
-moz-opacity:.60; filter:alpha(opacity=60); opacity:.60;
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
z-index: 1;
}
.product .product-info
{
padding: 5px;
text-align: center;
z-index: 2;
}
.product .product-info .product-image
{
max-width: 200px;
max-height: 200px;
min-width: 150px;
min-height: 150px;
z-index: 2;
}
.product .product-code
{
position: absolute;
bottom: -15px;
width: 50%;
margin-left: auto;
margin-right: auto;
background-color: White;
text-align: center;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
border: 4px solid #C47F50;
line-height: 20px;
z-index: 2;
}
.product .image-enlargement
{
position: fixed;
display: none;
padding: 5px;
background-color: White;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
border: 4px solid #C47F50;
z-index: 103;
}
.product .enlarge
{
float: right;
}

I have found the solution!! I simply added position: relative; to .product-info. I can't believe I was so stupid as to not try that in the first place! Thanks for both your efforts #Thomas & Lazycommit. #Lazycommit your link came in handy - it confirmed that my code should have been working if it weren't for missing out the position: relative;. I noticed that they had set the position attribute for all of the divs in the example - this is what made me try it.

This is a big theme. U may look this page from Firefox developers for better understanding browsers stacking.

Try setting the z-index of the item that is supposed to be in the back to a negative number, like -1 :)

I know this is old, but you can use rgba() instead of opacity and get rid of the "product-info" div. This does the same effect you want since rgba() uses a different method of causing transparency that does not make the children elements go transparent as well. Makes doing the effect you wanted much easier.

if there is outer div to set position: fixed; and you need position: fixed; there add z-index same as inner div.
ex:
.notifications {
position: fixed;
width: auto;
max-width: 70%;
z-index: 9999;
}
.notifications > div {
position: relative;
z-index: 9999;
/* margin: 5px 0px;*/ /*default value*/
margin: 65px 10px;
display: inline-block;
}
will work fine.
But if notifications class like below it does not set z-index in chrome correctly.
.notifications {
width: auto;
max-width: 70%;
z-index: 9999;
}

Related

How do I stop my links from being clicked beneath it?

For some reason instead of only being able to click the links by clicking on the text, you can also click below it on empty space.
My friend said I had to reduce div size but I'm not quite sure on what he meant.
#video {
position: fixed;
right: 0;
bottom: 0;
min-height: 100%;
min-width: 100%;
}
#devil,
#steam,
#youtube {
display: block;
margin-left: auto;
margin-right: auto;
height: 230px;
width: 230px;
position: relative;
}
#steam,
#youtube {
text-decoration: none;
font-family: cursive;
font-style: oblique;
}
#devil {
border-radius: 120px;
top: 250px;
right: 20px;
}
#steam {
top: 280px;
left: 10px;
}
#youtube {
top: 50px;
left: 115px;
}
a:link,
a:visited {
color: forestgreen;
}
<div>
<img id="devil" src="img/frizzy.jpg">
</div>
<div>
<a id="steam" href="https://steamcommunity.com/id/impenetrable" target="_blank">steam</a>
<a id="youtube" href="https://www.youtube.com/c/ItsFrizzy" target="_blank">youtube</a>
</div>
Your problem is probably in here:
#devil,
#steam,
#youtube {
display: block;
margin-left: auto;
margin-right: auto;
height: 230px;
width: 230px;
position: relative;
}
You shouldn't need to set the height or width for your links, since they will be automatically set based on the text. You can use something like firefox tools to look at the bounding block of your links and see what's giving them the big space to click. You can even mess with the parameters here to suit your liking.
In your css, you specify height: 230px; for your element that holds the link. Decrease this size to remove the blank space that also responds to your mouse.
As suggested, use a border or background color to help indicate where your elements are, or use the development console (F12 in Chrome) to find your element sizes.
Instead of setting height to links you should set font-size for them and if this didn’t help set line-height same as font-size value.
You are getting a height on your anchors because you are applying a height to them (you should remove this). Also, I wouldn't use absolute or relative positioning for this as you do not need it. I would envelope your image and your social links in their own containers and position them. Here is an example of what I am talking about.
.container {
margin-top: 20px;
}
#video {
position: fixed;
right: 0;
bottom: 0;
min-height: 100%;
min-width: 100%;
}
.social_container {
margin: 0px auto;
padding: 10px;
width: 200px;
}
#steam,
#youtube {
margin: 0px auto;
width: 80px;
display: inline-block;
text-decoration: none;
font-family: cursive;
font-style: oblique;
text-align: center;
}
#devil {
border-radius: 120px;
display: block;
margin-left: auto;
margin-right: auto;
height: 230px;
width: 230px;
position: relative;
}
a:link,
a:visited {
color: forestgreen;
}
<div class="container">
<img id="devil" src="img/frizzy.jpg">
</div>
<div class="social_container">
<a id="steam" href="https://steamcommunity.com/id/impenetrable" target="_blank">steam</a>
<a id="youtube" href="https://www.youtube.com/c/ItsFrizzy" target="_blank">youtube</a>
</div>

Applying pseudo class "before" and "after" to multi-line text

I am trying to add a pseudo before and after vertical line to a textfield for styling purposes. These elements need to be flush to the text -20px left and -20px right.
This works fine when the text is on one line as an inline-block, but as soon as the text spans multiple lines the width expands to that of the parent and the pseudo elements are no longer just 20px from the text.
Is there a way in which I can accomplish this using CSS?
.container {
width: 500px;
background-color: red;
text-align: center;
margin-left: 40px;
}
h2 {
position: relative;
display: inline-block;
margin: 0;
padding: 0;
background-color: blue;
color: white;
}
span {
position: relative;
background-color: green;
}
h2::before,
h2::after {
content: '';
position: absolute;
top: 0;
width: 4px;
height: 20px;
background: black;
}
h2::before {
left: -20px;
}
h2::after {
right: -20px;
}
<!-- Single line example works as the black bars are 20px away from the start/end of text-->
<div class="container">
<h2><span>This is a title</span></h2>
</div>
<br> <br>
<!-- double line doesn't work because the h2 is now the full width of the container -->
<div class="container">
<h2><span>This is loooonnggggggggggggggggggggggeeeeerrr</span></h2>
</div>
Edit: Here is a working version using tables, but if anyone has a better solution I'd love to hear it: https://codepen.io/anon/pen/MqveLQ
So from what i can see is the issue here is where you are applying the borders with before and after. You need to alter where you apply your borders. Remove them from the h2, and add in a new html element that wraps the h2 and apply there.
eg:
<div class="container">
<div class="headerwrap">
<h2><span>This is loooonnggggggggggggggggggggggeeeeerrr</span></h2>
</div>
</div>
<div class="container">
<div class="headerwrap">
<h2><span>This is a title</span></h2>
</div>
</div>
CSS
.headerwrap::before,
.headerwrap::after {
content: '';
position: absolute;
top: 0px;
bottom:0;
margin:auto;
width: 4px;
height: 20px;
background: black;
}
.headerwrap::before {
left: 10px;
}
.headerwrap::after {
right: 10px;
}
Here is a working example: https://codepen.io/FEARtheMoose/pen/VGbJjO?editors=1100#0
Edit: altered example after comments - https://codepen.io/FEARtheMoose/pen/VGbJjO
I have moved your code to this fiddle: https://jsfiddle.net/n2Lr6xy5/13/ and removed position: absolute along with stripping out some of the other styles as they seemed unnecessary and I think I have created what you're after.
Here is the updated CSS:
.container {
width: 500px;
background-color: red;
text-align: center;
margin-left: 40px;
}
h2{
display: inline-block;
}
h2:after,
h2:before {
content: "";
width: 4px;
height: 20px;
background: #000000;
display: inline-block;
margin: 0 10px;
}

Crop a picture with CSS [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I am doing a Userstyle for a Website, so I can only change the CSS.
They generate their pictures with a white border at the top and the bottom which I want to get rid off.
The HTML-structure looks like this:
<a>
<img></img>
<span></span>
</a>
The span is a little coloured text-field, which overlaps the img, so putting overflow: hidden on the a doesnt work. (Because it will crop the span too)
I also tried using a border, but that didn't get me anywhere.
Is there another way?
EDIT: Here is a codepen of my problem
trautmann, take a look here:
https://jsfiddle.net/0qc27otz/
.wrapper {
background-color: grey;
padding-bottom: 4em;
padding-left: 4em;
padding-top: 4em;
width: 100%;
float: left;
}
div.wrapper a{
border: none;
display: block;
position: relative;
float: left;
width: auto;
height: 165px;
overflow: hidden;
}
div.wrapper a img{
display: block;
position: relative;
width: 100%;
margin-top: -5px;
}
.myspan {
display: block;
position: absolute;
bottom: 20px;
left: 5%;
width: 10%;
color: #FFF;
text-transform: uppercase;
font-weight: bold;
height: 16px;
background: red;
}
is that what you need?
As quantumwannabe said in the comments, you can use clip-path like so:
img {
-webkit-clip-path: inset(10px);
clip-path: inset(10px);
}
<img src="http://placehold.it/300x125">
Browser support is quite bad to be honest. Here's a fun tool to play with the property.
You can use clip-path on top and bottom, add this to your CSS, if the browser don't support clip-path it will not the end of the world, it will show the border image.
a > img{
/* top, right, bottom, left */
-webkit-clip-path: inset(2px 0px 2px 0px);
clip-path: inset(2px 0px 2px 0px);
}
Further Reading
Clipping in CSS and SVG — The clip-path Property and <clipPath> Element
Using clip-path
I suggest you to take a look here:
http://cssdeck.com/labs/full/1z7osafa
I added classes to img, a and wrapped everything to div.
So the main idea is to make to be blocks of definite height and hide the oversflow and also you can set any borders around.
Hope the code will be shown to you and you will understand it.
if no, here is html:
<div class='SomeWrapper'>
<a class='TheLinker' href='http://sdelanounas.ru/'>
<img class='TheIMG' src='http://sdelanounas.ru/i/c/2/r/f_c2RlbGFub3VuYXMucnUvdXBsb2Fkcy82LzkvNjk1MTM4NjU3MDk5NF9vcmlnLmpwZWc_X19pZD00NDYwMg==.jpeg'/>
<span class='sometext'>This Is a Great Plane</span>
</a>
<a class='TheLinker' href='topwar.ru/'>
<img class='TheIMG' src='http://cdn.topwar.ru/uploads/posts/2014-03/1395891634_2249x1444_su-34-frontovoj-zaschitnik-fullback.jpg'/>
<span class='sometext'>This Is a Great Plane</span>
</a>
</div>
Here is CSS:
div.SomeWrapper{
width: 100%;
display: block;
position: relative;
float: left;
}
div.SomeWrapper{
width: 100%;
display: block;
position: relative;
float: left;
}
a.TheLinker{
display: block;
position: relative;
float: left;
width: 48%;
margin: 0 1%;
height: 18em;
overflow: hidden;
}
a.TheLinker img{
width: 100%;
border: none;
}
span.sometext{
display: block;
position: absolute;
bottom: 1em;
background: rgba(255,255,255, 0.8);
color: #555;
text-shadow: #ccc;
width: 100%;
text-align: center;
}
a.TheLinker img{
width: 100%;
border: none;
}
span.sometext{
display: block;
position: absolute;
bottom: 1em;
background: rgba(255,255,255, 0.8);
color: #555;
text-shadow: #ccc;
width: 100%;
text-align: center;
}
I'm a newbie here so my code could be not properly formed, so sorry if something's not looking good..
If you have questions - ask, I think I really can help!

Difficulties with div and id arrangement when making my own header bar

I'm trying to make a header bar that looks similar to Bootstrap. If you view this document now the problem is that 'Item 1' is displayed correctly but 'Item 2' is pushed below it, instead of being to the right of it. I thought that by setting "left:80px' to 'Item 2' it would go 80px right of item 1.
Please let me know how to fix this. I was also wondering if I'm doing this in a smart way or if stacking the elements (.items > #item_1) is better. Thanks!
CSS
/* header, logo, and items */
#header {
width: 100%;
height: 45px;
position: absolute;
top: 0px;
left: 0px;
background: #3b5998;
text-align: left;
box-shadow: 0px 1px 0px #888888;
}
.items {
top: 0px;
right: 0px;
width: 200px;
height: 23px;
padding-top: 11px;
padding-bottom: 11px;
position: absolute;
background: #3b5928;
text-align: center;
font-family: 'Calibri';
font-size: 18px;
color: #f7f7f7;
}
#item_1 {
width:80px;
background: fff;
}
#item_2 {
width: 80px;
left: 80px;
background: #3b7328;
}
HTML
<!--Header and Footer-->
<div id="header">
<div class="items">
<div id="item_1"> Item 1 </div>
<div id="item_2"> Item 2 </div>
</div>
</div>
One approach would be to change the display of the elements to inline-block. (example)
.items > div {
display:inline-block;
}
Alternatively, you could float the elements or use a flexbox layout.
It's worth noting that you can't position a static element (i.e., position:static - the default). If you wanted left: 80px to work, you could add position:relative or position:absolute - fixed would work too. (example) As the example demonstrates, this isn't really an effective way to line the elements up though. It would be better to either float them or make them inline.
#item_2 {
width: 80px;
left: 80px;
background: #3b7328;
position: relative;
}
Here is a JS Fiddle, next time you should set one up. It's very useful for other people to see your issue.
<!--Header and Footer-->
<div id="header">
<div class="items">
<div id="item_1"> Item 1 </div>
<div id="item_2"> Item 2 </div>
</div>
</div>
#item_1 {
width:80px;
color: black;
background: #fff;
position: relative;
float: left;
display: inline-block;
}
#item_2 {
float: left;
width: 80px;
background: #3b7328;
position: relative;
display: inline-block;
}
http://jsfiddle.net/ws5ew/

pixel difference between Chrome and FF

I'm trying to make a "step by step", but i'm heaving some problems with pixel difference between chrome and FF.
so, all steps are dynamic and should be in the middle, some times can appear only two, three our 5 options, thats why i'm making a sub-line for each side, to reach the end of the wrapper.
This lines are the problem, they are making 2 our 1 pixels difference.
i'm missing something or in this case, we should make a "workaround" ?
will be more simple if you see in action here: jsfiddle
for those who wants to see the code directly here:
html:
<article id="people-add">
<nav>
<div class="step-wrapper">
<div class="base-left-line"></div>
<div class="step first-step">
<div class="active-stepc step-circle"></div>
<span class="step-label">
Step 1
</span>
</div>
<div class="step">
<div class="step-line"></div>
<div class="step-circle"></div>
<span class="step-label">
Step 2
</span>
</div>
<div class="step">
<div class="step-line"></div>
<div class="step-circle"></div>
<span class="step-label">
Step 4
</span>
</div>
<div class="step">
<div class="step-line"></div>
<div class="step-circle"></div>
<span class="step-label">
Step 5
</span>
</div>
<div class="base-right-line"></div>
</div>
</nav>
</article>​
and css:
#people-add {
float: left;
width: 100%;
}
#people-add nav {
padding: 5px 0 60px 0;
}
.step-wrapper {
float: left;
width: 100%;
text-align: center;
position: relative;
}
.step {
display: inline-block;
position: relative;
width: 120px;
}
.first-step {
width: 0 !important;
}
.step .step-label {
position: absolute;
right: -35px;
bottom: -30px;
font-size: 12px;
width: 96px;
text-align: center;
font-weight: bold;
color: #818181;
}
.step .step-line {
border-bottom: solid #E5E5E5 2px;
position: absolute;
right: 5px;
top: -2px;
z-index: 12;
width: 120px;
}
.step .step-circle {
background-color: #B3B3B3;
border: solid 4px #E5E5E5;
width: 20px;
height: 20px;
border-radius: 50px;
position: absolute;
right: -1px;
top: -15px;
z-index: 13;
}
.base-left-line,
.base-right-line {
position: absolute;
width: 50%;
top: 12px;
z-index: 1;
}
.base-left-line {
border-bottom: 2px solid #9BBD5E;
left: 0;
}
.base-right-line {
border-bottom: 2px solid #9BBD5E;
right: 0;
} ​
print:
as you can see, the green line in FF are crossing all over the graylines in the middle of steps.
Okay, I (just like many others who commented) did not see the same difference you show between my Chrome and Firefox, and neither browser was behaving for me as you show you desired in your picture.
I did, however, note some odd behaviors of the lines when I zoomed in and out in the browsers. This lead me to look more carefully at your code, and I feel that the reason you are seeing some differences (and the inconsistencies for us all) is because of how you have positioned the lines. I recommend the following changes (I only note those, not all your code), as seen in this fiddle, which may fix your issues.
Explanation
The vertical-align is normally bottom by default on inline-block, and since you are positioning your .base-[left/right]-line elements by a top position, it is better to do so for the elements inside the .step that are intended to overlap those. So...
ADD
.step {
vertical-align: top; /* ADDED THIS so that dimensions come from the top */
}
CHANGE
.step .step-label {
bottom: -45px; /* CHANGED THIS for the vertical align top */
}
.step .step-line {
top: 12px; /* CHANGED THIS, which now matches offset of the baselines */
}
.step .step-circle {
top: 0; /* CHANGED THIS */
}