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

Stretching an element in both directions considering paddings

I’m pretty new to CSS so apologies for this question in advance. I know that it’s pretty easy, but I can’t create an element that is fully stretched in both directions (consider padding, please). Here is my try:

* {
   background-color: lightblue;
}

body {
  display: flex;
  justify-content: left;
  overflow:hidden;
   height: 100%;
}
.timeline {
  width: 85%;
  height: 25%;
  background: #ECF1F524;
  mix-blend-mode: normal;
  backdrop-filter: blur(15px);
  overflow: hidden;
  position: absolute;
  box-shadow: 0px 20px 53px -30px rgba(95, 102, 173, 0.566816);
  border-radius: 30px;
  
  padding-top: 100px;
  padding-right: 100px;
  padding-bottom: 100px;
  padding-left: 100px;
}
<html>
<body>
  <div class="main">
    <div class="timeline"/>
</div>
</body>
</html>

>Solution :

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

In your code you are mixing different techniques. One way to achieve the result is using "static" positioning (default) is the following. I suggest you to take a look at the box sizing property when struggling with paddings. It’s generally useful to set box-sizing: border-box for all elements.

The other tricky part is setting a full height. All parent elements should have a height: 100% to stretch full width.

* {
  box-sizing: border-box;
}

html,
body,
.main {
  background-color: lightblue;
  height: 100%;
  margin: 0;
  padding: 4px;
}

.timeline {
  width: 100%;
  height: 100%;
  background: #ECF1F524;
  mix-blend-mode: normal;
  backdrop-filter: blur(15px);
  box-shadow: 0px 20px 53px -30px rgba(95, 102, 173, 0.566816);
  border-radius: 30px;
  padding-top: 100px;
  padding-right: 100px;
  padding-bottom: 100px;
  padding-left: 100px;
}
<html>

<body>
  <div class="main">
    <div class="timeline" />
  </div>
</body>

</html>
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