-3

Trying to float a ul element to the left and tried googled solutions that say to float left and padding 0 but that not seem to be working. How do I align the li items to the left of the row in css? Here is complete codepen. Looking at the image or running the code snippet you can see that there is a large space to the left of the displayed files. I am trying to achieve getting the displayed file names to float left to occupy that whitespace.

enter image description here

function getFileData() {
  var fileDiv = document.querySelector('#files');

  var files = Array.from(document.getElementById('attachments').files);

  fileDiv.innerHTML = '<ul>' + files.map(file => {
    return '<li>' + file.name + '</li>';
  }).join('') + '</ul>';


};
#files {
  display: flex;
  justify-content: left;
}

#files ul {
  list-style-type: none;
  float: left;
}

#files ul li {
  display: inline;
  float: left;
}
<label>Attachments</label>
<div>
  <input type="file" class="form-control input-lg" name="attachments" id="attachments" multiple onchange="getFileData()">
</div>
<div id="files"></div>
mplungjan
  • 169,008
  • 28
  • 173
  • 236
martinbshp
  • 1,073
  • 4
  • 22
  • 36

2 Answers2

1

Just add padding-left: 0; to the #files ul.

#files ul {
  list-style-type: none;
  float: left;
  padding-left: 0;
}
Aleksandar
  • 460
  • 3
  • 13
0

The ul element has some default styles set due to which it behaves like this. Try setting:

padding-inline-start: 0 ; //the original property responsible

OR simply:

padding-left: 0;

for #files ul {} styles. Both will work.

Arslan Shahab
  • 639
  • 3
  • 9