Transparent background CSS - html

I have a navigation bar with a semi-transparent background but the navigation links are also semi-transparent. How can I make it so my links do not become transparent? I have attached a copy of my code below (also available on JSFiddle.
<style type="text/css">
body{
margin:0;
padding:0;
}
a{
font-family:sans-serif;
font-size:15px;
}
#nav{
height:30px;
background-color:#dddddd;
filter:alpha(opacity=60);
opacity:0.6;
}
#right{
position:absolute;
top:0;
right:0;
}
.gbt{
display:inline-block;
line-height:26px;
}
.gbtc{
margin:0;
padding:0;
}
.gbts{
padding:6px;
}
</style>
<div id="nav">
<ol class=gbtc>
<li class=gbt><span class=gbts>Link</span></li>
<li class=gbt><span class=gbts>Link</span></li>
<li class=gbt><span class=gbts>Link</span></li>
<li class=gbt><span class=gbts>Link</span></li>
<li class=gbt><span class=gbts>Link</span></li>
</ol>
</div>
Any ideas are much appreciated and I hope you can understand what I'm trying to describe. The code I have provided is easier to see with a background image.
Thanks in advance,
Callum

To set the opacity of the background only, you can set an rgba value for the background colour. This will not affect any child elements.
#nav {
background:rgba(221, 221, 221, 0.6);
}
IE does not support rgba however. For this, you need to use a proprietary filter:
#nav {
background:rgba(221, 221, 221, 0.6);
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#99dddddd,endColorstr=# 99dddddd);
}

I would do it like this: http://jsfiddle.net/5p3vN/
html:
<div id="bg"></div>
<div id="nav">
<!-- the list -->
</div>
css:
#bg{
height:30px;
width: 100%;
background-color:#dddddd;
filter:alpha(opacity=60);
opacity:0.6;
}
#nav{
position: absolute;
top:0;
}

The opacity in CSS is inherited to children. Full Stop. To overcome this create a the transparent background to your navigation seperately and absolutely position your li items over it with a higher z-index. There are other workarounds but they all require some form of js, but to do it with pure css this is what you want.

Related

Create a navigation list that changes its image on hover,but it doesn't work

HTML
<ul id="NavList">
<li id="Home"></li>
<li id="About"></li>
</ul>
CSS:
#Home {
background: url('NavIcons/1.gif');
}
#Home a:hover {
background: url('NavIcons\2.gif');
}
I am creating a navigation list that changes its image on hover, but it doesnt work.
If you want to show the background change of #Home or #About when hovering only on a then you can use the following:
HTML
<ul id="NavList">
<li id="Home">1<div></div></li>
<li id="About">2<div></div></li>
</ul>
CSS
#Home,#About {
position:relative;
width:70px;
height:50px;
}
#Home div, #About div{
position:absolute;
background: url('http://i.stack.imgur.com/2JzQz.jpg');
background-position:-20px 0px;
top:0px;
width:100%;
height:100%;
}
#Home a,#About a{
position:absolute;
top:20px;
left:20px;
z-index:100;
}
#Home a:hover+div , #About a:hover+div{
background: url('http://i.stack.imgur.com/7rx8G.jpg');
background-position:-20px 0px;
}
Demo
Got this idea from How to style the parent element when hovering a child element? .My CSS is different but using same idea.
a tag will probably not be large enough to show your image. You can try this
#Home {
background: url('NavIcons/1.gif');
}
#Home:hover {
background: url('NavIcons/2.gif');
}
or give width and height to a.
try like this
#Home {
background: url(NavIcons/1.gif) 0 0 no-repeat;
}
#Home:hover {
background: url(NavIcons/2.gif) 0 0 no-repeat;
}
JsFiddle demo : But this for changing color on hover
Please check for image URL if not coming properly
I think you might want to try styling the A rather then the LI since it's just a placeholder as list item for the actual link.
#Home a {
background: url('NavIcons/1.gif');
}
#Home a:hover {
background: url('NavIcons/2.gif');
}

styling of links applies to images?

