Creating a PNG image of a CSS star with box-shadow is a great way to improve performance

I created this stunning star using CSS, complete with a beautiful box-shadow effect. However, when I tried to populate my page with multiple stars to create a galaxy effect, the performance took a hit due to the heavy use of box-shadow. This resulted in slow scrolling on the page.

After experimenting, I found that using a PNG image instead of a DIV element significantly improved performance and eliminated the scrolling issue. The only problem is, I can't figure out how to convert this intricate star design into a PNG format. HTML2Canvas was no help as it doesn't support shadows, leaving me stuck with a less-than-ideal solution.

If anyone has any tips or solutions, I would be incredibly grateful for the assistance. My last resort would be to find a similar star design in SVG format, but I believe there are talented individuals here who could provide a better solution. Please help!

.holder {
  position: absolute;
  left: 0%;
  top: 0%;
  width: 100%;
  height: 100%;
  background-color: #000000;
}
.star {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 50px;
  height: 50px;
  transform: translateX(-50%) translateY(-50%);
}
.star div {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 100%;
  height: 100%;
  transform: translateX(-50%) translateY(-50%) rotateX(-85deg) rotateZ(45deg);
  background-color: #ffffff;
  box-shadow:
    0 0 10px #fff,
    0 0 20px #fff,
    0 0 30px #fff,
    0 0 40px rgb(27, 53, 97),
    0 0 70px rgb(27, 53, 97),
    0 0 80px rgb(27, 53, 97),
    0 0 100px rgb(27, 53, 97),
    0 0 150px rgb(27, 53, 97);
}
.star div:nth-child(2) {
  transform: translateX(-50%) translateY(-50%) rotateZ(90deg) rotateX(-85deg) rotateZ(45deg);
}
.star div:nth-child(3) {
  width: 50%;
  height: 50%;
  transform: translateX(-50%) translateY(-50%) rotateZ(45deg) rotateX(-85deg) rotateZ(45deg);
}
.star div:nth-child(4) {
  width: 50%;
  height: 50%;
  transform: translateX(-50%) translateY(-50%) rotateZ(-45deg) rotateX(-85deg) rotateZ(45deg);
}
<div class="holder">
  <div class="star"><div></div><div></div><div></div><div></div></div>
</div>

Answer №1

Here are two versions of unoptimized PNG images. You can use tinypng to optimize them along with the SVG version. The optimized images may not be 100% identical but very close :)

https://i.sstatic.net/2hjUx.png

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    body {
      background-color: #000;
    }
  </style>
</head>

<body>
  <svg width="100%" height="100%" viewBox="0 0 127 129" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;"><g id="lopatk"><use xlink:href="#_Image1" x="61.525" y="0" width="9.481px" height="128.976px" transform="matrix(0.948079,0,0,0.999817,-5.45697e-14,2.72848e-14)"/><use xlink:href="#_Image2" x="0" y="55.061" width="126.142px" height="18.979px" transform="matrix(0.993242,0,0,0.998877,-5.45697e-14,2.72848e-14)"/><path d="M97.182,64.511c0,0 -20.204,-2.312 -34.042,-2.312c-13.838,0 -34.18,2.174 -34.18,2.174c0,0 20.342,2.405 34.042,2.405c13.699,0 34.18,-2.267 34.18,-2.267Z" style="fill:#fff;"/><use xlink:href="#_Image3" x="53.642" y="26.492" width="18.979px" height="75.996px" transform="matrix(0.998877,0,0,0.999948,-5.45697e-14,2.72848e-14)"/><path d="M63.094,29.69c0,0 -2.312,20.611 -2.312,34.728c0,14.116 2.173,34.868 2.173,34.868c0,0 2.405,-20.752 2.405,-34.727c0,-13.976 -2.266,-34.869 -2.266,-34.869Z" style="fill:#fff;"/><use xlink:href="#_Image4" x="32.681" y="34.011" width="60.893px" height="60.978px" transform="matrix(0.99825,0,0,0.999646,-5.45697e-14,2.72848e-14)"/><path d="M50.888,52.354c0,0 8.017,6.387 12.949,11.319c4.932,4.933 11.417,12.949 11.417,12.949c0,0 -8.098,-6.403 -12.981,-11.286c-4.883,-4.883 -11.385,-12.982 -11.385,-12.982Z" style="fill:#fff;"/><use xlink:href="#_Image5" x="49.135" y="50.74" width="27.972px" height="27.891px" transform="matrix(0.99899,0,0,0.996114,-5.45697e-14,2.72848e-14)"/><path d="M75.254,52.354c0,0 -8.016,6.387 -12.949,11.319c-4.932,4.933 -11.417,12.949 -11.417,12.949c0,0 8.098,-6.403 12.982,-11.286c4.883,-4.883 11.384,-12.982 11.384,-12.982Z" style="fill:#fff;"/></g><defs><image id="_Image1" width="10px" height="129px" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAACBCAYAAAD5RSumAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACQklEQVRYha1Y69KrIAzcqO//xK05fwwNywZoz+eMU8RlLwFsK0CHu5u7P/dbBlCfA4CZOQBcNPB4TgC4nxMMtAd09k4cZuZXks3AkL/DAjOeT589gFf2pIAn+ZUeo++dLLQR4TEYr+de9E...[…truncated]…00EWAAAAASUVORK5CYII="/><image id="_Image5" width="28px" height="28px" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAYAAAByDd+UAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABAUlEQVRIibW2w6DIBAE0FH7/59c+lLMOM6yoLCJsdWEwy4XAdbG9r8uD1YgUZTPQox/l57ePMX4Xuh9AYAZGTrIZgcAx0RsA7ALqBUs+0SML35fQFk+LalDtIwXqMaTDCPstuYIP++[![mJa6iy+PhdgafiBgAAAABJRU5ErkJggg=="/></defs></svg>
