{"id":3266,"date":"2022-04-02T09:00:00","date_gmt":"2022-04-02T09:00:00","guid":{"rendered":"https:\/\/cssdeck.com\/blog\/?p=3266"},"modified":"2022-04-02T06:48:36","modified_gmt":"2022-04-02T06:48:36","slug":"what-are-css-image-rulers","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/what-are-css-image-rulers\/","title":{"rendered":"What are CSS Image Rulers to Follow"},"content":{"rendered":"\n<p>Create a ruler cell div, add background pictures for markers (linear-gradient is OK), and specify a percent location for each marker. This can only be done once in your CSS, and if you utilize the same picture, there will be just one request for that file; moreover, if you use linear-gradient, there will be no extra requests at all. Because you select a % location, you may stretch the ruler as much as you like and it will still look great.<\/p>\n\n\n\n<p>In some instances (for example, on a mobile device screen or while stretching your ruler to magnify), you may wish to produce extra markings between the ruler points dynamically. Simply use javascript to add a new class to your ruler cells, such as.big, and define a distinct set of mark backgrounds for that class. They will make a smooth transition.<\/p>\n\n\n\n<p>Also, since we employ non-pseudo components &#8211; actual divs, real backgrounds, &#8211; this modular approach to ruler enables you dynamically adjust it with javascript.<\/p>\n\n\n\n<p><strong>See Also: <a href=\"https:\/\/cssdeck.com\/blog\/how-to-center-an-image-in-css\/\">How To Center An Image In CSS<\/a><\/strong><\/p>\n\n\n\n<p>Here is the code:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/Y5A4QVfvTEnZS3_zewkPeePNxuVJp-xG55HJK8G7hXeeosaon8PKmVB_tH3A3MaDdLk7gLOp-AjqsTPzSmWVqqsTXhg72YGdhfMu-3Mjdy2KZmeWGkK9lqCRwdHKKsrfVI5PXUpy\" alt=\"\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/fewHjvlqaObgkR1C8_zOZjdmgWYUT5HdEJF9NG1UZ3BCngcQlPA8puQdPYIEIScn8NDPODFz4YtCUOd0y8OfCFd2eAlZptMEDW6JyZPUxYjZp4_Ik1twytkyjqaMOcWaSOdfOxNP\" alt=\"\" \/><\/figure><\/div>\n\n\n\n<p>Notes:<\/p>\n\n\n\n<ul><li>It&#8217;s a partial one, without adding numbers, just the scale markers. You can scroll down for learning to add numbers further in this article.<\/li><li>Here, we only include 4 marks, but there can be many. Don&#8217;t forget you need 1 mark LESS than there are elements (e.g. 9 marks for 10mm)<\/li><li>It includes a ruler centerline.<\/li><li>NO Javascript and NO HTML elements for markers (useful if you have an endless ruler that is autogenerated when you drag or magnify it)<\/li><\/ul>\n\n\n\n<p><strong>See Also: <a href=\"https:\/\/cssdeck.com\/blog\/how-to-add-a-background-image-in-css\/\">How To Add A Background Image In CSS<\/a><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Create Changeable CSS Ruler with Background-Image<\/h2>\n\n\n\n<p>Let&#8217;s have a look at how we can make a changeable ruler with CSS background-image, a number of variables, and just a healthy amount of JavaScript for a visual editor.<\/p>\n\n\n\n<p>Our ruler will contain two sets of &#8220;ticks&#8221; &#8211; low and tall (the numbers will be determined later):<\/p>\n\n\n\n<p>Both sets of ticks start with the following Custom Properties:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/EsbaR610xgtVZTDCJgzX56iKt-1wfl8ZputtcyR5F04WeIyEwoe_dBXbPrWY2pFLH9OOHkTxgZBQHhLPvV2MLFg_xa-iGeHggWjgpycdspGHhh6145deCY8194DWwmtwiCf1KDn_\" alt=\"\" \/><\/figure><\/div>\n\n\n\n<p>We can generate a dynamic backdrop picture using these properties:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/y-gfJfX7-fsDjrw1iq_AYfBm2qMgyRixxCL3lJQ-BGV8UH7GBzp1Nz0JC1m74UbTHAedRZgYUmxGNi2BT4O_ERxtLfiY4Ke_LkKcLu8R7qEIujHCm6CLdOVSNf31az5-MMR27gQA\" alt=\"\" \/><\/figure><\/div>\n\n\n\n<p>However, without background-repeat and background-size, we don&#8217;t see anything like a ruler!<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/KA0hUms21TIURHT3iVF4BAZmd5CL1cbALoujoxeAJaYZ3MZaiotFPJl8D9JIgygnFKCBtHGIh2lXr_eAByF2LC1R6ScoHlb6OdglpdAQSzVRcRu-rvJMDNIlY6zRP4ftijvvIe0p\" alt=\"\" \/><\/figure><\/div>\n\n\n\n<p>That&#8217;s all there is to it! We only need to add background-attachment: fixed to keep the ruler in place when scrolling!<\/p>\n\n\n\n<p><strong>See Also: <a href=\"https:\/\/cssdeck.com\/blog\/zoom-images-inside-the-container-on-mouse-over-using-css\/\">Zoom images inside the container on mouseover using CSS<\/a><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Adding up the numbers<\/h2>\n\n\n\n<p>Here We&#8217;ll make a list of the numbers:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/LZpDTB7h4c8sQO88cEYY2rKcQkvxRCnZ_j-qGnIJr-UqTfazBNzARR-ddedB5ETYXKp32zOSCMqmQh4nW_Ma2Og5PM8rT9YQ8Y9dx6kogJet6ZExH2ee68nyADckXCTg0knAxcgQ\" alt=\"\" \/><\/figure><\/div>\n\n\n\n<p>In our ruler, each blank li&gt;\/li&gt; will represent a number. The number will appear at the bottom of the tall &#8220;ticks&#8221;:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/Bx5KmOI7MhLKbkdXSganWMuuUiO7gDauJ84Op8n70ZpVE7-2FKX8zbFNai4CqDiLE76vfYTmj_E3O-2HLlEa9lA3NNgZPnSZgNi9PIl0FZq2e1LDZ_aa0cTZymk5z5DY-X4mtW39\" alt=\"\" \/><\/figure><\/div>\n\n\n\n<p>Based on the \u2014ruler2-space-property: we&#8217;ll utilise a CSS counter to fill in the numbers.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/VsKGTT43RAdGlOmFGfAdhKuej0Q1i21KnJXUk_ahyDMqEQH73ZFv29zOG1H6Fjc4ngLTz_kanEVQdpMY7zvuYxOFJocra817vSN_kfgsIStU06ed7f1LPVTlNF4LybmprxQwQOSx\" alt=\"\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Creating an Editor<\/h2>\n\n\n\n<p>&nbsp;Let&#8217;s start by making a simple editor for our ruler.<\/p>\n\n\n\n<p>To update the Custom Properties, we&#8217;ll use a tiny JavaScript:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/FNdF5WutQJDy_Y8Zny8xIT8HlFBbL5drxlBXiIWxTqzBXMeIFaDMjJuIzanBGKZr-bRa_qu2l_wv0QatbcE4DTyqU4EaR5TSEHki7zS-c7bb6iy8WBL6SE9B1Qdzr95MHpcKZPg8\" alt=\"\" \/><\/figure><\/div>\n\n\n\n<p>Add &lt;input&gt;s to the &lt;form id=&#8221;app&#8221;&gt; in HTML, using name for the property to set, value for the value (surprise!) and data-suffix to add any suffix to the value:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/RjP9x8JR32G3isDQe_iNlSg9AgQJ3oyQvwn7-qi_zgZBnImQwlvLR5pg0zZM7l_aF4Tru3uzS64BZFHcRu-l-83Hol35c-_lgqtqiOVP_iC_DwIPO5Tpnq4mCzLA9vxb8racqtpO\" alt=\"\" \/><\/figure><\/div>\n\n\n\n<p>Repeat for each property that you wish to be editable.<\/p>\n\n\n\n<p>Ending Note: you can change the values according to your need in the above codes.<\/p>\n\n\n\n<p><strong>See Also: <a href=\"https:\/\/cssdeck.com\/blog\/creating-a-simple-responsive-image-gallery-using-css\/\">Creating a Simple, Responsive Image Gallery Using CSS<\/a><\/strong><\/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>Create a ruler cell div, add background pictures for markers (linear-gradient is OK), and specify a percent location for each marker. This can only be done once in your CSS, and if you utilize the same picture, there will be [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/what-are-css-image-rulers\/\" title=\"Click to read 'What are CSS Image Rulers to Follow'\">Read Article<\/a><\/p>\n","protected":false},"author":21,"featured_media":3267,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,41,171,173],"tags":[],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/3266"}],"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\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/comments?post=3266"}],"version-history":[{"count":2,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/3266\/revisions"}],"predecessor-version":[{"id":3270,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/3266\/revisions\/3270"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media\/3267"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=3266"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=3266"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=3266"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}