One place for hosting & domains

      How to Change a CSS Background Image’s Opacity


      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.

      With CSS and CSS3 you can do a lot of things, but setting an opacity on a CSS background is not one of them. However, if you get creative, there are a ton of creative work-arounds you to make it seem like you’re changing the CSS background image’s opacity. Both of the following methods have excellent browser support down to Internet Explorer 8.

      Method 1: Use absolute positioning and an image

      This method is exactly like it sounds. You simply use absolute positioning on an a normal img tag and make it seem like you used the CSS background-image property. All you have to do is put the image inside of a position: relative; container. Here’s what the HTML markup generally looks like:

      <div class="demo_wrap">
        <h1>Hello World!</h1>
        <img src="https://www.xpresservers.com/wp-content/uploads/2020/09/How-to-Change-a-CSS-Background-Images-Opacity.png">
      </div>
      

      And here’s what your CSS will look like:

      .demo_wrap {
          position: relative;
          overflow: hidden;
          padding: 16px;
          border: 1px dashed green;
      }
      .demo_wrap h1 {
          padding: 100px;
          position: relative;
          z-index: 2;
      }
      .demo_wrap img {
          position: absolute;
          left: 0;
          top: 0;
          width: 100%;
          height: auto;
          opacity: 0.6;
      }
      

      The trick here is to absolutely position the img and stretch it so it fills the entire parent container. And to relatively position everything else so that you can set a z-index that pulls it above the img.

      Here’s a live demo:

      Method 2: Using CSS Pseudo-Elements

      This method is seems simple once you see it, and is definitely my preferred method of doing this. Using CSS pseudo-elements of either :before or :after, you a div with a background image and set an opacity on it. Here’s what your HTML markup would roughly look like:

      <div class="demo_wrap">
        <h1>Hello World!</h1>
      </div>
      

      And here’s what the CSS looks like:

         .demo_wrap {
          position: relative;
          background: #5C97FF;
          overflow: hidden;
      }
      .demo_wrap h1 {
          padding: 50px;
          position: relative;
          z-index: 2;
      }
      /* You could use :after - it doesn't really matter */
      .demo_wrap:before {
          content: ' ';
          display: block;
          position: absolute;
          left: 0;
          top: 0;
          width: 100%;
          height: 100%;
          z-index: 1;
          opacity: 0.6;
          background-image: url('https://www.xpresservers.com/wp-content/uploads/2020/09/How-to-Change-a-CSS-Background-Images-Opacity.png');
          background-repeat: no-repeat;
          background-position: 50% 0;
          background-size: cover;
      }
      

      Here again we must move the z-index of content (in this cas the <h1>) above the background pseudoelement, and we must explicitly define the position: absolute; and z-index: 1 on the :before pseudoelement.

      The rest of the attributes on the pseudoelement exist to position it to overlap 100% of the parent, and also make use of a clever new CSS property: background-size: cover which sizes the background to cover the element without changing proportions.
      Here’s a nice little demo of this method:



      Source link

      6 Awesome CSS Extensions for VS Code


      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.

      One of the most impressive parts of Visual Studio Code is customizability, especially via extensions. With tons of developers creating extensions, the functionality is literally endless! Here are some of the best extensions in VS Code for writing CSS.

      Check out Learn Visual Studio Code to learn everything you need to know about about the hottest editor in Web Development!

      HTML CSS Support


      HTML CSS Support (and the next extension listed) provides intellisense in your HTML files based on the CSS that is included in your project or referenced remotely. Here’s a full list of features.

      • Class attribute completion

      • Id attribute completion

      • Supports Zen Coding completion for class and id attributes

      • Scans workspace folder for css and scss files

      • Supports remote css files

      One thing that really stands out about this one is that you can specify remote CSS files to cache as well. You can do this by adding the following setting. This example is refering the Bootstrap 4 CSS file.

      "css.remoteStyleSheets": [
        "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css"
      ]
      

      Intellisense for CSS Class Names

      Intellisense for CSS Class Names provides similar functionality to the extension above. This one will also automatically pull classes from CSS referenced in your HTML files. This class definitions will also be available via intellisense when using Emmet as well!

      At any point, you can trigger a re-cache of the classes from your CSS files by opening up the Command Palette.

      Autoprefixer


      Having to prefix certain CSS properties to ensure browser support can be an extreme hassle. If it weren’t for the workflows already configured with Create React App, Angular CLI, etc. I would completely forget to add the vendor prefixes.

      Autoprefixer will automatically add vendor prefixes to make sure your app looks as good as possible in different browsers. It’s crazy simple. Open the Command Palette and call “Autoprefixer CSS”.

      CSS Peek

      If you’re anything like me, I hate having to toggle over to my .css file to check the properties attached to a class or id. With CSS Peek, you can view a hover image of your CSS from within you HTML file.

      This extension also turns class names and ids into a hyper link that takes you directly to that class or id definition in your CSS!

      Prettier – Code Formatter

      Never worry about formatting again. Setup Prettier once, and it takes care of the rest!

      Prettier – Code Formatter is incredibly popular for auto-formatting your JavaScript, but did you know it autoformats CSS as well? Well, it does, and it’s awesome!

      Here’s a before (with terrible format).

      …and after (with BEAUTIFUL formatting)!


      You can set this up to run on save automatically or manually if you choose.

      Bootstrap 4, Font awesome 4, Font Awesome 5 Free & Pro snippets

      Sure, not every project uses Bootstrap or Font Awesome, but a ton of them do. That’s why I figured it was worth sharing this extension which provides intellisense for Bootstrap 4, Font Awesome 4, and Font Awesome 5.

      There are so many classes in Bootstrap that it’s impossible to memorize them all. Same with working with Font Awesome. I have to look up the syntax every time I want to add an icon, but not anymore!

      To activate the snippets for Bootstrap use “B4”.

      and “FA5” for Font Awesome 5.

      Recap

      There you go, some of the best CSS extensions for Visual Studio Code. If you think we’ve missed anything, comment below and share your favorites!



      Source link

      Change the Mouse Cursor in CSS With the cursor 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.

      cursor is used to change the mouse cursor on specific elements. This is especially useful in web apps where different tasks can be done other than clicking. This obviously only works when there’s a pointing device:

      .in-progress {
        cursor: progress;
      }
      

      Available Cursors

      Hover over the following to see the different cursors available if you’re on a desktop/laptop computer:

      General/Default Cursors

      Scroll Cursor

      Status Cursors

      context-menu

      help

      wait

      progress

      Selection Cursors

      crosshair

      cell

      text

      vertical-text

      Drag & Drop Cursors

      alias

      copy

      move

      no-drop

      not-allowed

      Zoom Cursors

      Grab Cursors

      Resizing Cursors

      e-resize

      n-resize

      ne-resize

      nw-resize

      s-resize

      se-resize

      sw-resize

      w-resize

      ew-resize

      ns-resize

      nesw-resize

      nwse-resize

      col-resize

      row-resize

      Custom Cursors

      You can define custom cursors. Note that not all browsers support svg files for cursors, and .cur files are supported across the board, so it can be a good idea to provide a .cur fallback if you want to use an svg cursor. You can also provide a fallback to one of the non-custom cursors.

      You can define a custom position for the cursor hotspot by adding x & y coordinates for where the hotspot should be in the provided custom image.

      Note that, when using svg cursors, it’s important that your svg has width & height values on the root svg element, or else your cursor won’t show. In the following example, our svg file (droplet.svg) starts like this:

      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 42 42" width="42" height="42">...
      
      .custom-cur {
        cursor: url('/images/droplet.svg');
      }
      
      /* With a .cur fallback */
      .custom-cur {
        cursor: url('/images/droplet.svg'),
        url('/images/droplet.cur');
      }
      
      /* With a custom hotspot */
      .custom-cur {
        cursor: url('/images/droplet.svg') 10 12;
      }
      
      /* With a non-custom fallback: */
      .custom-cur {
        cursor: url('/images/droplet.svg'),
        move;
      }
      

      Here’s an example with a custom cursor:

      Dino Sammy Cursor

      Browser Support:
      As of 2020, only 80% of browsers worldwide support custom cursors according to Can I Use css3-cursors?. But this isn’t surprising, many of the browsers that don’t support it are mobile-only browsers that have no use for cursors.

      Conclusion:

      Custom cursors are most commonly used to indicate that an HTML element that’s not already a link <a href="https://www.digitalocean.com/community/tutorials/..."> is clickable. But it provides a diverse set of additional configurability that could be useful to developers building rich web apps. Keep the following caveats in mind when using custom cursors:

      1. Your users spend most of their time on other sites, so use custom cursors in a way that is consistent with other sites.
      2. Touchscreen users (mobile and tablet) won’t see custom cursors.



      Source link