Currently, I am working on a project involving HTML/CSS/JS where the application has a fixed size and requires precise positioning of elements according to the provided designs. Working with pixel dimensions in CSS is not a concern due to the fixed window size, eliminating the need to worry about browser resizing. Moreover, the focus is solely on ensuring compatibility with webkit and firefox, disregarding IE and Opera.
At certain points in the project, I need to implement a gradient background spanning a specific number of pixels. This can be easily achieved using:
background-image: linear-gradient(to top, #666666, #000000 60px);
(along with its -webkit-
and -moz-
versions). This method works for most elements but poses a challenge for instances where the color stops need to be defined by top and bottom pixel positions. If these positions were percentages, handling them would be straightforward with code like:
background-image: linear-gradient(to top, #666666, black 60px, transparent 60px, transparent 90%, black 90%, #666666);
(transitioning from grey to black over 60px followed by a transparent section and then black to grey over the last 10%). However, the requirement is to achieve the same outcome based on pixels, considering that the element's size varies. Ideally, relying on JS to dynamically apply the gradient with calculated percentage points should be avoided.
Hence, my inquiry is whether there is a method to specify a color stop x pixels (not percentage) from the end?