以文件输入形式为中心 - html / bootstrap / angular

时间:2015-11-09 08:19:19

标签: html css angularjs

我已经使用Angular指令创建了一个文件输入,由于某种原因,它似乎很难将其置于中心位置:

enter image description here

这是我的HTML,感谢任何见解。

<form class=".form-control">
    <center style="border: blue">
        <input class=".form-control" type="file" file-input="files" multiple>
    </center>
    <br>
    <br>
    <button class=".form-group" ng-click="upload('/upload')">Upload</button>
    <button class=".form-group" ng-click="upload('/upload/save')">
        Save New Profile Picture
    </button>
    <li ng-repeat="file in files">{{file.name}}
        <img ng-src="{{imageData}}" style="max-height: 200px; max-width: 200px">
    </li>
</form>

1 个答案:

答案 0 :(得分:3)

对于初学者,你现在不应该使用center,它已经过时了。现在,您可以这样做:

<input class="form-control center" type="file" file-input="files" multiple>

CSS

.center { 
    margin: 0 auto !important; /* I have added the !important attribute just for debugging, you can remove it. */ 
}

另一个有效的技巧是使用flexbox:

<form class="form-control flex">

CSS:

.flex { 
    display: flex;
    justify-content: center;
    align-items: center; /* Optional */
}

详细了解flexbox here