2

I have three ul's in a line. How do i slide the ul to the left side if another ul li's are removed. Here is the example how it looks. (If possible Pure Javascript).

.one {
  box-sizing: border-box;
  padding: 16px;
  width: 100%;
  background-color: red;
  color: #fff;
}
.two {
  box-sizing: border-box;
  padding: 16px;
  width: 100%;
  background-color: green;
  color: #fff;
}
.three {
  box-sizing: border-box;
  padding: 16px;
  width: 100%;
  background-color: blue;
  color: #fff;
}
.closebtn {
  float: right;
  font-size: 30px;
  font-weight: bold;
  cursor: pointer;
}
.closebtn:hover {
  color: #000;
}
ul {
  width: 25%;
  display: inline-block;
}
<ul>
<li class="one">
  <span onclick="this.parentElement.style.display = 'none';" class="closebtn">&times;</span>
  <p>To close this container, click on the X symbol to the right.</p>
</li>
<li class="two">
  <span onclick="this.parentElement.style.display = 'none';" class="closebtn">&times;</span>
  <p>To close this container, click on the X symbol to the right.</p>
</li>
<li class="three">
  <span onclick="this.parentElement.style.display = 'none';" class="closebtn">&times;</span>
  <p>To close this container, click on the X symbol to the right.</p>
</li>
</ul>
<ul>
<li class="one">
  <span onclick="this.parentElement.style.display = 'none';" class="closebtn">&times;</span>
  <p>To close this container, click on the X symbol to the right.</p>
</li>
<li class="two">
  <span onclick="this.parentElement.style.display = 'none';" class="closebtn">&times;</span>
  <p>To close this container, click on the X symbol to the right.</p>
</li>
<li class="three">
  <span onclick="this.parentElement.style.display = 'none';" class="closebtn">&times;</span>
  <p>To close this container, click on the X symbol to the right.</p>
</li>
</ul>
<ul>
<li class="one">
  <span onclick="this.parentElement.style.display = 'none';" class="closebtn">&times;</span>
  <p>To close this container, click on the X symbol to the right.</p>
</li>
<li class="two">
  <span onclick="this.parentElement.style.display = 'none';" class="closebtn">&times;</span>
  <p>To close this container, click on the X symbol to the right.</p>
</li>
<li class="three">
  <span onclick="this.parentElement.style.display = 'none';" class="closebtn">&times;</span>
  <p>To close this container, click on the X symbol to the right.</p>
</li>
</ul>
Pete
  • 57,112
  • 28
  • 117
  • 166

1 Answers1

0

Instead of width on ul you can use max-width. check updated snippet below

.one {
  box-sizing: border-box;
  padding: 16px;
  width: 100%;
  background-color: red;
  color: #fff;
}
.two {
  box-sizing: border-box;
  padding: 16px;
  width: 100%;
  background-color: green;
  color: #fff;
}
.three {
  box-sizing: border-box;
  padding: 16px;
  width: 100%;
  background-color: blue;
  color: #fff;
}
.closebtn {
  float: right;
  font-size: 30px;
  font-weight: bold;
  cursor: pointer;
}
.closebtn:hover {
  color: #000;
}
ul {
  max-width: 25%;
  display: inline-block;
}
<ul>
<li class="one">
  <span onclick="this.parentElement.style.display = 'none';" class="closebtn">&times;</span>
  <p>To close this container, click on the X symbol to the right.</p>
</li>
<li class="two">
  <span onclick="this.parentElement.style.display = 'none';" class="closebtn">&times;</span>
  <p>To close this container, click on the X symbol to the right.</p>
</li>
<li class="three">
  <span onclick="this.parentElement.style.display = 'none';" class="closebtn">&times;</span>
  <p>To close this container, click on the X symbol to the right.</p>
</li>
</ul>
<ul>
<li class="one">
  <span onclick="this.parentElement.style.display = 'none';" class="closebtn">&times;</span>
  <p>To close this container, click on the X symbol to the right.</p>
</li>
<li class="two">
  <span onclick="this.parentElement.style.display = 'none';" class="closebtn">&times;</span>
  <p>To close this container, click on the X symbol to the right.</p>
</li>
<li class="three">
  <span onclick="this.parentElement.style.display = 'none';" class="closebtn">&times;</span>
  <p>To close this container, click on the X symbol to the right.</p>
</li>
</ul>
<ul>
<li class="one">
  <span onclick="this.parentElement.style.display = 'none';" class="closebtn">&times;</span>
  <p>To close this container, click on the X symbol to the right.</p>
</li>
<li class="two">
  <span onclick="this.parentElement.style.display = 'none';" class="closebtn">&times;</span>
  <p>To close this container, click on the X symbol to the right.</p>
</li>
<li class="three">
  <span onclick="this.parentElement.style.display = 'none';" class="closebtn">&times;</span>
  <p>To close this container, click on the X symbol to the right.</p>
</li>
</ul>
Super User
  • 9,448
  • 3
  • 31
  • 47