{"id":3072,"date":"2017-07-26T10:07:44","date_gmt":"2017-07-26T15:07:44","guid":{"rendered":"http:\/\/cssnewbie.com\/?p=2367"},"modified":"2017-07-26T10:07:44","modified_gmt":"2017-07-26T15:07:44","slug":"css-tool-tips-support-website-visitors","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/css-tool-tips-support-website-visitors\/","title":{"rendered":"CSS Tool tips (Infotips) to Support Your Website Visitors"},"content":{"rendered":"<p>Tool tips are messages that appear when you hover your cursor over a word, hyperlink, image, icon, or any other element in a graphical user interface (GUI) or website.<\/p>\n<p>Also called an \u201cinfotip\u201d and sometimes written as \u201ctooltip\u201d, these useful messages appear in a hover box, usually to describe the feature your mouse is hovering over before you click it. Normally, these tool tips only appear on computers using a mouse, as mobile devices mostly do not have a cursor in their GUI.<\/p>\n<p>Here is an example of what a tool tip looks like:<\/p>\n<p style=\"text-align: left;\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2369\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2017\/07\/HTML_tooltip.png\" alt=\"HTML_tooltip\" width=\"564\" height=\"82\" \/><br \/>\n(Image by <a title=\"User:Nikola Smolenski\" href=\"https:\/\/commons.wikimedia.org\/w\/index.php?curid=2043284\">Nikola Smolenski<\/a>)<\/p>\n<p>Traditionally, you can use simple HTML to create these tool tips, as in the example above. However, CSS tool tips will elevate the amount of support that you can provide your visitors.<\/p>\n<p>With basic HTML, the tool tips appear automatically with no animations and no positioning. Using CSS, you have control over what they look like, where they\u2019re positioned, and even whether they will have an arrow pointing to the element or not. In the example below, we have programmed the tool tip to appear below the sample text, with a black background, and an arrow pointing up.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2372\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2017\/07\/hover-example.jpg\" alt=\"hover-example\" width=\"209\" height=\"115\" \/><\/p>\n<h2>Basic Tool Tip<\/h2>\n<p>As with most CSS tricks, you will need to define things in both the style sheet (external or within the web page) as well as within the body of the web page.<\/p>\n<p>Here is a sample piece of code for a basic tool tip:<\/p>\n<pre>&lt;style&gt;\n\n\/* Tooltip container *\/\n\n.tooltip {\n\nposition: relative;\n\ndisplay: inline-block;\n\nborder-bottom: 1px dotted black; \/* If you want dots under the hoverable text *\/\n\n}\n\n\/* Tooltip text *\/\n\n.tooltip .tooltiptext {\n\nvisibility: hidden;\n\nwidth: 120px;\n\nbackground-color: black;\n\ncolor: #fff;\n\ntext-align: center;\n\npadding: 5px 0;\n\nborder-radius: 6px;\n\n\/* Position the tooltip text - see examples below! *\/\n\nposition: absolute;\n\nz-index: 1;\n\n}\n\n\/* Show the tooltip text when you mouse over the tooltip container *\/\n\n.tooltip:hover .tooltiptext {\n\nvisibility: visible;\n\n}\n\n&lt;\/style&gt;\n\n&lt;div class=\"tooltip\"&gt;Hover over me\n\n&lt;span class=\"tooltiptext\"&gt;Tooltip text&lt;\/span&gt;\n\n&lt;\/div&gt;<\/pre>\n<p>In the above example, there are two parts at play \u2013 the <strong>HTML<\/strong> part and the <strong>CSS<\/strong> part.<\/p>\n<p>For the HTML portion, you need to create a container element such as <strong>&lt;div&gt;<\/strong> and then add a class to it, in this case we used \u201c<strong>tooltip<\/strong>\u201d.<\/p>\n<p>Separately, the tool tip in itself is within an inline element (<strong>&lt;span&gt; <\/strong>in this example, with class \u201c<strong>tooltiptext<\/strong>\u201d).<\/p>\n<p>For the CSS portion, the classes you have specified in HTML are defined here. In this example, the <strong>tooltip<\/strong> class uses <strong>position:relative <\/strong>(which you can change to <strong>position:absolute<\/strong> to define where the tool tip would appear).<\/p>\n<p>We have also used the CSS3 <strong>border-radius<\/strong> property to <a href=\"http:\/\/cssnewbie.com\/cross-browser-rounded-buttons\/\">make the corners rounded<\/a>, creating a nice smooth border.<\/p>\n<p>Lastly, the <strong>:hover <\/strong>selector tells the web page to show the tool tip when your mouse hovers over the <strong>&lt;div class=&#8221;tooltip&#8221;&gt;<\/strong>.<\/p>\n<h2>Positioning the Tool Tips<\/h2>\n<p>It\u2019s easy to move the tool tip\u2019s position using CSS, to the left or right, or to <a href=\"http:\/\/cssreset.com\/how-to-use-csss-top-and-bottom-properties\/\">the top and bottom<\/a>. All you need to do is define them like in the example codes below:<\/p>\n<h3>Positioned Right<\/h3>\n<pre>.tooltip .tooltiptext {\n\ntop: -5px;\n\nleft: 105%;\n\n}<\/pre>\n<h3>Positioned Left<\/h3>\n<pre>.tooltip .tooltiptext {\n\ntop: -5px;\n\nright: 105%;\n\n}<\/pre>\n<h3>Positioned at the Top<\/h3>\n<p>Use <strong>margin-left<\/strong> by defining half of the tool tip\u2019s width to center the tool tip. In this example, half of 120px is 60, so <strong>margin-left<\/strong> is <strong>-60px<\/strong>.<\/p>\n<pre>.tooltip .tooltiptext {\n\nwidth: 120px;\n\nbottom: 100%;\n\nleft: 50%;\n\nmargin-left: -60px;\n\n}<\/pre>\n<h3>Positioned at the Bottom<\/h3>\n<p>You can center the tool tip in the same manner as positioning tool tips at the top.<\/p>\n<pre>.tooltip .tooltiptext {\n\nwidth: 120px;\n\ntop: 100%;\n\nleft: 50%;\n\nmargin-left: -60px;\n\n}<\/pre>\n<p>There are many other cool things you can incorporate into a tool tip, all of which draw more attention and improve user experience in a way that basic HTML can&#8217;t. Once you learn other elements like borders and <a href=\"http:\/\/cssnewbie.com\/15-new-awesome-creative-css-animations\/\">animation<\/a> (using transition and opacity), you&#8217;ll be able to make your tool tips even more attractive. So have fun with it and keep learning!<\/p>\n<div class=\"wp-socializer wpsr-share-icons \" data-lg-action=\"show\" data-sm-action=\"show\" data-sm-width=\"768\" ><h3>Share and Enjoy !<\/h3><div class=\"wpsr-si-inner\"><div class=\"wpsr-counter wpsrc-sz-32px\" style=\"color:#000\"><span class=\"scount\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook,twitter,linkedin,pinterest,print,pdf\">0<\/span><\/span><small class=\"stext\">Shares<\/small><\/div><div class=\"socializer sr-popup sr-32px sr-circle sr-opacity sr-pad sr-count-1 sr-count-1\"><span class=\"sr-facebook\"><a rel=\"nofollow\" href=\"https:\/\/www.facebook.com\/share.php?u=\" target=\"_blank\"  title=\"Share this on Facebook\"  style=\"color: #ffffff\" ><i class=\"fab fa-facebook-f\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-twitter\"><a rel=\"nofollow\" href=\"https:\/\/twitter.com\/intent\/tweet?text=%20-%20%20\" target=\"_blank\"  title=\"Tweet this !\"  style=\"color: #ffffff\" ><i class=\"fab fa-twitter\"><\/i><\/a><\/span>\n<span class=\"sr-linkedin\"><a rel=\"nofollow\" href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=\" target=\"_blank\"  title=\"Add this to LinkedIn\"  style=\"color: #ffffff\" ><i class=\"fab fa-linkedin-in\"><\/i><\/a><\/span>\n<span class=\"sr-pinterest\"><a rel=\"nofollow\" href=\"https:\/\/www.pinterest.com\/pin\/create\/button\/?url=&amp;media=&amp;description=\" target=\"_blank\"  title=\"Submit this to Pinterest\"  style=\"color: #ffffff\" data-pin-custom=\"true\"><i class=\"fab fa-pinterest\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"pinterest\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-print\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Print this article \"  style=\"color: #ffffff\" ><i class=\"fa fa-print\"><\/i><\/a><\/span>\n<span class=\"sr-pdf\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Convert to PDF\"  style=\"color: #ffffff\" ><i class=\"fa fa-file-pdf\"><\/i><\/a><\/span><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Tool tips are messages that appear when you hover your cursor over a word, hyperlink, image, icon, or any other element in a graphical user interface (GUI) or website.<\/p>\n<p>Also called an \u201cinfotip\u201d and sometimes written as \u201ctooltip\u201d, these useful messages [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/css-tool-tips-support-website-visitors\/\" title=\"Click to read 'CSS Tool tips (Infotips) to Support Your Website Visitors'\">Read Article<\/a><\/p>\n","protected":false},"author":18,"featured_media":2923,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[172,192,195],"tags":[277,280,286,287,324,370,371,376],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/3072"}],"collection":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/comments?post=3072"}],"version-history":[{"count":0,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/3072\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media\/2923"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=3072"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=3072"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=3072"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}