bootstrap 中的自定义输入文件 4 不显示按钮
custom input file in bootstrap 4 not show button
当我在 bootstrap 4 中使用自定义输入文件时,不更改我的输入并且不显示 browse
按钮。
<label class="custom-file">
<input type="file" id="Image" class="custom-file-input">
<span class="custom-file-control"></span>
</label>
.自定义文件
position: relative;
display: inline-block;
max-width: 100%;
height: 2.5rem;
cursor: pointer;
.自定义文件输入
min-width: 14rem;
max-width: 100%;
margin: 0;
filter: alpha(opacity=0);
opacity: 0;
.自定义文件控制
position: absolute;
top: 0;
left: 0;
right: 0;
z-index: 5;
height: 2.5rem;
padding: .5rem 1rem;
line-height: 1.5;
color: #555;
user-select: none;
background-color: #fff;
border: 1px solid #ddd;
border-radius: .25rem;
据我检查 - 您需要插入 :before 和 :after 伪元素 - 然后就可以了。
.custom-file-control:before{
content: "Browse";
}
.custom-file-control:after{
content: "Add files..";
}
尝试使用以下代码。希望它能解决你的问题。它在 Bootstrap 页面的代码示例下方给出。
$custom-file-text: (
placeholder: (
en: "Choose file...",
es: "Seleccionar archivo..."
),
button-label: (
en: "Browse",
es: "Navegar"
)
);
文档指出您应该设置文档的语言。例如,设置为:
<html lang="en">
足以让它工作,除非像@masud_moni 的回答一样,你指定了另一种语言然后使用它而不是 "en"。
关于按钮,您可以在 .css 文件中指定语言,它将显示:
.custom-file-control:lang(fr)::before{
content:"PARCOURIR";
}
.custom-file-control:lang(en)::before{
content:"BROWSE";
}
要在 非英语页面 中显示 custom-file-control 的占位符及其按钮标题,您必须将 CSS .custom-file-control:before
和 .custom-file-control:empty::after
与此代码段相同。
此时,open issue 可以在选择后获取自定义控件内的文件名...您可以应用此处显示的 onchange
事件解决方法。
/* Valid for any language */
.custom-file-control:before {
content: "Search";
}
.custom-file-control:empty::after {
content: "Choose a file...";
}
/* Specific for spanish language */
.custom-file-control:lang(es)::before {
content : "Buscar";
}
.custom-file-control:lang(es):empty::after {
content : "Seleccionar un fichero...";
}
<!DOCTYPE html>
<html lang="es-es">
<head>
<title>Test custom-file-control</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
</head>
<body>
<div class="mt-5 ml-5">
<label class="custom-file">
<input type="file" id="file" class="custom-file-input" onchange="$(this).next().after().text($(this).val().split('\').slice(-1)[0])" required>
<span class="custom-file-control"></span>
</label>
</div>
</body>
</html>
我遇到了同样的问题,来这里解决,没有找到,所以我继续挖掘:正确的做法是div of class custom-file 以及其中的输入和标签,而不是标签内的输入。
<div class="custom-file">
<input type="file" id="Image" class="custom-file-input">
<label class="custom-file" for="Image">Select file to upload</label>
</div>
当我在 bootstrap 4 中使用自定义输入文件时,不更改我的输入并且不显示 browse
按钮。
<label class="custom-file">
<input type="file" id="Image" class="custom-file-input">
<span class="custom-file-control"></span>
</label>
.自定义文件
position: relative;
display: inline-block;
max-width: 100%;
height: 2.5rem;
cursor: pointer;
.自定义文件输入
min-width: 14rem;
max-width: 100%;
margin: 0;
filter: alpha(opacity=0);
opacity: 0;
.自定义文件控制
position: absolute;
top: 0;
left: 0;
right: 0;
z-index: 5;
height: 2.5rem;
padding: .5rem 1rem;
line-height: 1.5;
color: #555;
user-select: none;
background-color: #fff;
border: 1px solid #ddd;
border-radius: .25rem;
据我检查 - 您需要插入 :before 和 :after 伪元素 - 然后就可以了。
.custom-file-control:before{
content: "Browse";
}
.custom-file-control:after{
content: "Add files..";
}
尝试使用以下代码。希望它能解决你的问题。它在 Bootstrap 页面的代码示例下方给出。
$custom-file-text: (
placeholder: (
en: "Choose file...",
es: "Seleccionar archivo..."
),
button-label: (
en: "Browse",
es: "Navegar"
)
);
文档指出您应该设置文档的语言。例如,设置为:
<html lang="en">
足以让它工作,除非像@masud_moni 的回答一样,你指定了另一种语言然后使用它而不是 "en"。
关于按钮,您可以在 .css 文件中指定语言,它将显示:
.custom-file-control:lang(fr)::before{
content:"PARCOURIR";
}
.custom-file-control:lang(en)::before{
content:"BROWSE";
}
要在 非英语页面 中显示 custom-file-control 的占位符及其按钮标题,您必须将 CSS .custom-file-control:before
和 .custom-file-control:empty::after
与此代码段相同。
此时,open issue 可以在选择后获取自定义控件内的文件名...您可以应用此处显示的 onchange
事件解决方法。
/* Valid for any language */
.custom-file-control:before {
content: "Search";
}
.custom-file-control:empty::after {
content: "Choose a file...";
}
/* Specific for spanish language */
.custom-file-control:lang(es)::before {
content : "Buscar";
}
.custom-file-control:lang(es):empty::after {
content : "Seleccionar un fichero...";
}
<!DOCTYPE html>
<html lang="es-es">
<head>
<title>Test custom-file-control</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
</head>
<body>
<div class="mt-5 ml-5">
<label class="custom-file">
<input type="file" id="file" class="custom-file-input" onchange="$(this).next().after().text($(this).val().split('\').slice(-1)[0])" required>
<span class="custom-file-control"></span>
</label>
</div>
</body>
</html>
我遇到了同样的问题,来这里解决,没有找到,所以我继续挖掘:正确的做法是div of class custom-file 以及其中的输入和标签,而不是标签内的输入。
<div class="custom-file">
<input type="file" id="Image" class="custom-file-input">
<label class="custom-file" for="Image">Select file to upload</label>
</div>