Z index problem

hi alli feel like an idiot posting this,
but for some reason z-index stumps me

Im trying to create z-index on this page: http://bluecrushdesign.co.za/templates/leftnavblue

See the bottom of the page?

I want the heading " range 1" to lie ABOVE the backpacker image as in a layer above so that it ends up covering some of the backpack.

I know i can do this with a background image in the DIV but need to know the z-index way to, in case the devs prefer this for clients.
Ive positioned both, ive given both a z-index value

Can anyone help? (inspect element/view css to see what ive done)

Ps does anyone know why my hover on the navigation elements doesnt work in IE8?appreciate it!

You’d need to apply a z-index to your heading.

.producthome h4 {
 position:relative;
 z-index:100;
}

Edit: Regarding your navigation links: I just saw that you are using RGBA values for your :hover state. IE8 and lower do not support that property.

Maleika, beat me to it on both counts.

To elaborate on the Z index issue:
1)In order to utilize z-index the element must have : relative, fixed or absolute position.
2) By default elements that come later in the source code have a “higher calculated default index” ( stacking order) than previous elements. To see what I mean DONT do what Maleika suggested, instead put the IMG tag before the H4 in your source code. Of course the problem would be that, tho it fixes your presentation issue, it isnt very semantic to do it that way. So we HAVE to play the z-indexes of the children .producthome … and thus we need to give the h4 position relative, as Maleika suggested.

Just using position: relative and z-indexes won’t get you the whole way, though. You’d then need to pull the image upwards if you want it to sit under the title. E.g.

.producthome img {
  position: relative;
  [COLOR="#FF0000"]top: -50px;[/COLOR]
  z-index: 10;
}

hey guys,
i already had this on my h4 in my CSS, so i get that you need to use position on it as i was using it!:

position:relative;z-index:100;so this edit didnt help…:
.producthome h4 {position:relative;z-index:100;}

ralphs edit did though! the top -50px worked :wink: thanks!!
what would one do if they want the img to centre horizontally and vertically?

Ps RE - IE8
by the way its not the RGBA value that i am trying to get working in IE8 -
i have already got that working ( you can use a conditional statement- look at my code at the top - do you see my header has an RGBA value and its transparent in IE8?
:wink:

im trying to get the hover to work…regardless of using RGBA or other for hover state…
any ideas?

Ideally, set it as a bg image on the div … But anyhow, since it’s currently positioned relatively, you can just give it a top and left setting that moves it where you want.

hey there,
but there might be a different size image it it next time (this is for templates - that image is just a default image)

so we cant centre it using top/left or position relative/z index?

If the image container is a fixed height and width then you can use text-align:center and line-height to center the image.

Here is an example:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<style>
.imgcontainer {
	width:150px;
	height:160px;
	line-height:160px;
	border:1px solid #000;
	text-align:center;
	overflow:hidden;
}
* html .imgcontainer{font-size:145px}/* approximation for IE6 as it doesn't center with line height on images*/
*+html .imgcontainer{font-size:145px}/* approximation for IE7 etc.*/
.imgcontainer img { display:inline;vertical-align:middle; }
</style>
</head>

<body>
<div class="imgcontainer"><img src="img1.jpg" width="118" height="125" alt="test"></div>
<div class="imgcontainer"><img src="img2.jpg" width="50" height="75" alt="test"></div>
</body>
</html>

The element called .imgcontainer should hold only the single image and no text.

thanks paul, ok so id need to create a div for the image, and a div for the h4 text…?

This way would be an alternate way to using a background image on a div,…

I have actually used the background image on a div now:
http://bluecrushdesign.co.za/templates/leftnavblue[COLOR=#464646] [/COLOR]

thing is , i want to get hover and background colour working on IE,
and i can only get background colour working

what would you suggest?
do i use the alternative way as paul suggests and try get hover to work

or is there a fix for background image in css and hover/background color to work in IE?

(stock answer #3) A lot of your issues IMHO start with your nonsensical markup – exacerbated by the use of that HTML 5 idiocy when you’re not even USING any HTML 5 in your actual markup. A “slogan” is not the start of a new subsection, why does it warrant a h2… you don’t have meaningful H2’s or H3’s, so why are those H4’s in there? While the nonsensical half-assed HTML 5 rule may allow you to wrap block level tags in anchors, browser support is nonexistent. You also appear to be using a bunch of DIV and ID’s that IMHO probably aren’t even necessary… and to be brutally frank, if you have to resort to filters for silly things like gradients or IE conditionals for CSS, there’s probably something fundamentally wrong with how you are building the page.

… and that’s before we even TALK CSS. You’re “reset” goes a little overboard pissing on accessibility by messing with outline, the HTML font-size is redundant nonsense, you don’t explicitly state a line-height, you’re using div.clear like it’s still 1998, you’re redeclaring font sizes without restating line-heights causing inheritance issues when %/EM actually do their job, you seem to be using oddball fractional sizes that don’t round off the same cross browser, you’ve got multiple classes that appear to be redundant to each-other with 90%+ of their properties… and of course since legacy IE knows not RGBA, there’s why your hover states don’t work in IE8-. Of your 3.5k of CSS I’d ballpark 15% or more should go on the cutting room floor.

So first step is let’s swing an axe at the HTML 5 nonsense, and try to get you some actually semantic markup in there.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html
	xmlns="http://www.w3.org/1999/xhtml"
	lang="en"
	xml:lang="en"
><head>

<meta
	http-equiv="Content-Type"
	content="text/html; charset=utf-8"
/>

<meta
	http-equiv="Content-Language"
	content="en"
/>

<link
	type="text/css"
	rel="stylesheet"
	href="screen.css"
	media="screen,projection,tv"
/>

<title>
	Your Business Name
</title>

</head><body>

<div id="pageWrapper">

	<h1>
		Your Business Name
		<small>
			<span>Your Business Slogan</span>
			+254 202 902 000
		</small>
	</h1>
	
	<div id="cartStatus">3 Items</div>

	<ul id="mainMenu">
		<li><a href="#" class="current">home</a></li>
		<li><a href="#">range 1</a></li>
		<li><a href="#">range 2</a></li>
		<li><a href="#">custom page</a></li>
		<li><a href="#">contact us</a></li>
		<li><a href="#">view cart</a></li>
		<li><a href="#">404</a></li>
		<li><a href="#">product not found</a></li>
	</ul>
	
	<hr />

	<div class="contentBox">
		<img
			src="placeHolder"
			alt="Image Here"
			class="trailingPlate"
		/>
		<p>
			Pellentesque at augue. Etiam quis enim. Suspendisse tincidunt consectetuer sem. Morbi quis velit. Nulla vel dui. Praesent eros odio, fringilla sit amet, tincidunt sed, accumsan ac, erat. Nullam ultricies luctus ligula.
		</p><p>
			Pellentesque at augue. Etiam quis enim. Suspendisse tincidunt consectetuer sem. Morbi quis velit. Nulla vel dui. Praesent eros odio, fringilla sit amet, tincidunt sed, accumsan ac, erat. Nullam ultricies luctus ligula. Pellentesque at augue. Etiam quis enim. Suspendisse tincidunt consectetuer sem. Morbi quis velit. Nulla vel dui. Praesent eros odio, fringilla sit amet, tincidunt sed, accumsan ac, erat. Nullam ultricies luctus ligula.
		</p>
	<!-- .contentBox --></div>
		
	<hr />
	
	<ul class="ranges">
		<li>
			<a href="#">
				<span>Range 1</span><br />
				<img src="images/range1.png" alt="Range 1" />
			</a>
		</li><li>
			<a href="#">
				<span>Range 2</span><br />
				<img src="images/range2.png" alt="Range 2" />
			</a>
		</li><li>
			<a href="#">
				<span>Range 3</span><br />
				<img src="images/range3.png" alt="Range 3" />
			</a>
		</li><li>
			<a href="#">
				<span>Range 4</span><br />
				<img src="images/range4.png" alt="Range 4" />
			</a>
		</li><li>
			<a href="#">
				<span>Range 5</span><br />
				<img src="images/range5.png" alt="Range 5" />
			</a>
		</li><li>
			<a href="#">
				<span>Range 6</span><br />
				<img src="images/range1.png" alt="Range 6" />
			</a>
		</li>
	</ul>
		
<!-- #pageWrapper --></div>

</body></html>

Which despite the heavier comments and ‘wasteful bloated’ HTML4/XHTML1.0 style header, is still a smaller file thanks to axing all the ‘div for nothing’ and use of semantic markup – surprising since I changed what appear to be content images (product pictures) into IMG tags. Remember content images (product thumbnails, gallery pictures, etc) go in IMG, everything else is presentational (border images, cutesy icons next to text) belong in the CSS.

so how about some CSS for that?


/* null margins and padding to give good cross-browser baseline */
html,body,address,blockquote,div,
form,fieldset,caption,
h1,h2,h3,h4,h5,h6,
hr,ul,li,ol,ul,dl,
table,tr,td,th,p,img {
	margin:0;
	padding:0;
}

img,fieldset {
	border:none;
}

hr {
	/* In my code HR are for semantics and non screen.css users */
	display:none;
}

body {
	text-align:center; /* center #pageWrapper legacy IE */
	font:normal 85%/150% verdana,helvetica,sans-serif;
	background:#187CA7 url(images/bodyBackground.jpg) top center repeat-x;
}

#pageWrapper {
	position:relative;
	width:95%;
	min-width:752px;
	max-width:68em;
	margin:0 auto;
	padding:3em 0 1em;
	text-align:left;
}

h1 {
	padding:0.5em;
	margin-bottom:1px;
	font:normal 180%/130% arial,helvetica,sans-serif;
	color:#333;
	background:#C5E0EB; /* for browsers that don't know RGBA */
	background:rgba(255,255,255,0.75);
}

h1 small {
	overflow:hidden; /* wrap floats */
	width:100%; /* trip haslayout, wrap floats legacy IE */
	display:block;
	text-align:right;
	font:normal 65%/130% verdana,helvetica,sans-serif;
}

h1 small span {
	float:left;
}

p {
	padding-bottom:1em;
}

#cartStatus {
	position:absolute;
	top:0.5em;
	right:0.5em;
	padding-left:28px;
	white-space:nowrap;
	font:normal 120%/150% verdana,helvetica,sans-serif;
	color:#FFF;
	background:url(images/cart.gif) center left no-repeat;
}

