CSS - Tooltips Using Css Using <span>
I am trying to make tooltips, using PHP code inside <span>.
Is there possibility to control the position in <style>, to avoid possibility for the box (tooltip), not to be completely visible, I mean, when the word that has to be described is at the right bottom of the window, box will change it's position and will be placed at the upper and left position. The box would have to be placed at the position it can have to be readable. Similar TutorialsHi folks I am using the excellent Adx CSS drop-down menu, which is great. One thing I'd like to add to it though, is mouseover tooltips giving more info on each link, using the span method suggested by Meyerweb and others: div#menu a:hover span { etc.... This works beautifully in FF and IE5. But IE6, bless its heart, will not display any span words in a submenu: http://ied.gospelcom.net/adxmenu.html If I substitute li:hover span in the code, then it does display every set of span words in the whole submenu. I've tried various tricks, including stuff in the IE only extra style sheet that AdX uses, but with no success. Any ideas of stuff to try? Many thanks Tony Hi I'm struggeling with the following: I have some span elements inside a td. If I apply padding to a span then the padding is flowing outside the td (above and below the borders of the td). Why does that happen and is there a way to make the td to autogrow to fit all the span's inside? Se example code below Code: <table border="0" cellpadding="0" cellspacing="0" align="center" style="width:300px; margin-top:50px;"> <tr> <td style="background-color:gray; text-align:center; border:1px solid black;"> <span style="margin-right:20px;">First</span> <span style="margin-right:20px;">1</span> <span style="margin-right:20px;">2</span> <span style="margin-right:20px; background-color:orange; padding:10px;">3</span> <span style="margin-right:20px;">4</span> <span style="margin-right:20px;">5</span> <span style="">Last</span> </td> </tr> </table> ******* UPDATE ******* I found this link today: http://css-discuss.incutio.com/?page=FormattingContexts which says (among other things): ************************* Only one thing impacts the vertical space between inline elements: the line height. Normally, the line height is based upon the line height for the text in that line, or the height/padding/border/margin of any replaced items. The element on a line with the largest line height or replaced height is the one to define the vertical space that line takes up. Height, padding, border or margins on text do not impact the line height or the container height. Instead, borders, padding and margins overlap from line to line. If you want to give an inline text element some padding and border, make sure you give it some extra line height, too, or else it will overlap with whatever else is above or below it. ************************* So does that rule mean that I have no way to make my TD autogrow in relation to the padding applied to the SPAN in the example above? Is there any working workarounds for this...? I have successfully implemented css tooltips on my links page to provide a short description of the site on hover... I had to apply a positive z-index change on the anchor tag when hovered in order for the span to cover the following links... but this "fix" doesn't work for IE7... any ideas? [edit]I also had to add text-decoration:none to hide the underline from IE7[/edit] Links Page The relative css css Code: Original - css Code a.spantip { position:relative; z-index:50; } a.spantip:hover { font-size:1em; z-index:55; } a.spantip span { display:none; text-decoration:none; } a.spantip:hover span { position:absolute; top:5px; left:30px; width:250px; display:block; color:#666666; font-weight:normal; background:#ffcc66; border:1px solid #ff6600; } a.spantip { Hello, I have [almost] successfully added CSS tooltips to a conference agenda and have an issue where links are "bleeding" through the tooltips. I think it has something to do with the way the links and tooltips are positioned. For example, I have a table cell with 2 links in it like this: <p><a link>Link1<span>Tooltip1</span></a></p> <p><a link>Link2</a><span>Tooltip2</span></p> The spans are hidden until hovered over, using a display:none to display:block switch. The links are positioned relative and the blocks are positioned absolute. The behavior I'm seeing is that Link2 will "bleed" through the tooltip block, obscuring the text in the block. I've tried a couple of other positioning strategies and using z-index with no improvement. Can someone have a look and see if you can help? Visit http://www.tipsweb.com/about/events/conference2007/agenda_new.asp And mouse over the Brazos 2 session links from 1:00 pm - 2:30 pm on Tuesday April 17th. Thanks! Chris Okay, so I needed tooltips on my site and made some. Then realised they didn't work on IE and implemented the csshover3.htc but for some reason it still doesn't work. Actually, it doesn't work on any IE I have around here, while it SHOULD work on IE7 and IE8 right? Well it just displays the "trigger" text and the tooltip text in plain text without any of the hover css code displayed below, other css code (like "body") is applied. I'm not that great with css so that could cause the problem. I did add the MIME-type text/x-component .htc If anyone could help me out here, I would really appreciate it Thanks! This is a cut from my css file (general.php): (zz is a tag I made to spawn the tooltips, could that be the problem?) Code: body { color: white; font-family: "Verdana"; font-size:12px; behavior:url("csshover3.htc"); } zz span{display: none;} zz:hover{ font-weight:bold; position: relative; } zz:hover span.tooltip{ position: absolute; font-weight:normal; padding: 5px; color: white; display: block; background: #111111; border: 1px solid orange; top: 20px; left: 20px; } This is my csshover3.htc file Code: <public:attach event="ondocumentready" onevent="CSSHover()" /> <script> // <![CDATA[ /** * Whatever:hover - V3.00.081222 * ------------------------------------------------------------ * Author - Peter Nederlof, http://www.xs4all.nl/~peterned * License - http://creativecommons.org/licenses/LGPL/2.1 * * Whatever:hover is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * Whatever:hover is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * howto: body { behavior:url("csshover3.htc"); } * ------------------------------------------------------------ */ window.CSSHover = (function(){ // regular expressions, used and explained later on. var REG_INTERACTIVE = /(^|\s)((([^a]([^ ]+)?)|(a([^#.][^ ]+)+)):(hover|active|focus))/i, REG_AFFECTED = /(.*?)\:(hover|active|focus)/i, REG_PSEUDO = /[^:]+:([a-z-]+).*/i, REG_SELECT = /(\.([a-z0-9_-]+):[a-z]+)|(:[a-z]+)/gi, REG_CLASS = /\.([a-z0-9_-]*on(hover|active|focus))/i, REG_MSIE = /msie (5|6|7)/i, REG_COMPAT = /backcompat/i; // css prefix, a leading dash would be nice (spec), but IE6 doesn't like that. var CSSHOVER_PREFIX = 'csh-'; /** * Local CSSHover object * -------------------------- */ var CSSHover = { // array of CSSHoverElements, used to unload created events elements: [], // buffer used for checking on duplicate expressions callbacks: {}, // init, called once ondomcontentready via the exposed window.CSSHover function init:function() { // don't run in IE8 standards; expressions don't work in standards mode anyway, // and the stuff we're trying to fix should already work properly if(!REG_MSIE.test(navigator.userAgent) && !REG_COMPAT.test(window.document.compatMode)) return; // start parsing the existing stylesheets var sheets = window.document.styleSheets, l = sheets.length; for(var i=0; i<l; i++) { this.parseStylesheet(sheets[i]); } }, // called from init, parses individual stylesheets parseStylesheet:function(sheet) { // check sheet imports and parse those recursively if(sheet.imports) { try { var imports = sheet.imports, l = imports.length; for(var i=0; i<l; i++) { this.parseStylesheet(sheet.imports[i]); } } catch(securityException){ // trycatch for various possible errors, // todo; might need to be placed inside the for loop, since an error // on an import stops following imports from being processed. } } // interate the sheet's rules and send them to the parser try { var rules = sheet.rules, l = rules.length; for(var j=0; j<l; j++) { this.parseCSSRule(rules[j], sheet); } } catch(securityException){ // trycatch for various errors, most likely accessing the sheet's rules, // don't see how individual rules would throw errors, but you never know. } }, // magic starts here ... parseCSSRule:function(rule, sheet) { // The sheet is used to insert new rules into, this must be the same sheet the rule // came from, to ensure that relative paths keep pointing to the right location. // only parse a rule if it contains an interactive pseudo. var select = rule.selectorText; if(REG_INTERACTIVE.test(select)) { var style = rule.style.cssText, // affected elements are found by truncating the selector after the interactive pseudo, // eg: "div li:hover" >> "div li" affected = REG_AFFECTED.exec(select)[1], // that pseudo is needed for a classname, and defines the type of interaction (focus, hover, active) // eg: "li:hover" >> "onhover" pseudo = select.replace(REG_PSEUDO, 'on$1'), // the new selector is going to use that classname in a new css rule, // since IE6 doesn't support multiple classnames, this is merged into one classname // eg: "li:hover" >> "li.onhover", "li.folder:hover" >> "li.folderonhover" newSelect = select.replace(REG_SELECT, '.$2' + pseudo), // the classname is needed for the events that are going to be set on affected nodes // eg: "li.folder:hover" >> "folderonhover" className = REG_CLASS.exec(newSelect)[1]; // no need to set the same callback more than once when the same selector uses the same classname var hash = affected + className; if(!this.callbacks[hash]) { // affected elements are given an expression under a fake css property, the classname is used // because a unique name (eg "behavior:") would be overruled (in IE6, not 7) by a following rule // selecting the same element. The expression does a callback to CSSHover.patch, rerouted via the // exposed window.CSSHover function. // because the expression is added to the stylesheet, and styles are always applied to html that is // dynamically added to the dom, the expression will also trigger for those new elements (provided // they are selected by the affected selector). sheet.addRule(affected, CSSHOVER_PREFIX + className + ':expression(CSSHover(this, "'+pseudo+'", "'+className+'"))'); // hash it, so an identical selector/class combo does not duplicate the expression this.callbacks[hash] = true; } // duplicate expressions need not be set, but the style could differ sheet.addRule(newSelect, style); } }, // called via the expression, patches individual nodes patch:function(node, type, className) { // the patch's type is returned to the expression. That way the expression property // can be found and removed, to stop it from calling patch over and over. // The if will fail the first time, since the expression has not yet received a value. var property = CSSHOVER_PREFIX + className; if(node.style[property]) { node.style[property] = null; } // just to make sure, also keep track of patched classnames locally on the node if(!node.csshover) node.csshover = []; // and check for it to prevent duplicate events with the same classname from being set if(!node.csshover[className]) { node.csshover[className] = true; // create an instance for the given type and class var element = new CSSHoverElement(node, type, className); // and store that instance for unloading later on this.elements.push(element); } // returns a dummy value to the expression return type; }, // unload stuff onbeforeunload unload:function() { try { // remove events var l = this.elements.length; for(var i=0; i<l; i++) { this.elements[i].unload(); } // and set properties to null this.elements = []; this.callbacks = {}; } catch (e) { } } }; // add the unload to the onbeforeunload event window.attachEvent('onbeforeunload', function(){ CSSHover.unload(); }); /** * CSSHoverElement * -------------------------- */ // the event types associated with the interactive pseudos var CSSEvents = { onhover: { activator: 'onmouseenter', deactivator: 'onmouseleave' }, onactive: { activator: 'onmousedown', deactivator: 'onmouseup' }, onfocus: { activator: 'onfocus', deactivator: 'onblur' } }; // CSSHoverElement constructor, called via CSSHover.patch function CSSHoverElement(node, type, className) { // the CSSHoverElement patches individual nodes by manually applying the events that should // have fired by the css pseudoclasses, eg mouseenter and mouseleave for :hover. this.node = node; this.type = type; var replacer = new RegExp('(^|\\s)'+className+'(\\s|$)', 'g'); // store event handlers for removal onunload this.activator = function(){ node.className += ' ' + className; }; this.deactivator = function(){ node.className = node.className.replace(replacer, ' '); }; // add the events node.attachEvent(CSSEvents[type].activator, this.activator); node.attachEvent(CSSEvents[type].deactivator, this.deactivator); } CSSHoverElement.prototype = { // onbeforeunload, called via CSSHover.unload unload:function() { // remove events this.node.detachEvent(CSSEvents[this.type].activator, this.activator); this.node.detachEvent(CSSEvents[this.type].deactivator, this.deactivator); // and set properties to null this.activator = null; this.deactivator = null; this.node = null; this.type = null; } }; /** * Public hook * -------------------------- */ return function(node, type, className) { if(node) { // called via the css expression; patches individual nodes return CSSHover.patch(node, type, className); } else { // called ondomcontentready via the public:attach node CSSHover.init(); } }; })(); // ]]> </script> Hi. See code below. Why does the outer SPAN in TABLE not grow with the image height. If the text is longer so it is forced below image then it looks as it should. Please also read some comments in the code. Code: <html><body><center><br><br> Why does image not force the outermost span to be at least as high as image?<br> If the text are long enough and gets below the bottom border of image it look good though.<br><br> NOTE: I need to put Image and text either within separate span or in same span as the examples below.<br> In my real application I'm using an <a href=" ...> around the outer span in examples below.<br> <br><br> <table border=1 cellpadding=0 cellspacing=0 width=200px><tr><td> <span style="display:block; background-color:#ffa827; padding-top:10px; padding-left:10px; padding-right:10px;"> <span style="display:block; float:left"> <img src="landscape.jpg" height="40px" width="40px" alt="" border="0"> </span> <span style="display: block; color: white;"> Text here. </span> </span> </td></tr></table> <br><br> <table border=1 cellpadding=0 cellspacing=0 width=200px><tr><td> <span style="display:block; background-color:#ffa827; padding-top:10px; padding-left:10px; padding-right:10px; color: white;"> <img src="landscape.jpg" height="40px" width="40px" alt="" border="0" style="float:left"> Text here. </span> </td></tr></table> </center></body></html> hi, i have a chunk of dynamic text coming in. it can have html links in it. so something like: 'blah blah blah <a href="site">link text</a> blah blah' im trying to stylize the dynamic text with CSS. i can get the font size and everything to work but i can't get the link text to behave like i want it to. here's what i have: PHP Code: //the css class .articleDesc { font-family: verdana, arial, geneva, sans serif; font-size: 12px; font-weight: none; text-decoration: none; color: #000000; } //trying to make all links red, doesn't work a.articleDesc { color: #FF0000; } //php print '<span class="articleDesc">' . $dynText . '</span>'; the links just come out default, ie. blue and purple... anyone know what's wrong here? Hi, I am currently trying to produce a website using CSS style sheets. I have used 'span' to position and align blocks of text on the page. All looks well, but when I try and validate the page I get an error message that says the <p> and <ol> tags cannot be used within <span> tags. Can anyone suggest anyway round this? Many thanks x Hi, Code: <tr><td colspan="2" height="5"></td></tr> <tr><td width="30%" align="right">City</td><td>This is supposed to be some content</td></tr> How do I imitate structure of the table above. In the example below the text between <span> if too long ends up on new line below <label> How do I make sure that it stay on right side? Code: <div><label>City</label><span>This is supposed to be some content when too long appears below span not below label</span></div> Thank you. I'm a novice with CSS and HTML so the following may seem elementary to most of you. I'm a retail vitamin store owner with a website, (URL address blocked: See forum rules) . We do very well with our store front and are getting better and better with our online discount vitamin store. Our web master has programmed our site so we can easily insert new products. This is done in the <body>. Recently I've wanted to add some spice with color and formatting . At first I was doing this with something like <FONT FACE="Verdana, Helvetica, Arial" size="4" color="006600">. But now as I get into CSS and double checking all code with W3.org, it doesn't like this approach. Now I'm trying <span id="enzymatic" class="prod_description"> in the <body> with span#enzymatic p { color: green; } span#enzymatic h4{ color: blue; } etc. in a CSS definition file. It all works well, but W3.org still doesn't like where I've inserted the code. If you go to our page: (URL address blocked: See forum rules)=country-life-seniority-multivitamin You will get among other "errors" the following message: <h4>Seniority ™ Multi-Vitamin Capsules </h4> The mentioned element is not allowed to appear in the context in which you've placed it; the other mentioned elements are the only ones that are both allowed there and can contain the element mentioned. This might mean that you need a containing element, or possibly that you've forgotten to close a previous element. One possible cause for this message is that you have attempted to put a block-level element (such as "<p>" or "<table>") inside an inline element (such as "<a>", "<span>", or "<font>"). Any hints as to what basic rules I'm breaking? Be kind. Many thanks, healthyphil Hello, Well this is a very simple question ... how can Iset the width of a span from CSS? Basically I tried setting the span with from CSS however the span size remained wrapped to the text inside rather then taking the width I desire. I check some interent forums, and found out that if I set the float:left the width is taken, but my span is no longer is place! is there a way to set the span width without having to set thr float:left option? thanks and regards, Sim085 I'm wondering is is it possible to have a <div> tag where a left <span> can stick to the left and a right <span> to stick to the right. What I'm looking for is .... ============================================ =[blah blah] (lot of spaces here) [blah blah]= ============================================ Code: div.divTop { margin: 0px; padding: 8px 0px; width: 600px; color: #000000; font-weight: normal; font-family: verdana; font-size: 10pt; font-style: normal; text-indent: 20px; } span.spanTitle1 { font-size: 16pt; } span.spanTitle2 { font-size: 10pt; } [code] [code] <div class="divTop"> <span class="spanTitle1">blah blah1</span> <span class="spanTitle2">blah blah2<img src="....."></span> </div> Edit: Can't make the ASCII text work here..... I am creating a page where I will list OS names, and when I mouse over the name I would like to display the versions in the database for the corresponding name. The problem I am having is that I'm trying to use span to display the versions but I keep getting a document.all.menu1.style is null or not an object. Here is my code. I don't seewhere it's not working since I got this code from a tutorial and the tutorial code works just fine. <STYLE TYPE="text/css"> #menu1 { display : none } A:link {color:black; text-decoration:none} A:hover {color:blue; text-decoration:underline} </STYLE> <td bgcolor="#DCEBEB"> <SPAN onMouseOver="document.all.menu1.style.display = 'block'" onMouseOut="document.all.menu1.style.display = 'block'"> <img src="../../images/plus.gif">AIX<br> </SPAN> <SPAN ID="menu1" onClick="document.all.menu1.style.display = 'none'"> <img src="../../images/minus.gif"><a href="http://www.test.com">Testing 1</a><br> <img src="../../images/minus.gif"><a href="http://www.yahoo.com">Testing 2</a><br> <img src="../../images/minus.gif"><a href="http://www.cnn.com">Testing 3</a> </SPAN></td> Hi everyone. I would like to change the first letter of an h2 tag thats NOT in a span in the following chunk of code Code: <h2> <span class="subtleHeader">Saskatoon, Regina and Edmonton's</span><br> WEB DESIGN EXPERTS </h2> So in this example I want to change the W. yes I can change the dom, but I'm very very lazy and have this DOM structure in many places and was wondering if there was a css way to do it. Thanks Why is this? Code: <div style='margin:0 0px 5px 3px;text-align:center;background-color:#EEEEEE;padding:4px 0;border:2px solid #CCCCCC;'> <span style='color:#888888;font-weight:bold;font-size:10px;'> RECENT BLOGS </span> </div> different than this? Code: <div style='margin:0 0px 5px 3px;text-align:center;background-color:#EEEEEE;padding:4px 0;border:2px solid #CCCCCC;'> <span style='color:#888888;font-weight:bold;font-size:10px;'>RECENT BLOGS</span> </div> Why is IE7 adding its own padding when i don't add a nl between the span and the content within the span? It's the display:block issue that also happens with images. But I just can't understand why IE7 would add spacing there, the 2 above are almost identical. I am having trouble understanding what exactly the CLASS, ID, DIV, and SPAN elements and attributes do. What are there purposes? How do the relate to each other? When should one be used and not another? In laymens terms please. Thanks ok, i know that because span is a inline element width cant be applied to it, and a lot of people suggest DIV my problem is that div wont work, because of its auto-break thing.... it being a block element and all... so, how would i apply a width of something like 100px to the span elements in code like this?... Code: <div class="infocontainer"> <span class="infobox">Publisher: <?php print $publisher; ?></span> <span class="infobox">Developer: <?php print $developer; ?></span> <span class="infobox">System: <?php print $system; ?></span> <span class="infobox">Gen <?php print $genre; ?></span> </div> I am a 3week knewb to css. I was wondering if anyone could explain to me when I would use: div or display:block div or span span or display:inline thank you Hi, there. I've created a simple 2-column list using a <span> to justify items I want in the right column to the right edge of the containing <div>... everything is working fine in Firefox, but have just noticed that Internet Explorer is punching all the spans down one line. I thought spans were purely inline, so this is a little confusing! Here's the CSS I'm using: Code: #300px-LIST { width:300px; margin:0px auto; text-align:left; padding:0; } .right { float: right; } ...and the HTML: Code: <div id="300px-LIST"> LINE 1 LEFT<span class="right">LINE 1 RIGHT</span><br /> LINE 2 LEFT<span class="right">LINE 2 RIGHT</span><br /> LINE 3 LEFT<span class="right">LINE 3 RIGHT</span><br /> </div> Any pointers gratefully received! |