{"id":9986,"date":"2024-02-27T19:00:13","date_gmt":"2024-02-27T19:00:13","guid":{"rendered":"https:\/\/tyranocode.com\/?p=9986"},"modified":"2024-03-04T19:09:35","modified_gmt":"2024-03-04T19:09:35","slug":"5-useful-css-snippets","status":"publish","type":"post","link":"https:\/\/tyranocode.com\/index.php\/2024\/02\/27\/5-useful-css-snippets\/","title":{"rendered":"5 useful CSS snippets"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\" id=\"f420\">Zoom on hover<\/h1>\n\n\n\n<p>To implement a zoom effect on hover using CSS, you can use the transform property with the scale function.&lt;!DOCTYPE html&gt;<br>&lt;html lang=&#8221;en&#8221;&gt;<br>&lt;head&gt;<br>&lt;meta charset=&#8221;UTF-8&#8243;&gt;<br>&lt;meta name=&#8221;viewport&#8221; content=&#8221;width=device-width, initial-scale=1.0&#8243;&gt;<br>&lt;title&gt;Zoom on Hover&lt;\/title&gt;<br>&lt;\/head&gt;<br>&lt;body&gt;<\/p>\n\n\n\n<p>&lt;div class=&#8221;zoom-on-hover&#8221;&gt;<br>&lt;img src=&#8221;image.png&#8221; alt=&#8221;Zoomable Image&#8221;&gt;<br>&lt;\/div&gt;<\/p>\n\n\n\n<p>&lt;\/body&gt;<br>&lt;\/html&gt;.zoom-on-hover {<br>transition: transform 0.3s ease;<br>}<br>.zoom-on-hover:hover {<br>transform: scale(1.2);<br>}<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"a1ee\">Overlay slide<\/h1>\n\n\n\n<p>To create an overlay slide effect with CSS, you can use absolute positioning along with transition effects.&lt;!DOCTYPE html&gt;<br>&lt;html lang=&#8221;en&#8221;&gt;<br>&lt;head&gt;<br>&lt;meta charset=&#8221;UTF-8&#8243;&gt;<br>&lt;meta name=&#8221;viewport&#8221; content=&#8221;width=device-width, initial-scale=1.0&#8243;&gt;<br>&lt;title&gt;Zoom on Hover&lt;\/title&gt;<br>&lt;\/head&gt;<br>&lt;body&gt;<\/p>\n\n\n\n<p>&lt;div class=&#8221;container&#8221;&gt;<br>&lt;img src=&#8221;image.jpg&#8221; alt=&#8221;Image&#8221;&gt;<br>&lt;div class=&#8221;overlay&#8221;&gt;&lt;\/div&gt;<br>&lt;\/div&gt;<\/p>\n\n\n\n<p>&lt;\/body&gt;<br>&lt;\/html&gt;.container {<br>position: relative;<br>width: 300px; \/* Adjust this according to your image size *\/<br>}<\/p>\n\n\n\n<p>img {<br>width: 100%;<br>height: auto;<br>}<\/p>\n\n\n\n<p>.overlay {<br>opacity: 0;<br>position: absolute;<br>top: 0;<br>left: 100%;<br>width: 100%;<br>height: 100%;<br>background-color: rgba(0, 0, 0, 0.5); \/* Adjust the opacity as needed *\/<br>transition: left 0.3s ease;<br>}<\/p>\n\n\n\n<p>.container:hover .overlay {<br>left: 0;<br>opacity: 1;<br>}<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"ee7d\">Center an item horizontally and vertically<\/h1>\n\n\n\n<p>You can use display: grid; and place-items: center; to center an element horizontally and vertically.&lt;!DOCTYPE html&gt;<br>&lt;html lang=&#8221;en&#8221;&gt;<br>&lt;head&gt;<br>&lt;meta charset=&#8221;UTF-8&#8243;&gt;<br>&lt;meta name=&#8221;viewport&#8221; content=&#8221;width=device-width, initial-scale=1.0&#8243;&gt;<br>&lt;title&gt;Center an element&lt;\/title&gt;<br>&lt;\/head&gt;<br>&lt;body&gt;<\/p>\n\n\n\n<p>&lt;div class=&#8221;container&#8221;&gt;<br>&lt;img src=&#8221;image.jpg&#8221; alt=&#8221;Image&#8221;&gt;<br>&lt;\/div&gt;<\/p>\n\n\n\n<p>&lt;\/body&gt;<br>&lt;\/html&gt;.container{<br>display: grid;<br>place-items: center;<br>height: 500px;<br>border: 2px solid;<br>}<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"609b\">Create a gradient background<\/h1>\n\n\n\n<p>This snippet creates a gradient background that transitions smoothly from one color to another, horizontally from left to right.&lt;!DOCTYPE html&gt;<br>&lt;html lang=&#8221;en&#8221;&gt;<br>&lt;head&gt;<br>&lt;meta charset=&#8221;UTF-8&#8243;&gt;<br>&lt;meta name=&#8221;viewport&#8221; content=&#8221;width=device-width, initial-scale=1.0&#8243;&gt;<br>&lt;title&gt;Gradient background&lt;\/title&gt;<br>&lt;\/head&gt;<br>&lt;body&gt;<\/p>\n\n\n\n<p>&lt;div class=&#8221;container&#8221;&gt;<br>&lt;\/div&gt;<\/p>\n\n\n\n<p>&lt;\/body&gt;<br>&lt;\/html&gt;.container{<br>background: linear-gradient(to right, #ff7e5f, #feb47b); \/* Change colors as needed *\/<br>height: 500px; \/*Height for testing purpose*\/<br>}<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"000f\">Styling links<\/h1>\n\n\n\n<p>This snippet provides basic styling for hyperlinks, removing the default underline and changing the color on hover.&lt;!DOCTYPE html&gt;<br>&lt;html lang=&#8221;en&#8221;&gt;<br>&lt;head&gt;<br>&lt;meta charset=&#8221;UTF-8&#8243;&gt;<br>&lt;meta name=&#8221;viewport&#8221; content=&#8221;width=device-width, initial-scale=1.0&#8243;&gt;<br>&lt;title&gt;Styling links&lt;\/title&gt;<br>&lt;\/head&gt;<br>&lt;body&gt;<\/p>\n\n\n\n<p>&lt;a href=&#8221;#&#8221;&gt;This is a link&lt;\/a&gt;<\/p>\n\n\n\n<p>&lt;\/body&gt;<br>&lt;\/html&gt;a {<br>text-decoration: none;<br>color: #007bff; \/* or any other color *\/<br>}<br>a:hover {<br>text-decoration: underline;<br>}<\/p>\n\n\n\n<p><a href=\"https:\/\/archive.ph\/o\/OWxIA\/https:\/\/medium.com\/@creativebyte\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Zoom on hover To implement a zoom effect on hover using CSS, you can use the transform&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-9986","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/tyranocode.com\/index.php\/wp-json\/wp\/v2\/posts\/9986","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tyranocode.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tyranocode.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tyranocode.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tyranocode.com\/index.php\/wp-json\/wp\/v2\/comments?post=9986"}],"version-history":[{"count":1,"href":"https:\/\/tyranocode.com\/index.php\/wp-json\/wp\/v2\/posts\/9986\/revisions"}],"predecessor-version":[{"id":9991,"href":"https:\/\/tyranocode.com\/index.php\/wp-json\/wp\/v2\/posts\/9986\/revisions\/9991"}],"wp:attachment":[{"href":"https:\/\/tyranocode.com\/index.php\/wp-json\/wp\/v2\/media?parent=9986"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tyranocode.com\/index.php\/wp-json\/wp\/v2\/categories?post=9986"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tyranocode.com\/index.php\/wp-json\/wp\/v2\/tags?post=9986"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}