#mainMenu,
.ranges {
	overflow:hidden; /* wrap floats */
	width:100%; /* trip haslayout, wrap floats IE */
	margin-bottom:1em;
	list-style:none;
}

#mainMenu li,
.ranges li {
	display:inline; /* basically remove from flow, avoid IE7 headaches */
}

#mainMenu a,
.ranges a {
	float:left;
	display:inline; /* prevent IE margin doubling */
	margin:0 1px 1px 0;
	text-decoration:none;
	font:normal 110%/120% verdana,helvetica,sans-serif;
	text-align:center;
	color:#000;
	background:#C5E0EB; /* for browsers that don't know RGBA */
	background:rgba(255,255,255,0.75);
}	
	
#mainMenu a {
	padding:0.3em 12px; /* using px side padding in case you're adding icons */
}

.ranges a {
	position:relative;
	width:182px;
	height:160px;
}

#mainMenu a.current,
#mainMenu a:active,
#mainMenu a:hover {
	background:#D5D55E; /* for browsers that don't know RGBA */
	background:rgba(243,226,78,0.85);
}

.ranges a:active,
.ranges a:hover {
	background:#97C4D8; /* for browsers that don't know RGBA */
	background:rgba(255,255,255,0.55)	
}

.ranges a span {
	position:absolute;
	left:0;
	bottom:16px;
	padding:0.25em 0.5em;
	background:#FFF;
}

.contentBox {
	overflow:hidden; /* wrap floats */
	height:1%; /* holly hack, trip haslayout, wrap floats IE */
	padding:1em 1em 0;
	margin-bottom:1em;
	background:#D5D55E; /* for browsers that don't know RGBA */
	background:rgba(243,226,78,0.85);
}

/* standard image content plates */

.leadingPlate {
	float:left;
	margin:0 1em 1em 0;
}

.trailingPlate {
	float:right;
	margin:0 0 1em 1em;
}

.plate {
	display:block;
	margin:0 auto 1em;
}

Which you can find a live demo of here:
http://www.cutcodedown.com/for_others/escapedf/template.html

As with all my examples the directory:
http://www.cutcodedown.com/for_others/escapedf/

Is wide open for easy access to the bits and pieces.

Valid XHTML 1.0 Strict, Valid CSS 2.1 apart from the RGBA declarations, Tested working all the way back to IE 6… Though admittedly legacy IE doesn’t get the transparencies (oh noes, not that!). I also did some image optimizations since at 289k total your original was TWICE the upper limit I’d allow for a page and almost four times my ideal target. This rewrite comes out to 55k thanks to cropping the redundancies out of the body background, saving it as jpeg, switching the ‘range’ images and cart to palette transparency, and of course the smaller source code.

Hope this helps. Basically I think you were diving for DIV before you were thinking semantics, which combined with failing to grasp element inheritance in your CSS was leading you down the path towards a ‘non-viable’ layout and overcomplicated code. Don’t worry, it happens to all of us at the start.

im actually unbelievably shocked at your reply! People are in here to learn, not to get insulted.

This is my first stab at HTML5 and CSS 3 …as my client has asked for this.
I am just learning all this, new to HTML5 etc … did you even think that maybe that was the case?

If anyone can help me without being condescending, and actually on this site to help, id appreciate it.
It needs to be HTML5 … and im still learning it

Thanks

… and where was I insulting YOU? I insulted HTML 5 not YOU… excepting perhaps the choice… and if the choice is the clients, you need to educate the client that there’s more to websites than goofy buzzwords and specifications that are DECADES away from being practical in the real world, particularly if you care about legacy support… and that to be frank are doing nothing but undoing the past decade of progress in coding sites!