i'm having this really frustrating problem where a thin silver of the color that i'm applying as the a:hover,a:active is appearing outside of where it should. i have an image in absolute positioning right above the menu that is exhibiting this....i could just move the image up one but i want to solve it the correct way....here is my css
.logo
{
width:200px;
height:108px;
position:absolute;
left:5px;
top:10px;
}
#menu
{
position:relative;
top:110px;
padding-top:0px;
clear:both;
}
ul
{
list-style-type:none;
overflow:hidden;
padding:0px;
width:900px;
}
a
{
text-decoration:none;
}
li
{
float:left;
}
a:link,a:visited
{
display:block;
font-weight:bold;
text-align:center;
background-color:#ffffff;
padding:3px;
width:120px;
height:auto;
color:#000000;
float:left;
}
a:hover,a:active
{
background-color:#804000;
color:#ffffff;
}
here is my corresponding html:
Sorry, your browser doesn’t support JavaScript!
U4U Test Page
<div class="header">
<img class="logo" src="linktofilehere" alt="U4U Logo" />
</div>
<div id="menu">
<ul>
<li><a href="/" >Home</a></li>
<li>About Us</li>
<li>Programs</li>
<li>US Movement</li>
<li>Sponsorship</li>
<li>Donate</li>
</ul>
</div>
</body>
</html>
i've searched through the help knowledge and couldn't find anything related really....i'm sure it is something simple....any help would be appreciate, i think it might have to do with positioning or not defining the hover area correctly but i'm not sure....i just started learning html and css last week so please be kind!
You will need to create a new style for the 'a' of your image. If you don't, it will use the standard 'a' stylings of your CSS.
Like this :
a.imglink:hover
{
background:none;
}
I'd add a style to remove the background color from linked images - that way you won't run into issues with transparent PNGs etc:
.imglink:hover {
background-color:transparent;
}
I just specifically targetted links inside the list for the background color on hover..
CSS:
#menu > ul > li > a:hover,a:active
{
background-color:#804000;
color:#ffffff;
}
http://jsfiddle.net/cSSU7/
Did this solve your problem?
/* remove the background */
.imglink:hover { background: none; }
/* if you run into specificity issues, be more selective! :) */
a.imglink:hover { background: none; }
/* or remove the padding from just the first a */
a:first-of-type{ padding: 0; }
/* or remove the background from the first link */
a:first-of-type{ background: none; }
DEMO

CSS Can only style elements with pixels, not percents

