Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Symmetrical gradient as background

I would like to make a gradient on the background of the page in such a way that it is light blue in the center and turns into dark blue symmetrically to the left and right. I made gradient that goes from left to the right, but there is no symmetry as I wish.

I was thinking about dividing body section into two 50% width divs with float: left and designing the left one like a mirror reflection of the right one, but I am convinced that there is an easier and shorter way to do it. I’m also worried that creating two divs only for colors may cause problems with subsequent divs later.

Here is my code in HTML and CSS:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

body {
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: linear-gradient(to right, #3498db, #162ba4);
}

.main-container {
  padding: 20px;
  background: rgba(244, 228, 228, 0.532);
  /* main divs color */
  border-radius: 20px;
  backdrop-filter: blur(10px);
  /* blur */
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
  /* shadow */
}
<div class="main-container">
  <!-- content -->
  <h1>My page</h1>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit....</p>
</div>

>Solution :

replace the background property in body with this line

  background-image: linear-gradient(to right, #162ba4, #3498db, #162ba4);
body {
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background-image: linear-gradient(to right, #162ba4, #3498db, #162ba4);
}

.main-container {
  padding: 20px;
  background: rgba(244, 228, 228, 0.532);
  /* main divs color */
  border-radius: 20px;
  backdrop-filter: blur(10px);
  /* blur */
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
  /* shadow */
}
<div class="main-container">
  <!-- content -->
  <h1>My page</h1>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit....</p>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading