I want to create a unique design by combining a solid color and a gradient in a single CSS background attribute. The challenge here is to have these two backgrounds with separate size and position parameters specified in individual background-position and background-size attributes so that they can be placed next to each other.
div {
width: 400px; height: 200px; border: 1px solid gray;
background: red, linear-gradient(to right, black, white);
background-position: left, right;
background-size: 70% 100%, 30% 100%;
background-repeat: no-repeat;
}
<div></div>
This setup should result in the following visual appearance:
https://i.sstatic.net/ZWCDp.png
However, Chrome indicates an error stating that the background property has an invalid value:
https://i.sstatic.net/WGrvB.png
I am struggling to comprehend the reason behind this error.
My attempts to find a solution on Stack Overflow or through Google have not been successful as most solutions involve combining a color with an image, which is different from my requirement of having distinct colors and gradients as "two backgrounds" with their own sizes and positions.
The goal is to avoid merging the solid color into the gradient for two primary reasons:
- The end plan involves rotating the gradient while keeping the vertical border between the two backgrounds intact.
- There is a need to animate the position/size change in a transition (altering the 70%/30% ratio during hover), which cannot be achieved with single gradient stops.
The current workaround I have employed seems inelegant - wrapping the solid color in a gradient with identical start and end colors. It feels like there should be a simpler solution...