html - How to divide div color with 30% different color and 70% different color in vertical using css

Html - How to divide div color with 30% different color and 70% different color in vertical using css

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:

  • The .colored-div class has a specified height (300px in this case). Adjust this value according to your needs.
  • The linear-gradient is used with color stops at 30% and 70% to create the division.
  • The 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.

Examples

  1. "CSS gradient for vertical color division (30% and 70%)"

    • Code Implementation:
      .color-divider { height: 100px; background: linear-gradient(to bottom, #3498db 30%, #e74c3c 30%); } 
    • Description: Utilizes a linear gradient background to achieve a vertical color division, with 30% of the first color and 70% of the second color.
  2. "CSS background-image for vertical color division"

    • Code Implementation:
      .color-divider { height: 100px; background-image: linear-gradient(to bottom, #27ae60 30%, #f39c12 30%, #f39c12 70%, #e74c3c 70%); } 
    • Description: Uses background-image with multiple color stops to create a vertical division with 30% and 70% of different colors.
  3. "CSS pseudo-elements for vertical color division"

    • Code Implementation:
      .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; } 
    • Description: Uses pseudo-elements ::before and ::after to create two sections with different colors in a vertical division.
  4. "CSS flexbox for vertical color division"

    • Code Implementation:
      .color-divider { height: 100px; display: flex; } .color-divider .left { flex: 3; background-color: #3498db; } .color-divider .right { flex: 7; background-color: #e74c3c; } 
    • Description: Applies flexbox with two child divs, adjusting their flex properties to achieve a 30%-70% vertical color division.
  5. "CSS grid for vertical color division"

    • Code Implementation:
      .color-divider { height: 100px; display: grid; grid-template-columns: 30% 70%; } .color-divider .left { background-color: #3498db; } .color-divider .right { background-color: #e74c3c; } 
    • Description: Implements a CSS grid with two columns to achieve a vertical color division with 30% and 70% different colors.
  6. "CSS background-size for vertical color division"

    • Code Implementation:
      .color-divider { height: 100px; background: linear-gradient(to bottom, #27ae60 30%, #e74c3c 30%, #e74c3c 70%, #3498db 70%); background-size: 100% 200%; } 
    • Description: Uses background-size to control the size of the gradient, achieving a vertical division with 30% and 70% of different colors.
  7. "CSS clip-path for vertical color division"

    • Code Implementation:
      .color-divider { height: 100px; background-color: #3498db; clip-path: polygon(0 0, 30% 0, 30% 100%, 0 100%); } 
    • Description: Utilizes clip-path to create a polygon-shaped clip, achieving a vertical division with 30% and 70% different colors.
  8. "CSS linear-gradient with calc for vertical color division"

    • Code Implementation:
      .color-divider { height: 100px; background: linear-gradient(to bottom, #3498db 30%, #e74c3c 30%, #e74c3c calc(30% + 1px), #3498db calc(30% + 1px)); } 
    • Description: Uses linear-gradient with calc to create a vertical color division with 30% and 70% of different colors.
  9. "CSS background-clip for vertical color division"

    • Code Implementation:
      .color-divider { height: 100px; background: linear-gradient(to bottom, #3498db 30%, #e74c3c 30%); background-clip: content-box; } 
    • Description: Applies background-clip: content-box; to control the background rendering, achieving a vertical color division with 30% and 70%.
  10. "CSS radial-gradient for vertical color division"

    • Code Implementation:
      .color-divider { height: 100px; background: radial-gradient(circle, #3498db 30%, #e74c3c 30%, #e74c3c 70%, #3498db 70%); } 
    • Description: Uses radial-gradient to create a circular gradient, achieving a vertical division with 30% and 70% of different colors.

More Tags

v-model smooth-scrolling core cjk evaluation date stock ubuntu-18.04 spring-config vuetify.js

More Programming Questions

More Mortgage and Real Estate Calculators

More General chemistry Calculators

More Trees & Forestry Calculators

More Cat Calculators