i'm having a bit of a brain melting problem. I have a master div thats pretty much the body (don't ask me why, i was getting desperate), and within that div is a head div, and within that div is the navigation bar. It's a clear hierarchy. The problem is, whenever i try to use percents to adjust the height and width of the navigation bar or the head div, nothing happens. Zip, zero, nada. I've tried changing the positions to absolute, relative, even static. I've removed the Master Div, i've reordered the hierarchy, but nothing seems to work. Eventually i got to the point where i figured out that when i used pixels, i got the change wanted. (Obviously had to do a bit of conversion). My first thought was hierarchy, but again, it's clear, with no missing ending tags, no weird parents or children.
HTML
<div id="master_div">
<div id="head_div">
<div id="title_div">
<p id="title">A Challenging Sew</p>
<p id="subtitle">A sewing room, Venti Starbucks and a iPod classic....with a weekly Monday update to keep me on task....lets see what happens....</p>
</div>
<div id="nav_bar">
<ul>
<li><a class="nav_bar_links" href="/home">Home</a></li>
<li><a class="nav_bar_links" href="/about">About</a></li>
<li><a class="nav_bar_links" href="/projects/2013">Projects for 2013/2014</a></li>
<li><a class="nav_bar_links" href="http://www.flickr.com/photos/91959855#N02/collections/72157632507621761/">Completed</a></li>
<li><a class="nav_bar_links" href="/archive">Archives</a></li>
<li><a class="nav_bar_links" href="/subscribe">Subscribe</a></li>
<li><a class="nav_bar_links" id="sign_in" href="#">Sign In</a></li>
</ul>
</div>
</div>
</div>
CSS
body
{
font-family: 'Lato', Helvetica, Arial, sans-serif;
font-size: 15px;
padding:0 !important;
}
#master_div
{
position:relative;
width:100%;
height:100%;
margin:0;
padding:0;
}
/* Navigation Page */
#scary_tree
{
position:absolute;
right:40%;
top:25%;
}
/* Home */
/* TODO: Make Responsive Home Page */
#head_div
{
background-color:whitesmoke;
position:absolute;
height:63px;
width:100%;
margin:0;
padding:0;
}
/* A Challenging Sew + A sewing room, Venti Starbucks and a iPod classic..*/
#title_div
{
background-color:white;
opacity: .7;
position:relative;
height:30px;
width:100%;
top:15px;
border-top: solid 1px #e7e7e7;
border-bottom: solid 1px #e7e7e7;
}
#title
{
position:absolute;
left:3%;
top:-9%;
font-size:100%;
margin:0;
padding:0;
}
#subtitle
{
position:absolute;
left:3%;
top:50%;
padding:0;
margin:0;
font-size:40%;
line-height: 1.2;
}
#nav_bar
{
position:absolute;
top:100%;
height:15%;
width:100%;
background-color:whitesmoke;
border-top: solid 1px #e7e7e7;
border-bottom: solid 1px #e7e7e7;
margin:0;
padding:0;
}
#nav_bar ul {
margin:0;
padding:0;
position:relative;
height:20px;
top:-8px;
}
#nav_bar li {
display:inline;
}
#nav_bar a:link,a:visited {
margin:0;
padding-left:5px;
text-decoration: none;
color: black;
font-size:50%;
}
#nav_bar #sign_in
{
position:absolute;
right:2%;
top:3px;
margin:0;
padding:0;
}
Note: I am using a reset file. However, i still have margin and padding :0 in there because it doesn't really seem to be taking hold.
Feel free to critique me on my coding style, still learning!
You might wan to try
min-height: 100%;
min-width: 100%;
position: absolute;
Found the cause, setting my master div's position to relative was the issue. Have no idea why but hey. It works now. Sort of.

How do I correctly control stacking ordered of my divs using z-index?

I have a drop down menu (#dropDownMenu) which appears when the "#headerNav" of my website is hovered over. It works properly if I position the #dropDownMenu (originally hidden with display:none until link is hovered over) slightly over the #headerNav div.
This stops the slight flickering that is caused if the cursor isn't moved over fast enough to the drop down menu when it appears. By slightly overlapping #dropDownMenu over #headerNav this makes it seem like the #headerNav is still being hovered over when cursor is actually in the #dropDownMenu.
Anyway I now want to hide the overlapping part of #dropDownMenu behind header or #headerContent so everything looks neater and so the drop down menu actually looks like it's appearing beneath the #headerNav.
I've tried different z-index settings and none seem to work which is quite annoying. When I set the z-index of #headerNav:hover #dropDownMenu to -1 it is hidden behind all content as expected.
If I set z-index of header or #headerContent to a number higher than "#headerNav:hover #dropDownMenu" then hover over #headerNav there is no difference. I can still see #dropDownMenu overlapping.
CSS:
header {
position:fixed;
top:0;
right:0;
left:0;
height: 40px;
z-index:20;
}
#headerContent {
background-color: $main-background-color;
width: $site-width;
margin:0px auto 0px auto;
height:40px;
}
#headerNav {
float:right;
height:37px;
width:auto;
margin-top:1px;
background-color:#464646;
color:#cccccc;
}
#headerNav:hover {
background-color:#626262;
cursor:pointer;
color: white;
}
#headerNav:hover #dropDownMenu {
position:absolute;
background-color:white;
border:1px solid gray;
top:35px;
right:-39px;
height:300px;
width:200px;
font-weight:bold;
color:gray;
display:block !important;
z-index:1;
}
ul li {
float:right;
}
#photoThumbnail img {
height:28px;
width:31px;
padding-top:5px;
padding-right:8px;
-moz-border-radius: 1px 12px 1px 12px;
border-radius: 1px 12px 1px 12px;
}
#currentUser {
position:relative;
padding-top:12px;
padding-left:12px;
padding-right:6px;
}
#siteNavigation {
display:none;
}
HTML
<header>
<div id='headerContent'>
<div id='LogoHolder'>
</div>
<nav id='headerNav'>
<ul>
<li id='photoThumbnail'></li>
<li id='currentUser'>
<ul id='dropDownMenu'>
<li>link1</li>
<li>link2</li>
<li>link3</li>
<li>link4</li>
<li>link5</li>
<li>link6</li>
</ul>
</li>
</ul>
</nav>
</div>
</header>
Examples and corrections will be greatly appreciated.
Kind regards
If your z-index setting is being ignored you might need to add position property, set it to relative or whatever it needs to be. I'm pretty sure z-index is ignored if position property is not set.
I think you'll find that you are trying to hack your way around a fundamental markup issue. THe usual way to do ul based drop downs is this
<ul id='headerNav'>
<li>Menu Title
<ul class='dropDownMenu>
<li>link1</li>
<li>link2</li>
</ul>
</li>
</ul>
This way you set the hover action on #headerNav li:hover and your drop down is a child of your hover element and the menu will stay open (and not flicker) when you move your mouse over the .dropDownMenu as it is also being hovered. You're close.. you just need to wrap your html a bit better and adjust your css to hover on the li and show and hide the "li ul.dropDownMenu"
This should get rid of the need for your overlap - and fix your problem.

