avatarImdodd

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

6092

Abstract

S</h1><p id="cb86">These are some very basic text styling techniques that everyone should know. However, there are many other advanced options available.</p><div id="694c"><pre><span class="hljs-selector-tag">p</span> { <span class="hljs-attribute">font-family</span>: Helvetica, Arial, sans-serif; <span class="hljs-attribute">font-size</span>: <span class="hljs-number">5rem</span>; <span class="hljs-attribute">text-transform</span>: capitalize; <span class="hljs-attribute">text-shadow</span>: <span class="hljs-number">2px</span> <span class="hljs-number">2px</span> <span class="hljs-number">2px</span> pink, <span class="hljs-number">1px</span> <span class="hljs-number">1px</span> <span class="hljs-number">2px</span> pink; <span class="hljs-attribute">text-align</span>: center; <span class="hljs-attribute">font-weight</span>: normal; <span class="hljs-attribute">line-height</span>: <span class="hljs-number">1.6</span>; <span class="hljs-attribute">letter-spacing</span>: <span class="hljs-number">2px</span>; }</pre></div><h1 id="dc40">5. clamp() Function</h1><p id="333d">The CSS clamp() function restricts a value between two bounds, with a preferred value, a minimum value, and a maximum value. It comes in handy when adjusting font sizes based on the viewport.</p><div id="e83f"><pre><span class="hljs-selector-tag">p</span> { <span class="hljs-attribute">font-size</span>: <span class="hljs-built_in">clamp</span>(<span class="hljs-number">1.8rem</span>, <span class="hljs-number">2.5vw</span>, <span class="hljs-number">2.8rem</span>); }

 <span class="hljs-attribute">display</span>: flex;
 <span class="hljs-attribute">justify-content</span>: center;
 <span class="hljs-attribute">align-items</span>: center;
}</pre></div><h1 id="c908">7. CSS Linear Gradient</h1><p id="a824">To create a gradient with CSS, you can simply use the following CSS code.</p><div id="7653"><pre><span class="hljs-selector-tag">div</span> {
 <span class="hljs-attribute">background</span>: <span class="hljs-built_in">linear-gradient</span>(<span class="hljs-number">35deg</span>, <span class="hljs-number">#CCFFFF</span>, <span class="hljs-number">#FFCCCC</span>, <span class="hljs-built_in">rgb</span>(<span class="hljs-number">204</span>, <span class="hljs-number">204</span>, <span class="hljs-number">255</span>));
 <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">20px</span>;
 <span class="hljs-attribute">width</span>: <span class="hljs-number">70%</span>;
 <span class="hljs-attribute">height</span>: <span class="hljs-number">400px</span>;
 <span class="hljs-attribute">margin</span>: <span class="hljs-number">50px</span> auto;
}</pre></div><p id="cab6">These examples demonstrate various CSS techniques for styling text, setting font sizes responsively, centering divs, and creating linear gradients.</p><figure id="f295"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*t0WOrqBh1H29D3lsQ2_5fg.gif"><figcaption></figcaption></figure><p id="cab7">For more information, you can refer to the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/gradient/linear-gradient">MDN Web Docs</a>.</p><h1 id="c277">8. CSS Shake Effect</h1><p id="02b5">This “shake” animation effect shakes the input field when a user enters invalid content. It’s simple yet elegant. For example, if a user enters numbers instead of letters in the text field, the input field will shake.</p><p id="09a5">HTML:</p><div id="bac2"><pre><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">id</span>=<span class="hljs-string">”name”</span> <span class="hljs-attr">type</span>=<span class="hljs-string">”text”</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">”Enter</span> <span class="hljs-attr">your</span> <span class="hljs-attr">name</span>” <span class="hljs-attr">pattern</span>=<span class="hljs-string">”[A-Za-z]*”/</span>&gt;</span></pre></div><p id="0f19">CSS:</p><div id="ba76"><pre><span class="hljs-selector-tag">input</span><span class="hljs-selector-pseudo">:invalid</span> {
 <span class="hljs-attribute">animation</span>: shake <span class="hljs-number">0.2s</span> ease-in-out <span class="hljs-number">0s</span> <span class="hljs-number">2</span>;
 <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">0</span> <span class="hljs-number">0</span> <span class="hljs-number">0.4em</span> red;
}

<span class="hljs-keyword">@keyframes</span> shake {
 <span class="hljs-number">0%</span> { <span class="hljs-attribute">margin-left</span>: <span class="hljs-number">0rem</span>; }
 <span class="hljs-number">25%</span> { <span class="hljs-attribute">margin-left</span>: <span class="hljs-number">0.5rem</span>; }
 <span class="hljs-number">75%</span> { <span class="hljs-attribute">margin-left</span>: -<span class="hljs-number">0.5rem</span>; }
 <span class="hljs-number">100%</span> { <span class="hljs-attribute">margin-left</span>: <span class="hljs-number">0rem</span>; }
}</pre></div><p id="e295">This code creates a “shake” animation for input elements with invalid content. It uses the <code>pattern</code> attribute in the HTML input element to specify the valid input pattern.</p><p id="97fb">When invalid input is detected, the input field shakes briefly, providing a visual indication to the user.</p><figure id="b82b"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*04JK0bX7lOnkiJqT5d-mRA.gif"
# Options
><figcaption></figcaption></figure><p id="f6ed">For more information, you can refer to the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@keyframes">MDN Web Docs</a>.</p><h1 id="225c">9. Shadow Effects</h1><p id="14a4">With CSS, we can add effects to text and elements using the properties text-shadow and box-shadow.</p><p id="55a6">- <code>text-shadow</code>: This property adds a shadow to text.</p><p id="d213">Example:</p><div id="a543"><pre><span class="hljs-selector-tag">h1</span> {
 <span class="hljs-attribute">color</span>: blue;
 <span class="hljs-attribute">text-shadow</span>: <span class="hljs-number">2px</span> <span class="hljs-number">2px</span> <span class="hljs-number">4px</span> <span class="hljs-number">#000000</span>;
}</pre></div><p id="020c">`box-shadow` is used to add shadow effects to elements. In the example below, the actual `div` element is purple, and the box shadow is sky blue, offset 10 pixels to the right and 10 pixels down.</p><div id="31c7"><pre><span class="hljs-selector-tag">div</span> {
 <span class="hljs-attribute">width</span>: <span class="hljs-number">200px</span>;
 <span class="hljs-attribute">height</span>: <span class="hljs-number">200px</span>;
 <span class="hljs-attribute">padding</span>: <span class="hljs-number">15px</span>;
 <span class="hljs-attribute">background-color</span>: purple;
 <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">10px</span> <span class="hljs-number">10px</span> sky
}</pre></div><figure id="87cc"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*I-bXuTF1f3t2uVfLE7-WGQ.png"><figcaption></figcaption></figure><h1 id="f72b">10. Hue Rotation Animation</h1><p id="8342">You can use the following CSS code to create a hue-rotate animation:css</p><div id="c2d8"><pre><span class="hljs-selector-class">.button</span> {
   <span class="hljs-attribute">background</span>: <span class="hljs-built_in">linear-gradient</span>(<span class="hljs-number">35deg</span>, <span class="hljs-number">#8C52FF</span>, <span class="hljs-number">#C669FF</span>);
   <span class="hljs-attribute">animation</span>: hueRotate <span class="hljs-number">3s</span> linear infinite alternate;
}