</body>

</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Highlighting rows using jQuery upon selecting checkboxes

I attempted to emphasize a row in a table using jQuery when the checkbox is checked. This is the jQuery code I used for this purpose: $(":checkbox").change(function() { $(this).closest("tr").toggleClass("highlight", this.checked); }); However, it see ...

Prevent Border Around Images within a Child DIV

Currently, I am in the process of designing a Tumblr theme and facing the challenge of making my pages visually appealing. One particular issue that is causing me trouble is my desire to have images on individual pages bordered in green with a maximum wid ...

The sticky navigation bar hack (implementing fixed positioning with jQuery)

Essentially, when the navigation bar (or any other element) reaches the top of the page or window, a class called "sticky" is added to the element and CSS styles it as fixed. This functionality acts like an IF statement - if the element is far from the top ...

The presence of a border in CSS creates additional room around the content

My issue is that when I apply a border to a div, the content inside no longer fills up 100% of the width and height. I have already tried adding padding: 0;, margin: 0;, and box-sizing: border-box;, but the background still shows at certain zoom levels. ...

Ways to enlarge a div's dimensions initially by adjusting its height and then expanding its width

.box { background-color: DarkSeaGreen; padding: 0px; margin: 0px; float: left; min-height: 50px; min-width: 50px; max-height: 100px; max-width: 100px; } <div class="box"> ab cd ef gh ij kl mn </div> In the provided code snipp ...

Anchor tags within absolutely positioned blocks cannot be clicked in Internet Explorer 6

Dealing with IE6 is a nightmare, but unfortunately, many of our potential clients still use it. So, we have to make it work... I can't figure out why the anchor tags on the exploded view of the house (the little glowing lights) are not clickable. I&a ...

Ensure the div remains fixed in its position regardless of the page's height

I am seeking assistance with making two divs of equal height on my website. The left div contains dynamic content that may expand vertically with various inner divs. Meanwhile, the right div has a single inner div that should remain visible at the top ev ...

Bootstrap styles refusing to be overridden

The custom CSS file I imported after the bootstrap CDN is not successfully overriding it. [Inspecting element screenshot can be viewed here.][1] Importing bootstrap and custom css <!-- Bootstrap --> <link rel="stylesheet" ...

The dropdown menu's subcategories are not functioning properly within the navigation system

I am experiencing an issue with my navigation menu. The 'News' link works correctly, but when I try to access the dropdown menus for "Bulgaria" and "International", they do not appear as expected. Despite having the same code structure, there see ...

Can Three.js be used to create a compact canvas?

I've successfully implemented a three.js scene on my website where users can drag to rotate an object. However, I don't want the scene to take up the entire webpage. I tried adjusting the field parameters with the following code: renderer.setSiz ...

What is the best way to select a clicked span element within a div using JQuery and then adjust the spans before and after it

<div> <span>A</span> <span>B</span> <span>C</span> <span>D</span> </div> If a user clicks on one of the spans within the div, I want to apply styles (such as text color) to that span and all prec ...

I'm attempting to insert a line break after HTML elements that are being added from JavaScript code inside a `display: flex` div

I'm facing an issue where line breaks are not added after HTML elements are inserted via JavaScript upon clicking a button. For instance, the data from the inputs doesn't get separated even when I click submit multiple times: https://i.sstatic. ...

Opera bug causing issues with Bootstrap's :active list item styling

Lately, I've been delving into Bootstrap and have come across an issue while using Opera. Upon the webpage loading, the navbar should display a list structured as follows: <li class="hidden active"> <li class="page-scroll"> <li class=" ...

Is there a way to ensure that the fixed modal remains at the forefront and that its top stays in view even as the user scrolls?

Can you assist me in simplifying this code? import { LoginProps } from '@/layouts/layout.props'; import { Box, Button, Divider, Flex, FormControl, FormLabel, Heading, HStack, IconButton, Input, Link, Stack, Text, } from ...

Dealing with a straightforward problem in CSS: ensuring minimum height of 100% with margin

I'm seeking advice on how to make a div have a minimum height of 100% while also having a margin-top of 15px. My goal is for the div to reach the bottom of the screen without causing scrollbars, but when the content exceeds the screen size, I want it ...

Adjust the checkbox dimensions within the cells of a bootstrap table

I am utilizing bootstrap-table along with a column containing checkboxes. I need to adjust the size of the checkboxes in my code to be 25x25 pixels. However, when I try using the height and width CSS attributes, it does not seem to take effect. html < ...

The border of the circle div wraps around 75% of the circumference of the circle

I am trying to create a circular div with a border that only covers 3/4 of its circumference. Here's an example: Here is what I have so far in my code: <div id="Circle"></div> #Circle { overflow:hidden; display:block; float:left; width ...

CSS / JavaScript Navigation Menu overshadowing Flash content in Firefox

On my website, I have a drop-down menu that was created using CSS and JavaScript. This menu drops down over a Flash animation. Interestingly, in Internet Explorer 6 and 7, the drop-down menus successfully appear over the Flash animation. However, in Mozill ...

The implementation of gulp-less encounters issues when the !important rule is applied

When the !important declaration is used on a specific less variable, it causes the build to fail. The use of !important is common in our codebase, so it's puzzling why this particular instance is causing an issue. Setup: customer1.less @import "bas ...

applying conditional rendering in vue.js

I'm currently working on developing a chat application using the guidelines outlined in this tutorial: https://socket.io/get-started/private-messaging-part-1/ One of my goals is to customize the appearance of the messages, so that when a message is s ...