help on css positioning problem. my toolbar can't sit on div below it

i have made a toolbar using links placed inside listitems but the problem is that i cant get my toolbar to sit on a "div" placed below it. This is what i want to see.
but this is what am getting in firefoxNotice the space between my 'toolbar' and the div below it. Questionswhy is the code displaying properly in jsfiddle but displaying badly if i run it directly in fierfox?How can i solve the problem?
ps:
here is the html
<html><head>
<link rel='stylesheet' type='text/css' href='style.css'>
</head><body>
<div id='headercontainer'>
<h2>welcome to research club</h2>
<ul class='mainNavigation'>
<li><a class='currentPage' href='#'>Home</a></li>
<li><a href='#'>Meetups</a></li>
<li><a href='#'>Feedback</a></li>
<li><a href='#'>About</a></li>
</ul>
</div>
<div id='page'>
<p> this is a simple paragraph inside the page that is full of meaningless words but tries to populate a page . mama miya tolina galya mamba eno.</p>
</div><!--#page-->
</html>
Here is the css
div#headercontainer
{
position:relative;
}
div#page
{
margin:0px 50px 0px 50px;
padding:0 450px 0 30px;
position:relative;
background:#181C21;
clear:right;
color:white;
}
ul.mainNavigation
{
list-style:none;
margin:0px 50px 0px 0px;
position:absolute;
bottom:0; right:0;
padding:0;
}
ul.mainNavigation li
{
background:#192839;
color:white;
float:left;
height:1.6em;
padding:5px;
}
ul.mainNavigation li a
{
color:#bbbbbb;
display:block;
text-decoration:none;
height:1.6em;
font-size:0.9em;
}
ul.mainNavigation li a:hover
{
border-bottom:2px solid #0F67ff;
color:white;
}
ul.mainNavigation li a.currentPage
{
border-bottom:2px solid #176092;
}
I'm guessing that you haven't added a general selector to put all margins and paddings to 0, in this case you would need to add:
div#headercontainer {
position:relative;
padding:0px;
margin:0px;
}
or
*{
padding:0px;
margin:0px;
border:0px;
}
All browsers have some basic setups for non defined elements meaning I can set the I want all texts to be white instead of black and if you haven't set the color all the texts will be written in white.
Hoping this will help…
Use float and clear instead of position absolute.
Like this:
div#headercontainer{
float:left;
position:relative;
}
h2{
float:left;
}
ul.mainNavigation{
float:right;
}
#page{
clear:both;
float:left;
}
Hope this help... (This is my first answer on this website :S)