<span class="hljs-keyword">@keyframes</span> hueRotate {
 <span class="hljs-selector-tag">to</span> {
   <span class="hljs-attribute">filter</span>: <span class="hljs-built_in">hue-rotate</span>(<span class="hljs-number">85deg</span>);
 }
}</pre></div><p id="30c3">In this code:</p><ul><li>We’re targeting an element with the class “button” for the animation.</li><li>We apply a linear gradient background to the button, which creates a gradient between two colors (#8C52FF and #C669FF) at a 35-degree angle.</li><li>The animation is defined using the `<a href="http://twitter.com/keyframes">@keyframes</a>` rule with the name “hueRotate.”</li><li>Inside the keyframes animation, we use the `filter` property to apply the `hue-rotate` filter to the element. This filter rotates the hue of the colors by 85 degrees.</li><li>The animation lasts for 3 seconds, has a linear timing function, runs infinitely, and alternates between the original hue and the rotated hue.</li></ul><p id="e09f">This code will create a color-shifting effect on the button, giving it a dynamic and eye-catching appearance.</p><figure id="92ab"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*KvB3yjMiyfjjfs1uQWtZmQ.gif"><figcaption></figcaption></figure><p id="c8c3"><b><i>Welcome to follow <a href="https://readmedium.com/d4ee7735b468">Imdodd</a>, I will continue to write a lot of interesting games and JavaScript, and Vue.js learning experience.</i></b></p><p id="69a6">In addition, I wrote an article on how to optimize code performance. If you are interested, you can also take a look.</p><div id="e7ea" class="link-block">
          <a href="https://blog.stackademic.com/10-practical-code-shortcuts-in-javascript-to-make-your-code-more-concise-3e405ff850c2">
            <div>
              <div>
                <h2>10 Practical Code Shortcuts in JavaScript to Make Your Code More Concise</h2>
                <div><h3>Here are some my commonly used JavaScript shorthand techniques. Now I share with you to make your code more concise and…</h3></div>
                <div><p>blog.stackademic.com</p></div>
              </div>
              <div>
                <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*j20E53FuMSLZpQfq)"></div>
              </div>
            </div>
          </a>
        </div><div id="c3b9" class="link-block">
          <a href="https://blog.stackademic.com/because-didnt-understand-debouncing-and-throttling-with-vue-and-axios-john-had-to-work-overtime-68cb5c55706c">
            <div>
              <div>
                <h2>Because didn’t understand debouncing and throttling with Vue and Axios, John had to work overtime…</h2>
                <div><h3>Use the way to reduce 60% website’s requests!</h3></div>
                <div><p>blog.stackademic.com</p></div>
              </div>
              <div>
                <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*WaiuIRtirUOii9Jo)"></div>
              </div>
            </div>
          </a>
        </div><h1 id="18a1">In Plain English</h1><p id="b248"><i>Thank you for being a part of our community! Before you go:</i></p><ul><li><i>Be sure to <b>clap</b> and <b>follow</b> the writer! 👏</i></li><li><i>You can find even more content at <a href="https://plainenglish.io/"><b>PlainEnglish.io</b></a><b> 🚀</b></i></li><li><i>Sign up for our <a href="http://newsletter.plainenglish.io/"><b>free weekly newsletter</b></a>. 🗞️</i></li><li><i>Follow us on <a href="https://twitter.com/inPlainEngHQ"><b>Twitter</b></a><b>(X</b></i>), <a href="https://www.linkedin.com/company/inplainenglish/"><b><i>LinkedIn</i></b></a>, <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><b><i>YouTube</i></b></a>, and <a href="https://discord.gg/GtDtUAvyhW"><b><i>Discord</i></b></a><b><i>.</i></b></li></ul></article></body>

