【发布时间】:2015-08-04 15:18:53
【问题描述】:
我有一个需要放置在输入框内的清晰按钮。
主要问题是表单的方向会根据屏幕尺寸不断变化。
Link to DEMO2 (vanburenx's answer)
我阅读了以下问题,但所有问题的形式都是水平的或垂直的。 1234
代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
<link rel="stylesheet"
href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-social/4.2.1/bootstrap-social.css">
<style>
.top-container {
width: 76%;
float: left;
height: 100%;
padding-right: 45px;
}
.links a, .login button, .login input{
display: inline-block
}
.login-form-input {
width: 100%;
height: 40px;
border: 1px solid #000;
-webkit-box-shadow: none;
box-shadow: none;
margin-bottom: 10px;
margin-left: 3px;
}
@media only screen and (max-width:600px) {
.login input {
width: 100%
}
}
@media ( min-width :601px) and ( max-width :767px) {
.login input {
width: 44%
}
}
@media ( min-width :768px) and ( max-width :900px) {
.login input {
width: 49%;
}
}
@media ( min-width :1200px){
.login input {
width: 45%;
}
}
.searchclear {
position:absolute;
right:5px;
top:0;
bottom:0;
height:14px;
margin:auto;
font-size:14px;
cursor:pointer;
color:red;
}
</style>
</head>
<body>
<header>
<div class="top">
<div class="top-container">
<div class="login">
<form id="myForm" role="form" action="#" method="GET">
<input id="input1" name="input1"
class="form-control login-form-input searchinput" type="text" value="">
<span class="searchclear glyphicon glyphicon-remove-circle" style="display:block"></span>
<input id="input2" name="input2" class="form-control login-form-input searchinput"
type="text" value="">
<span class="searchclear glyphicon glyphicon-remove-circle" style="display:block"></span>
<button class="submit-button" type="submit" title="Submit">
<div>Submit
</div>
</button>
</form>
</div>
</div>
</div>
</header>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
$(document).ready(function () {
$(".searchinput").keyup(function () {
$(this).next().toggle(Boolean($(this).val()));
});
$(".searchclear").toggle(Boolean($(".searchinput").val()));
$(".searchclear").click(function () {
$(this).prev().val('').focus();
$(this).hide();
});
});
</script>
</body>
</html>
【问题讨论】:
-
你知道,如果你向我们展示你想要它的样子,我们会更容易提供帮助,并为你现在拥有的东西创建一个 jsfiddle,我们可以通过这种方式更快地帮助你。粘贴整个代码会使这种方式变得比需要的更难
-
@AbdulAhmad 感谢您的建议我没有 JSFiddle 将在创建时更新问题。
-
@AbdulAhmad 演示包括在内。
标签: jquery twitter-bootstrap css twitter-bootstrap-3