One place for hosting & domains

      Property

      CSS white-space Property


      While this tutorial has content that we believe is of great benefit to our community, we have not yet tested or
      edited it to ensure you have an error-free learning experience. It’s on our list, and we’re working on it!
      You can help us out by using the “report an issue” button at the bottom of the tutorial.

      white-space is a CSS property that helps control how whitespace and line breaks within an element’s text are treated.

      The white-space property can take these values:

      • normal: The default value. Multiple whitespaces are collapsed into one. The text wraps to the next line when needed.
      • nowrap: Multiple whitespaces are collapsed into one, but the text doesn’t wrap to the next line. We’ve already discussed how to use the nowrap value to prevent line breaks.
      • pre: Same results as using the <pre> where all the whitespaces will be kept as is and the text only wraps when line breaks are in the content.
      • pre-line: Multiple whitespaces are collapsed into one, the text breaks to the next line when needed or with line breaks in the content.
      • pre-wrap: Similar to pre, but the text also wraps when needed.

      white-space: normal

      Medusafish banded killifish convict blenny saury threadsail beluga sturgeon. Indian mul mora cisco masu salmon, roosterfish requiem shark longnose lancetfish bluefish red snapper Sacramento splittail giant danio.

      white-space: nowrap

      Medusafish banded killifish convict blenny saury threadsail beluga sturgeon. Indian mul mora cisco masu salmon, roosterfish requiem shark longnose lancetfish bluefish red snapper Sacramento splittail giant danio.

      white-space: pre

      Here I manually included line breaks and extra spaces. Notice the extra line break at the beginning. That’s because in the markup the text start on the line after the <p> element.

      Medusafish banded killifish convict blenny saury threadsail beluga sturgeon. Indian mul mora cisco masu salmon, roosterfish requiem shark longnose lancetfish bluefish red

      snapper Sacramento splittail giant danio.

      pre-line

      Here the text breaks when needed, but I also manually broke the last few words. I included the same extra whitespaces, but they are now collapsed.

      Medusafish banded killifish convict blenny saury threadsail beluga sturgeon. Indian mul mora cisco masu salmon, roosterfish requiem shark longnose lancetfish bluefish red snapper Sacramento splittail giant danio.

      pre-wrap

      Now the extra whitespaces aren’t collapsed.

      Medusafish banded killifish convict blenny saury threadsail beluga sturgeon. Indian mul mora cisco masu salmon, roosterfish requiem shark longnose lancetfish bluefish red snapper Sacramento splittail giant danio.



      Source link

      Masking Images in CSS Using the mask-image Property


      While this tutorial has content that we believe is of great benefit to our community, we have not yet tested or
      edited it to ensure you have an error-free learning experience. It’s on our list, and we’re working on it!
      You can help us out by using the “report an issue” button at the bottom of the tutorial.

      We covered the use of the clip-path property for clipping using CSS, so it’s only natural that we now go over masking. Contrary to clipping, where a part of an image or element is either completely invisible or completely visible, with masking we can hide or show parts of an image with different levels of opacity.

      Masking in CSS is done using the mask-image property, and an image has to be provided as the mask. Anything that’s 100% black in the image mask with be completely visible, anything that’s 100% transparent will be completely hidden, and anything in-between will partially mask the image. Linear and radial gradients in CSS are generated images, so they can be used as the image mask. SVGs that use the mask element can also be used as the image mask. Let’s go over the 3 possibilities for image masks with concrete examples:

      Masking Using Gradients

      Let’s first use a simple linear gradient that goes from transparent to black. The first image is our default starting image, and the second image has our linear gradient applied as the mask-image value:

      Without mask
      With gradient mask

      Here’s the CSS rules used here:

      .mask1 {
        -webkit-mask-image: linear-gradient(to bottom, transparent 25%, black 75%);
        mask-image: linear-gradient(to bottom, transparent 25%, black 75%);
      }
      

      Here are two more examples of interesting effects that can be accomplished with masking using gradients:

      Gradient mask example 2
      Gradient mask example 3

      And the CSS rules for these 2 gradient masks:

      .mask2 {
        -webkit-mask-image: radial-gradient(circle at 50% 60%, black 50%, rgba(0, 0, 0, 0.6) 50%);
        mask-image: radial-gradient(circle at 50% 60%, black 50%, rgba(0, 0, 0, 0.6) 50%);
      }
      .mask3 {
        -webkit-mask-image: radial-gradient(ellipse 90% 80% at 48% 78%, black 40%, transparent 50%);
        mask-image: radial-gradient(ellipse 90% 80% at 48% 78%, black 40%, transparent 50%);
      }
      

      Masking Using Images

      Here’s we’re using an image that was created using Sketch as our image mask. The first image is the image mask itself, and the second image has that mask applied to it:

      Image mask
      With image mask

      And our CSS looks like this:

      .mask4 {
        -webkit-mask-image: url("/path/to/image-mask.png");
        mask-image: url("/path/to/image-mask.png");
        -webkit-mask-size: 400px 600px;
        mask-size: 400px 600px;
      }
      

      We specified a value for mask-size here because our image mask is 800px by 1200px, but here we want everything shrunk by half so that the image can look sharp on retina displays.

      Masking Using SVG Masks

      Finally, if SVG is your groove, you can define image masks using the SVG mask element.

      The first example currently only seems to be working in Firefox (you probably won’t see anything in non-supporting browsers). It defines the SVG mask and then we reference the ID of the mask in CSS as usual. The second example seems to have wider support and defines the image as part of the SVG element itself.

      Also note that with SVG masks, the colors to use are white and black instead of transparent and black. The colors also work in reverse and white/partially white is what will be visible.

      See the Pen mdPBExv by alligatorio (@alligatorio) on CodePen.

      Example 1 (triangle)

      Here’s the SVG markup for the first example:

      <svg width="0" height="0" viewBox="0 0 400 600">
        <defs>
          <mask id="my-svg-mask">
            <rect fill="#000000" x="0" y="0" width="400" height="600"></rect>
            <polygon fill="#FFFFFF" points="200.5 152 349 449 52 449"></polygon>
          </mask>
        </defs>
      </svg>
      

      Then we can apply the mask to our image with mask-image as usual by refecencing the ID of the SVG mask:

      .mask5 {
        -webkit-mask-image: url(#my-svg-mask);
        mask-image: url(#my-svg-mask);
      }
      

      Example 2 (bubbles)

      For our second SVG example, everything is contained in the SVG definition, including our main image itself:

      <svg width="400px" height="600px" viewBox="0 0 400 600">
        <defs>
          <mask id="my-svg-mask2">
            <rect id="Rectangle" fill="#000000" x="0" y="0" width="400" height="600"></rect>
            <circle id="Oval" fill="#FFFFFF" cx="67.5" cy="51.5" r="67.5"></circle>
            <circle id="Oval" fill="#FFFFFF" cx="296.597656" cy="118.597656" r="56.5976562"></circle>
            <circle id="Oval" fill="#FFFFFF" cx="53.4648437" cy="256.464844" r="81.4648437"></circle>
            <circle id="Oval" fill="#FFFFFF" cx="239.587891" cy="313.587891" r="70.5878906"></circle>
            <circle id="Oval" fill="#FFFFFF" cx="366.597656" cy="562.597656" r="56.5976562"></circle>
            <circle id="Oval" fill="#FFFFFF" cx="93.203125" cy="486.203125" r="76.203125"></circle>
          </mask>
        </defs>
        <image mask="url(#my-svg-mask2)" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://www.digitalocean.com/images/css/masking/masking-example1.jpg" width="400" height="600"></image>
      </svg>
      



      Source link

      The CSS text-shadow property


      While this tutorial has content that we believe is of great benefit to our community, we have not yet tested or
      edited it to ensure you have an error-free learning experience. It’s on our list, and we’re working on it!
      You can help us out by using the “report an issue” button at the bottom of the tutorial.

      The CSS text-shadow property is similar to the box-shadow property, but the shadow is applied to each letter instead of the boundaries of the element:

      text-shadow: 2px 2px 1px rgba(0,0,0,0.4);
      

      The values go in this order: offset-x offset-y blur-radius color.

      You can also define multiple shadows:

      text-shadow: 45px 25px 4px rgb(25,93,229),
                   25px 15px 1px rgb(25,93,229);
      

      Note that, as with the box-shadow property, you can define multiple comma-separated shadows. Unlike with box-shadow however, you can’t define a spread value or use the inset keyword for text shadows. There are ways to create a text shadow that looks like an inset shadow, but the shadow itself won’t actually be inset.

      Result

      Here’s the result of the 2 text shadows from the above snippet:

      I’m just some text in the world with a basic shadow.

      I’m just some text in the world with two shadows.



      Source link