Can we Specify a color with some alpha value as a background ?

Discussion in 'CSS' started by electron, Oct 25, 2007.

  1. #1
    I want to give a background color to a div block.
    The color value is : #ff33cc & alpha=40%;
    Is there any way of doing this ??
    Or
    can i know the hex value of the resultant color ?

    else i will have to upload a img file and set it as background, which i dont wan to do.


    Thanks in Advance.
     
    electron, Oct 25, 2007 IP
  2. unitechy

    unitechy Peon

    Messages:
    350
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    body {
    background: #FF33CC;
    }
     
    unitechy, Oct 25, 2007 IP
  3. electron

    electron Well-Known Member

    Messages:
    249
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    But i want #ff33cc with alpha=40%
     
    electron, Oct 25, 2007 IP
  4. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #4
    
    div
    {
    background:#ff33cc;
    filter:alpha(opacity=40);
    -moz-opacity:.40;
    }
    Code (markup):
    That should work,

    BP
     
    blueparukia, Oct 25, 2007 IP
  5. unitechy

    unitechy Peon

    Messages:
    350
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #5
    body {
    background: #FF33CC;
    filter: alpha(opacity=40);
    }
     
    unitechy, Oct 25, 2007 IP
  6. electron

    electron Well-Known Member

    Messages:
    249
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #6
    Well, i tried that as well

    background:#ff33cc;
    filter:alpha(opacity=40);
    -moz-opacity:.40;

    but the problem with this is that the text that i write & the img that i put in that div section also gets transparent by 40%
    :(

    Can you suggest something else ??
     
    electron, Oct 25, 2007 IP
  7. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #7
    OK, try this:

    In you HTML, use somethng like this:

    
    <div id="transparent">
    Your Code
    <img src="image" class="notransparent" />
    <p class="notransparent">This text isn't transparent</p>
    
    </div>
    HTML:
    Your CSS:
    
    #transparent
    {
    background:#ff33cc;
    filter:alpha(opacity=40);
    -moz-opacity:.40;
    }
    
    .notransparent
    {
    filter:alpha(opacity=100);
    -moz-opacity:.100;
    }
    
    Code (markup):
    That will make anything with
    id="transparent"
    Code (markup):
    show at 40% opacity. And everything with
    class="notransparent"
    Code (markup):
    shows up with no transparency,


    BP
     
    blueparukia, Oct 25, 2007 IP
  8. electron

    electron Well-Known Member

    Messages:
    249
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #8
    Doesn't work, even after adding the notransparent class to the para it still shows it with the alpha value . :(
    Is it working on your system ?
    Never the less, thanks for your time :)
     
    electron, Oct 25, 2007 IP
  9. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #9
    Can I see your source, it would probably only take me a min or 2 to fix it, PPM it to me if you don't want to show it,

    BP
     
    blueparukia, Oct 25, 2007 IP
  10. electron

    electron Well-Known Member

    Messages:
    249
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #10
    Here it is :

    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    	<head>
    		<title>Master</title>
    		<style type="text/css">
    			*{padding:0; margin:0;}
    			body{padding:0; margin:0 auto; background-color : #ff33cc;}
    			.pagecontainer{margin:auto; width:800px; height:800px; background:transparent url(img/background.gif) top left repeat-y;}
    			.logo{float:left; width:270px; height:75px;}	
    			.banner{margin-top:5px; width:530; height:75;}
    			.topline{clear:left; width:800px; height:105px; background:#ff33cc;filter:alpha(opacity=10);-moz-opacity:.10;}
    			.notransparent{filter:alpha(opacity=100);-moz-opacity:.100;}
    			.navi{float:left; margin-top:5px; width:115px; height:800px; background-color:#ffccff;}
    
    		</style>
    	</head>
    
    	<body>
    		
    		<div class="pagecontainer">
    			<div class="logo">
    				<img src="img/logo.gif" />
    			</div>
    			 
    			<div class="banner">
    				<img src="img/banner.jpg"  />
    			</div>
    
    			<div class="topline">
    				<p class="notransparent">pop po po po p op o po po po p op o</p>
    			</div>
    
    			<div class="navi">
    				xa
    			</div>
    		</div>
    	</body>
    </html>
    
    Code (markup):
    Thanks Again :)
     
    electron, Oct 25, 2007 IP
  11. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #11
    I cheated with absolute positioning, but it works:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    	<head>
    		<title>Master</title>
    		<style type="text/css">
    			*{padding:0; margin:0;}
    			body{padding:0; margin:0 auto; background-color : #000;}
    			.pagecontainer{margin:auto; width:800px; height:800px; background:url(img/background.gif) top left repeat-y;}
    			.logo{float:left; width:270px; height:75px;}	
    			.banner{margin-top:5px; width:530; height:75;}
    			.topline{clear:left; width:800px; height:105px; background:#ff33cc;filter:alpha(opacity=40); opacity:.40;-moz-opacity:.40;}
    			.topline p {filter:alpha(opacity=100); opacity:1.0;-moz-opacity:1.0;}
    			.navi{float:left; margin-top:5px; width:115px; height:800px; background-color:#ffccff}
    		</style>
    	</head>
    
    	<body>
    		
    		<div class="pagecontainer">
    			<div class="logo">
    				<img src="img/logo.gif" />
    			</div>
    			 
    			<div class="banner">
    				<img src="img/banner.jpg"  />
    			</div>
    
    			<div class="topline"></div>
    <p style="position:absolute; left: 17px; top: 81px; width: 766px; height: 26px;">pop po po po p op o po po po p op o</p>
    			<div class="navi">
    				xa
    			</div>
    		</div>
    	</body>
    </html>
    HTML:
     
    blueparukia, Oct 25, 2007 IP
    electron likes this.
  12. Arnold9000

    Arnold9000 Peon

    Messages:
    241
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Resultant hex color #FFADEB
     
    Arnold9000, Oct 25, 2007 IP
  13. electron

    electron Well-Known Member

    Messages:
    249
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #13
    @BP(rep added)
    Well, that does not work in Mozilla, but works well in IE. Thanks :)
    @Arnold9000
    Thanks. This will save me a lot of time. :)
    How do we calculate it ?
     
    electron, Oct 25, 2007 IP
  14. KatieK

    KatieK Active Member

    Messages:
    116
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    58
    #14
    Here is an example (with explanation) of opaque text over an alpha background: http://www.mandarindesign.com/troops.html#opacitybackgroundhard

    To calculate the resulting hex color, I would have taken a screen grab, and then used the color picker in PhotoShop. But there are many graphics utilites, even Firefox addons, that would do the job.
     
    KatieK, Oct 25, 2007 IP