10 CSS Properties Every Front-End Developer Should Know

Enhance Your Page, Simplify Your Work

Photo by Ferenc Almasi on Unsplash

In the story, I will share 10 important CSS properties with you. They are so amazing and interesting and useful.

1. :in-range and :out-of-range Pseudo-Classes

CSS’s :in-range and :out-of-range pseudo-classes are used to style inputs within and outside specified range constraints.

:in-range If the current value of an input element falls within the range defined by the min and max attributes, it is considered within range. This pseudo-class is useful for determining whether the current value of a field is acceptable.

:out-of-range If the current value of an input element exceeds the range defined by the min and max attributes, it is considered out of range. This provides users with a visual indication that the field value exceeds the allowed range.

/* Styling for elements within range */
input:in-range {
  background-color: rgba(0, 255, 0, 0.25);
}

/* Styling for elements out of range */
input:out-of-range {
  background-color: rgba(255, 0, 0, 0.25);
}

These pseudo-classes offer a straightforward way to style input elements based on their adherence to specified value constraints.

Note: These pseudo-classes apply only to elements with a scope limit, without which the element cannot be in or out of scope.

For more information, you can refer to the MDN Web Docs.

2. The grayscale Function

By using values ranging from 0 to 100%, you can create various effects. Lower values will retain some color, while higher values will make the image closer to black and white.

This image effect can be achieved using the CSS filter property. By setting the filter property of an image to grayscale(100%), you can completely transform the image into black and white.

To create different effects, you can experiment with different grayscale values, such as grayscale(50%), which will give the image a halftone effect.

With CSS image transformation effects, we can easily convert a color image to black and white by adjusting the values and achieving a variety of different results.

.grayscale-image{
  filter: grayscale(100%);
}

For more information, you can refer to the MDN Web Docs.

3. Glass Effect

We can make a beautiful glass effect with just a few lines of code, adding elegance to our designs.

Glass.CSS is one of the most popular glass effect generators that allows us to create CSS glass effects for our projects for free. All you need to do is adjust some settings according to your requirements and then copy and paste the CSS code into your project.

.glass-effect {
   -webkit-backdrop-filter: blur(6.2px);
   backdrop-filter: blur(6.2px);
   background: rgba(255, 255, 255, 0.4);
   border-radius: 16px;
   border: 1px solid rgba(255, 255, 255, 0.24); 
}

