Lowering z-index causes descendant elements to become unclickable - html

I have a (CSS) stacking question.
The tab-boxes on my development site below have z-index set as -1 so that their border appears behind the tabs above them, so that the active tab's white bottom border covers it. But on all browsers but Opera this makes descendants of the tab-boxes (links, forms, etc.) unclickable. You can see this at:
http://od.philosofiles.com/
Can anyone help? Here's the bare bones of the HTML and CSS, though examining the link above with Firebug would probably be more illuminating:
<ul class="odtabs">
<li id="tab-Authors1" class="first active">Tab</li>
</ul>
<div id="tab_content-Authors1" class="odtab-content">
<p>Tab Box</p>
</div>
<style type="text/css">
<!--
.odtabs li {
float: left;
background-color: #ddd;
width: 80px;
height: 19px;
list-style-type: none;
}
.odtabs li.active {
background-color: white;
border-bottom-color: white;
}
.odtab-content {
border: 1px solid #babcbd;
margin-top: -1px;
clear: both;
position: relative;
top: -1px;
z-index: -1;
}
-->
</style>

Set z-index to -100.
.odtab-content {
border:1px solid #BABCBD;
clear:both;
font-size:0.9166em;
margin-top:-1px;
padding:0 1em;
position:relative;
top:-1px;
z-index:-100;
}

I finally fixed this myself, after a lot of experimentation with line-by-line reconstruction. I believe the problem was due to the z-index being negative; however, the only way to make it work with a positive z-index and a higher positive z-index was to set position: relative on the tabs, which required quite a different approach. (Apparently z-index only works on absolute, relative or fixed positioned elements.) Here, for those interested/with similar problems, is the full CSS I used:
ul.odtabs {
display: inline;
margin: 0;
padding: 0;
}
.odtabs li {
float: left;
background-color: #ddd;
border: 1px solid #babcbd;
width: 80px;
height: 19px;
margin-right: 2px;
text-align: center;
list-style-type: none;
position: relative;
z-index: 2;
}
.odtabs li.active {
background-color: white;
border-bottom-color: white;
}
.odtabs a {
color: #78797c;
font-size: 0.75em; /* 9px = 12*0.75 */
font-weight: bold;
margin-top: 0px;
padding-top: 0px;
}
.odtabs .last {
margin-right: 0px;
}
.odtab-content {
font-size: 0.9166em;
border: 1px solid #babcbd;
padding: 0px 1em; /* ie. 12px */
clear: both;
position: relative;
top: -1px;
z-index: 1;
}

Related

How could I show my navigation bar over my body / section text?

My problem is when I scroll up, the text on the page goes through my navbar and it looks really unprofessional and I need to fix it. I want to make it so that my navigation bar is layered on top of my body / section text (body text includes navigation bar but section only includes text not on my nav bar),
I tried adding a background-color and that worked except when I used my dark / light mode switcher, I have css properties for dark mode and light mode but I can't use a background color otherwise when you switch, it will still show the background color for light mode (or whatever mode you were deigning for).
I also tried Z-Indexes since that is supposed to work but no, literally did nothing. Which was really weird. I wish I could elaborate more but that's all I can say, it just didn't work. Here is an example of what I did but I can't actually show you the exact code since I already deleted those Z-Indexes since they didn't work.
EXAMPLE NAV BAR CSS {
z-index: 100;
}
EXAMPLE SECTION / TEXT CSS {
z-index: -100;
}
Here's my navigation bar code:
<ul>
<div class="without-dark-ul">
<img class="logo" width="100px" src="\imgs\logo.png">
<h1 class="logo-side">[PRIVATE] Accounting</h1>
<h2 class="logo-side-slogan">The best, afforadable accounting.</h2>
<br>
<hr>
<h3 class="navbar-text">Navigation</h3>
<div class="navbar">
<li><a class="main-nav" href="#">Home</a></li>
<li>Pricing</li>
<li>Contact</li>
</div>
<div class="vl"></div>
<h3 class="dark-mode-text">Dark / Light Mode</h3>
</div>
<div class="ul-dark">
<li class="li-dark">
<span>Dark</span>
<span>Light</span>
</li>
</div>
</ul>
And here's my CSS for my navbar (and I've got some in navbar CSS and some in dark mode CSS, I honestly don't know why I did it like that though.)
/* START NAVBAR */
.logo-side {
margin-left: 140px;
margin-top: -95px;
font-size: 40px
font-
}
.logo-side-slogan {
margin-left: 140px;
margin-top: -30px;
}
.logo {
margin-top: 20px;
margin-left: 20px;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
position: fixed;
/* position: -webkit-sticky; Safari */
/* position: sticky; */
top: 0;
width: 100%;
z-index: 100;
}
ul > hr {
margin-left: 10px;
margin-right: 10px;
margin-top: -10px;
}
li {
float: left;
}
li a {
display: block;
text-align: center;
padding: 14px 16px;
text-decoration: none;
color: inherit;
}
li a:hover {
background-color: rgb(105, 103, 103);
}
.main-nav {
background-color: #383838;
color: white;
}
.navbar {
margin-left: 20px;
margin-top: 30px;
padding-bottom: 70px;
}
.navbar-text {
margin-left: 20px;
margin-bottom: -20px;
}
.navigation-bar {
background-color: #262626;
position: absolute;
}
/* END NAVBAR */
/* START DARK MODE */ (This includes some nav bar CSS properties.)
.li-dark {
list-style: none;
width: 100%;
height: 60px;
text-align: center;
text-transform: uppercase;
transition: 0.5s;
}
.ul-dark.active li {
transform: translateY(-30px);
}
ul li span {
display: block;
height: 30px;
line-height: 30px;
width: 100%;
}
ul li span:nth-child(1) {
background: #262626;
color: #fff;
}
.ul-dark {
position: static;
top: 20px;
right: 20px;
margin-top: 25px;
margin-left: 320px;
padding: 0;
width: 100px;
height: 30px;
border: 1px solid #000;
cursor: pointer;
overflow: hidden;
}
.dark-mode-text {
margin-left: 320px;
margin-top: -113px;
}
/* END DARK MODE */
I don't know if that is all you need but please ask me to send more code if you need more!
Thanks for your help.
Solninja A
give a position relative to body and your text parent
and z-index:10000;

Border line next to text

I have a p tag. I want a border line next to it.
<p style="margin-left: -30px;font-size: 12px;margin-bottom: 2px;"><strong> Categories</strong></p>
I want to add a line next to p tag as the following image.
How can i implement it?
Please help,
Thanks
There are many other ways to achieve this, one of them would be applying a border-bottom to a pseudo-element (which establishes a new block formatting context in order to prevent overlapping) and floating the <strong> element to the left:
p.hasBorder {
overflow: hidden; /* Establish a new block formatting context */
}
p.hasBorder > strong {
float: left;
}
p.hasBorder:after {
content: "";
display: block;
border-bottom: 3px solid silver;
overflow: hidden; /* Establish a new block formatting context */
height: 1em; /* Up to you */
}
<p class="hasBorder">
<strong>Categories</strong>
</p>
Use a pseudo element
Jsfiddle Demo
CSS
p {
font-size: 12px;
margin-bottom: 2px;
overflow: hidden;
position: relative;
}
p:after {
content:"";
position: absolute;
border-bottom:1px solid grey; /* border-size & color are now controllable */
width:100%;
height:1em;
display: inline;
margin-left: 1em;
}
p {
margin-left: 0px;
font-size: 12px;
margin-bottom: 2px;
position: absolute;
margin-top: -7px;
background-color: #fff;
color: #333;
padding-right: 5px;
}
.line-back {
border-bottom: 1px solid #ccc;
margin: 25px;
}
<div class="line-back">
<p>
<strong> Categories</strong>
</p>
</div
p{
}
P:after{
content:'________';
}
DEMO
JS Fiddle
p {
font-size: 12px;
margin-bottom: 2px;
position:relative
}
p::after {
content:"";
border-bottom:1px solid grey;
width:100px;
position:absolute;
bottom:2px;
}

CSS navigation horizontal submenu not directly below parent

I am a little stuck. I am trying to build a horizontal navigation bar, 1024px across, which will allow for a submenu to display below it. But i want the submenu to also be 1024px in width and to display directly below the navigation bar, vertically aligned.
At the moment the submenu appears but fixes its left side to the left side of the current li that you are hovering over. How can I fix this?
Thanks!
EDIT: So on mouse over it would look something like this: http://eventav.biz/site/example.jpg
Link to what I've done so far -
http://www.eventav.biz/site/
ul.top_menu {
position: relative;
margin: 0;
margin-bottom: -1px;
list-style: none;
display: table;
width: 1024px;
border: 1px solid #111111;
border-bottom: 1px solid #000000;
border-radius: 10px 10px 0px 0px;
}
.top_menu li {
display: block;
position: relative;
border-right: 1px solid #111111;
float: left;
margin: 0px;
display: table-cell;
vertical-align: middle;
}
.top_menu li:first-child {
border-left: 1px solid #111111;
}
.top_menu li a {
display: block;
text-decoration: none;
color: #000000;
text-shadow: 3px 3px 8px #3A3A3A;
padding: 15px;
height: 30px;
display: table-cell;
vertical-align: middle;
margin: 0px;
}
#top_menu_item ul {
display: none;
margin: 0px;
}
#top_menu_item:hover ul {
display: block;
position: fixed;
margin: 0;
}
#top_menu_item:hover li {
width: 1024px;
background-color: #666;
text-align: left;
color: #FFF;
font-size: 12px;
margin: 0px;
}
<ul class="top_menu">
<li id="top_menu_item">HOME</li>
<li id="top_menu_item">OUR SERVICES
<ul><li id="top_menu_item">test</li></ul>
</li>
<li id="top_menu_item">EXAMPLES OF OUR WORK
<ul><li id="top_menu_item">test</li></ul>
</li>
<li id="top_menu_item">CONTACT US</li>
</ul>
Remove the fixed positioning from the child ul, and replace it with position:absolute. Add in left:0px, and then remove position:relative from the parent li.
Working jsFiddle example
#top_menu_item:hover ul {
display: block;
position: fixed; /* Change this to position:absolute; */
left:0px; /* Add this */
}
.top_menu li {
display: block;
position: relative; /* Remove this */
}
1) Remove position: relative; from #top_menu_item
2) Set #top_menu_item ul to position: absolute; left: 0; instead
3) Remove left padding on #top_menu with padding-left: 0;
4) Add:
#top_menu_item:first-child {
margin-left: 40px;
}
Essentially, the problem was that you've been positioning your inner ul tag relative to it's parent li. Instead, the solution above positions the secondary navigation absolutely in relation to the primary navigation, and we use left: 0; to make sure it's completely left-aligned.
It's also against the standard to use an id multiple times on a page. Therefore I'd recommend changing #top_menu_item into .top_menu_item and changing the HTML accordingly.
Let me know if you have any problems!

Centering ul inside container with responsive web design

So I'm trying to keep an unordered list centered once the website hits a certain media query. I can't get it to stay in the center of it's container if the page is moved around. Here is the corresponding code.
HTML
<div id="centerNav">
<ul id="home-nav">
<li>DUI/DWI Defense</li>
<li>Criminal Defense</li>
<li>Estate Planning</li>
<li style="border: none;"> Agricultural Law</li>
</ul>
</div>
CSS
#media only screen and (max-width: 839px)
{
#centerNav {
margin: 0 auto;
max-width: 840px;
padding: 0;
height:60px;
}
#home-nav li {
float: left;
position: relative;
display: block;
text-align: center;
background: none;
font-size: 20px;
width: 158px;
border-right: 1px solid #fff;
margin-top: 8px;
line-height: 1em;
padding-left: 10px;
}
#home-nav {
list-style:none;
position:relative;
height: 60px;
vertical-align: middle;
z-index: 5;
border-top: 4px double #fff;
border-bottom: 4px double #fff;
border: none;
margin: 0;
background: #7a0426;
}
}
Remove float from li and make it display: inline-block
I think this will solve your issue.
css
#centerNav {
margin: 0 auto;
max-width: 840px;
padding: 0;
height:60px;
text-align:center;
}
#home-nav li {
position: relative;
display: inline-block;
text-align: center;
background: none;
font-size: 20px;
border-right: 1px solid #fff;
line-height: 60px;
padding:0 10px;
}
jsFiddle Code
In your media query you need to make sure float is none because you have float set from previous css
#home-nav li {
float: none;
display: inline-block;
}
The unordered list that contains the li, add text-align: center
#home-nav {
text-align: center;
}
Also your html structure is currently invalid because you have a div as the immediate child of a ul. You can wrap the ul with the div if you need to but it definitely should not be the way it is now
That should solve the issue

absolute position with % width, inside a ul li?

I'm building a navigation menu where I use a regular ul#nav.
In my example bellow I'm trying to make the div inside the li#third hang over the bottom of the ul#nav. I know I need to use position: absolute on the div inside li#third but if I do that then it just takes up the 100% of the width assigned to it.
I tried changing the position: absolute; width: 40%; on the div but then the last li slides under it.
How can I keep the width the same as the li#third element and still have it flow over it at the bottom?
Updated example: http://jsfiddle.net/VyHJR/24/
HTML :
<ul id="nav">
<li id="first">item</li>
<li id="second">item</li>
<li id="third"><div id="search">search</div></li>
<li id="fourth"><div id="flag"><div id="flag_item">4</div></div></li>
</ul>
CSS :
ul#nav { width: 600px; background-color: #fdd; padding: 0; margin: 30px 0 0 20px; overflow: hidden; }
ul#nav li { float: left; text-align: center; }
ul#nav li a { color: #333333; }
ul#nav li#first { background-color: #dff; width: 20%; padding: 6px 0; }
ul#nav li#second { background-color: #ddf; width: 20%; padding: 6px 0; }
ul#nav li#third { background-color: #dfd; width: 40%; }
ul#nav li#fourth { background-color: #ffd; width: 20%; }
li#third div#search { width: 100%; background-color: #333333; height: 40px; color: #ffffff; }
li#fourth div#flag { width: 100%; height: 20px; background-color: #333333; }
li#fourth div#flag div#flag_item { width: 1px height: 30px; background-color: red; }
See: http://jsfiddle.net/thirtydot/VyHJR/34/
Now I understand what you were trying to do, it makes sense.
I removed overflow: hidden on ul#nav, which I assume was there to contain the floats, and replaced it with display: inline-block. I could also have used clearfix.
I added position: relative; height: 1px; to ul#nav li#third. Some height was required, otherwise the fourth li takes the place of the third. position: relative to contain the absolutely positioned div#search.
I added left: 0 to div#search purely to fix IE7.
li{ overflow: hidden;
position: relative;}