To divide a div
vertically with two different colors (30% and 70%), you can use a combination of CSS properties like linear-gradient
and background-size
. Here's an example:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Divide Div with Different Colors</title> <style> .colored-div { height: 300px; /* Set the height of your div */ background: linear-gradient(to bottom, #3498db 30%, #e74c3c 30%, #e74c3c 70%, #3498db 70%); background-size: 100% 100%; } </style> </head> <body> <!-- Your HTML content --> <div class="colored-div"></div> </body> </html>
In this example:
.colored-div
class has a specified height (300px
in this case). Adjust this value according to your needs.linear-gradient
is used with color stops at 30% and 70% to create the division.background-size
is set to 100% 100%
to ensure the gradient covers the entire div.This creates a vertical division of the div
with 30% of one color and 70% of another color. Customize the colors and other properties based on your design requirements.
"CSS gradient for vertical color division (30% and 70%)"
.color-divider { height: 100px; background: linear-gradient(to bottom, #3498db 30%, #e74c3c 30%); }
"CSS background-image for vertical color division"
.color-divider { height: 100px; background-image: linear-gradient(to bottom, #27ae60 30%, #f39c12 30%, #f39c12 70%, #e74c3c 70%); }
background-image
with multiple color stops to create a vertical division with 30% and 70% of different colors."CSS pseudo-elements for vertical color division"
.color-divider { height: 100px; position: relative; } .color-divider::before, .color-divider::after { content: ''; position: absolute; top: 0; bottom: 0; width: 30%; } .color-divider::before { left: 0; background-color: #3498db; } .color-divider::after { right: 0; background-color: #e74c3c; }
::before
and ::after
to create two sections with different colors in a vertical division."CSS flexbox for vertical color division"
.color-divider { height: 100px; display: flex; } .color-divider .left { flex: 3; background-color: #3498db; } .color-divider .right { flex: 7; background-color: #e74c3c; }
"CSS grid for vertical color division"
.color-divider { height: 100px; display: grid; grid-template-columns: 30% 70%; } .color-divider .left { background-color: #3498db; } .color-divider .right { background-color: #e74c3c; }
"CSS background-size for vertical color division"
.color-divider { height: 100px; background: linear-gradient(to bottom, #27ae60 30%, #e74c3c 30%, #e74c3c 70%, #3498db 70%); background-size: 100% 200%; }
background-size
to control the size of the gradient, achieving a vertical division with 30% and 70% of different colors."CSS clip-path for vertical color division"
.color-divider { height: 100px; background-color: #3498db; clip-path: polygon(0 0, 30% 0, 30% 100%, 0 100%); }
clip-path
to create a polygon-shaped clip, achieving a vertical division with 30% and 70% different colors."CSS linear-gradient with calc for vertical color division"
.color-divider { height: 100px; background: linear-gradient(to bottom, #3498db 30%, #e74c3c 30%, #e74c3c calc(30% + 1px), #3498db calc(30% + 1px)); }
linear-gradient
with calc
to create a vertical color division with 30% and 70% of different colors."CSS background-clip for vertical color division"
.color-divider { height: 100px; background: linear-gradient(to bottom, #3498db 30%, #e74c3c 30%); background-clip: content-box; }
background-clip: content-box;
to control the background rendering, achieving a vertical color division with 30% and 70%."CSS radial-gradient for vertical color division"
.color-divider { height: 100px; background: radial-gradient(circle, #3498db 30%, #e74c3c 30%, #e74c3c 70%, #3498db 70%); }
radial-gradient
to create a circular gradient, achieving a vertical division with 30% and 70% of different colors.v-model smooth-scrolling core cjk evaluation date stock ubuntu-18.04 spring-config vuetify.js