This code snippet applies a glass effect by using backdrop filters and setting the background and border properties accordingly. You can further customize it to fit your project’s needs.

4. Styling Text with CSS

These are some very basic text styling techniques that everyone should know. However, there are many other advanced options available.

p {
 font-family: Helvetica, Arial, sans-serif;
 font-size: 5rem;
 text-transform: capitalize;
 text-shadow: 2px 2px 2px pink, 1px 1px 2px pink;
 text-align: center;
 font-weight: normal;
 line-height: 1.6;
 letter-spacing: 2px;
}

5. clamp() Function

The CSS clamp() function restricts a value between two bounds, with a preferred value, a minimum value, and a maximum value. It comes in handy when adjusting font sizes based on the viewport.

p {
 font-size: clamp(1.8rem, 2.5vw, 2.8rem);
}
```

For more information, you can refer to the MDN Web Docs.

6. Centering a div

One of the most essential tasks for developers is centering a div. There are various options to achieve this, and in this example, we’re using CSS flexbox to center a div both horizontally and vertically.

div {
 display: flex;
 justify-content: center;
 align-items: center;
}

7. CSS Linear Gradient

To create a gradient with CSS, you can simply use the following CSS code.

div {
 background: linear-gradient(35deg, #CCFFFF, #FFCCCC, rgb(204, 204, 255));
 border-radius: 20px;
 width: 70%;
 height: 400px;
 margin: 50px auto;
}

These examples demonstrate various CSS techniques for styling text, setting font sizes responsively, centering divs, and creating linear gradients.

For more information, you can refer to the MDN Web Docs.

8. CSS Shake Effect

This “shake” animation effect shakes the input field when a user enters invalid content. It’s simple yet elegant. For example, if a user enters numbers instead of letters in the text field, the input field will shake.

HTML:

<input id=”name” type=”text” placeholder=”Enter your namepattern=”[A-Za-z]*”/>

CSS:

input:invalid {
 animation: shake 0.2s ease-in-out 0s 2;
 box-shadow: 0 0 0.4em red;
}

@keyframes shake {
 0% { margin-left: 0rem; }
 25% { margin-left: 0.5rem; }
 75% { margin-left: -0.5rem; }
 100% { margin-left: 0rem; }
}

This code creates a “shake” animation for input elements with invalid content. It uses the pattern attribute in the HTML input element to specify the valid input pattern.

When invalid input is detected, the input field shakes briefly, providing a visual indication to the user.

For more information, you can refer to the MDN Web Docs.

9. Shadow Effects

With CSS, we can add effects to text and elements using the properties text-shadow and box-shadow.

- text-shadow: This property adds a shadow to text.

Example:

h1 {
 color: blue;
 text-shadow: 2px 2px 4px #000000;
}

`box-shadow` is used to add shadow effects to elements. In the example below, the actual `div` element is purple, and the box shadow is sky blue, offset 10 pixels to the right and 10 pixels down.

div {
 width: 200px;
 height: 200px;
 padding: 15px;
 background-color: purple;
 box-shadow: 10px 10px sky
}

10. Hue Rotation Animation

You can use the following CSS code to create a hue-rotate animation:css

.button {
   background: linear-gradient(35deg, #8C52FF, #C669FF);
   animation: hueRotate 3s linear infinite alternate;
}

@keyframes hueRotate {
 to {
   filter: hue-rotate(85deg);
 }
}

In this code:

  • We’re targeting an element with the class “button” for the animation.
  • We apply a linear gradient background to the button, which creates a gradient between two colors (#8C52FF and #C669FF) at a 35-degree angle.
  • The animation is defined using the `@keyframes` rule with the name “hueRotate.”
  • Inside the keyframes animation, we use the `filter` property to apply the `hue-rotate` filter to the element. This filter rotates the hue of the colors by 85 degrees.
  • The animation lasts for 3 seconds, has a linear timing function, runs infinitely, and alternates between the original hue and the rotated hue.

This code will create a color-shifting effect on the button, giving it a dynamic and eye-catching appearance.

Welcome to follow Imdodd, I will continue to write a lot of interesting games and JavaScript, and Vue.js learning experience.

In addition, I wrote an article on how to optimize code performance. If you are interested, you can also take a look.

In Plain English

Thank you for being a part of our community! Before you go:

CSS
Front End Development
Web Development
Coding
Programming
Recommended from ReadMedium