You want to learn about HTML 5? It’s rubbish in it’s current form, and I advise AGAINST adopting it – in fact it’s like a cancer eating way at the Internet. I took the time to show you how to reduce the code, simplify the code, and build the site in a more practical manner with semantic markup – learn from that. “Needs to be HTML 5” usually means your client is running their mouth about things they don’t even understand…

But of course, you state a dislike for a stupid new trend and poor choices in doing work, it must be a personal attack – RIGHT. I find that attitude many times more insulting than flat out profanity.

chill out dude … as mentioned it needs to be HTML5… so ill repost my last comment before all this sidetracking, for the other users who may have come across this too or can help : thanks paul, ok so id need to create a div for the image, and a div for the h4 text…?This way would be an alternate way to using a background image on a div,…I have actually used the background image on a div now:http://bluecrushdesign.co.za/templates/leftnavblue …thing is , i want to get hover and background colour working on IE,and i can only get background colour workingwhat would you suggest?do i use the alternative way as paul suggests and try get hover to work or is there a fix for background image in css and hover/background color to work in IE? Thanks all

Don’t take Jason’s comments to heart as his dislike is for html5 and not meant to be aimed at you specifically. However, the code he has offered does address all of your problems in a much more solid and reliable way. If your client wants html5 then all you need to do is throw the html5 doctype on it and no one will know any different -especially your client.:slight_smile:

.I have actually used the background image on a div now:http://bluecrushdesign.co.za/templates/leftnavblue …thing is , i want to get hover and background colour working on IE,and i can only get background colour workingwhat would you suggest?do i use the alternative way as paul suggests and try get hover to work or is there a fix for background image in css and hover/background color to work in IE? Thanks all

I must admit I got lost in the logic of your code and it seems to me that IE9 doesn’t need any of those conditional comments at all and just giving them to less than IE9 should solve your IE9 hover problems.


<!--[if lt IE 9]>

I don’t understand why you are removing the background image and colours .What is this code supposed to be doing?


.producthome1, .producthome5 {
  background: transparent;
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#90FFFFFF,endColorstr=#90FFFFFF);
}

You’ve stopped the image from showing with background:transparent and then you’ve set a gradient filter that has no gradient.

I assume you are using it for transparency but I think you need to have a background-color for that to work.

Or have I missed the point as I try to avoid the IE filters where possible? If you wanted to to stop the background-color then you should use background-color:transparent and that would allow the image to show but I’ve no idea why the IE filter is needed unless it’s the transparency side effect and then I think you need a background-color. You should know that the IE filters usually break any of IE9’s css3 capabilities and things like border-radius and shadows won’t work properly if the filter is applied to the element as well (not to mention many other bugs).

As Jason already said don’t wrap block level elements inside anchors even though its allowed in html5 it just doesn’t work in the real world and browsers just don’t like it at all. I’ve seen many examples now of sites that are broken because of wrapping anchors around block elements that I strongly advise against it until browsers catch up - and even then I still think its an ugly and mostly unnecessary construct.

I’m not sure if any of that answers your question but I would urge you to check out Jason’s example just to see how he has handled some of the issues you are having. I’ll be back tomorrow if none of that makes any sense

Microsoft filters are ARGB, not RGBA – so that #90 is an attempt to use the gradient filter to make a solid transparency.

The solution I used in my rewrite was to simply feed IE solid colors instead of using filters to make transparencies in browsers that don’t do transparencies well. It ends up the same general color and apart from way up top behind the heading you’d never really notice the difference.

If you declare a background color the filter will be applied over it – switching the background to transparent means the filter is applied to BODY instead of to the element’s background.

Which is why I was asking why the block level containers in the first place – and why I swapped those out for a LIST – with said list set to wrap floats and then floating the anchors… basically making all the ‘content’ parts inline-level. I assumed the reason they had hovers was they were all supposed to be anchors, and I was sitting there scratching my head going “why are these H4?!?” since from a semantic standpoint… they aren’t headings. There’s no content in there for each so they aren’t the start of subsections – and with no H3 or proper H2 preceding them it’s just wrong to be all the way down to a 4… even with the h2 doing a small tag’s job using a 3 would just mean they’re a subsection of that h2… which they obviously aren’t.

… just like the h2 ‘starting a section’ that isn’t a subsection – hence in my version the entire header being… in a single header tag.

Just like how this on .mid:
height: 200px;

results in a broken layout at large fonts with the text blowing out the bottom of the box, or this on #cart:
width: 65px;

breaks the cart into two lines with “items” stretching down over the heading.

http://www.cutcodedown.com/for_others/escapedf/images/broken.jpg

Which is why it’s bad practice to declare fixed heights on content areas or really narrow fixed widths with dynamic font elements inside them.