我有一个bootstrap表单,其中有一个输入文件,但我希望它具有btn-outline-info的设计,所以我这样做:
<div class="btn btn-outline-info btn-lg">
<input id="signedAgreementFile" type="file" class="form-control-file">
</div>所以我有一个“选择一个文件”按钮,它的旁边有一个蓝色的字符串:“没有文件选择”,它们都在一个蓝色的框中:

当我将鼠标悬停在屏幕上时,按钮变为蓝色,文本变为白色:

直到现在一切都很顺利。但当我上传一个文件时,文件的名称将替换“无文件选择”,但始终保持空白:


我不知道为什么以及如何纠正它。我甚至不能在HTML中访问这个文本。
发布于 2018-10-13 08:09:21
将text-info类添加到您的输入中,并添加额外的CSS以停止悬停时背景颜色的更改。
.btn:hover {
background-color: transparent !important;
}<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<div class="btn btn-outline-info btn-lg">
<input id="signedAgreementFile" type="file" class="form-control-file text-info">
</div>
发布于 2018-10-14 04:04:52
尝尝这个?
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<div class="btn btn-outline-info btn-lg">
<input id="signedAgreementFile" type="file" class="form-control-file" onchange="this.style.color='#17a2be'">
</div>
https://stackoverflow.com/questions/52786978
复制相似问题