我有一个HTML表单。我希望第一个标签询问一个问题,单选按钮列表以及相应的标签出现在一行中。第二个标签询问一个问题和带有相应标签的复选框列表以单行显示。我在下面发布了我的代码。告诉我我需要添加什么以及如何在CSS中使用样式。
.jumbotron{
position:relative;
background : #000 url(background.jpg) center center;
background-size: cover;
overflow:hidden;
margin-bottom:0px;
}
.box{
position:relative;
background-color:#5DBCD2;
width:90%;
margin-top:0.5%;
height:98.5%;
margin-bottom:1%;
margin-left:5%;
margin-right:5%;
}
.navbar{
min-height: 60px;
margin-bottom:0px;
}
.navbar-inverse{
background-color:#00FF00;
border-color:#00FF00;
font-size:150%;
font-weight:bold;
}
.navbar-inverse .navbar-nav>li>a {
color:#000000;
}
.navbar-inverse .navbar-brand {
color: #ff0000;
font-weight: bold;
font-size:150%;
}
.navbar-inverse .navbar-nav>.active>a, .navbar-inverse .navbar-nav>.active>a:focus, .navbar-inverse .navbar-nav>.active>a:hover{
background-color:#800080;
}
#index .navbar-inverse>.container-fluid>.navbar-collapse>.navbar-nav>.index, #experience .navbar-inverse>.container-fluid>.navbar-collapse>.navbar-nav>.experience, #video .navbar-inverse>.container-fluid>.navbar-collapse>.navbar-nav>.video ,#hkust .navbar-inverse>.container-fluid>.navbar-collapse>.navbar-nav>.hkust ,#feedback .navbar-inverse>.container-fluid>.navbar-collapse>.navbar-nav>.feedback
{
background-color:#ff69b4;
}
.text
{
padding-top:0.5%;
padding-bottom:0.5%;
text-align: center;
}
.form
{
border-radius: 25px;
background-color:#f4f9a6;
margin-left:5%;
margin-right:5%;
width:90%;
height:80%;
margin-top:0.5%;
margin-bottom:1%;
padding-left:10%;
padding-right:10%;
padding-top:10px;
padding-bottom:20px;
}
input[type="text"] {
width: 70%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<b class="navbar-brand">Vivek's Site</b>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="index"><a href="index.html">Home</a></li>
<li class="experience"><a href="experience.html">Experience</a></li>
<li class="video"><a href="videos.html">Videos</a></li>
<li class="hkust"><a href="hkust.html">HKUST Life</a></li>
<li class="feedback"><a href="feedback.html">Feedback</a></li>
</ul>
</div>
</div>
</nav>
<div class="jumbotron">
<div class="box">
<div class="text">
<h1><u>Feedback Form</u></h1>
</div>
<div class="form">
<form class="form-horizontal" role="form">
<div class="form-group">
<label class="control-label col-sm-2" for="email">Name:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" placeholder="Enter name">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="position">Position:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="position" placeholder="Enter position">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="organization">Organization:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="organization" placeholder="Enter organization">
</div>
</div>
<div class="align1">
<div class="form-group">
<label class="control-label col-sm-2" for="rate">Please rate the site:</label>
<div class="col-sm-offset-2 col-sm-10">
<div class="radio">
<label><input type="radio" name="optradio1">Excellent</label>
</div>
<div class="radio">
<label><input type="radio" name="optradio2">Very Good</label>
</div>
<div class="radio">
<label><input type="radio" name="optradio3" >Good</label>
</div>
<div class="radio">
<label><input type="radio" name="optradio4">Fair</label>
</div>
<div class="radio">
<label><input type="radio" name="optradio5">Poor</label>
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="part">Best Part of Site :</label>
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label><input type="checkbox" value="home">Home</label>
</div>
<div class="checkbox">
<label><input type="checkbox" value="experience">Experience</label>
</div>
<div class="checkbox ">
<label><input type="checkbox" value="video">Videos</label>
</div>
<div class="checkbox ">
<label><input type="checkbox" value="hkust">HKUST Life</label>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="part">Best Aspect of Site :</label>
<select class="form-control" id="sel1">
<option>Select</option>
<option value="content">Content</option>
<option value="friendly">User-friendliness</option>
<option value="accessible">Accessibility</option>
<option value="interactive">Interactivity</option>
<option value="design">Design</option>
<option value="time">Load Time</option>
<option value="compatible">Browser Compatibility</option>
</select>
</div>
<div class="form-group">
<label for="comment">Comments for improvement: </label>
<textarea class="form-control" rows="5" id="comment"></textarea>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Submit</button>
<button type="reset" class="btn btn-default">Reset</button>
</div>
</div>
</form>
</div>
</div>
</div>
答案 0 :(得分:1)
Namaste vivek,
以下是我在标记中所做的一些更改,而CSS中没有任何更改。它只是你的列结构。
希望它对你有所帮助。您也可以使用复选框执行相同操作!
<div class="form-group">
<label class="control-label col-sm-2" for="rate">Please rate the site:</label>
<div class="col-sm-10">
<div class="radio col-md-2">
<label><input type="radio" name="optradio1">Excellent</label>
</div>
<div class="radio col-md-2">
<label><input type="radio" name="optradio2">Very Good</label>
</div>
<div class="radio col-md-2">
<label><input type="radio" name="optradio3" >Good</label>
</div>
<div class="radio col-md-2">
<label><input type="radio" name="optradio4">Fair</label>
</div>
<div class="radio col-md-2">
<label><input type="radio" name="optradio5">Poor</label>
</div>
</div>
</div>
&#13;
答案 1 :(得分:1)
我不确定我是否理解你,但我为你做了FIDDLE。
这是我添加的CSS:
/* makes all checkboxes and radio buttons stick to each other */
.radio-container, .radio,
.checkbox-container, .checkbox {
display: inline-block;
float: left;
}
.checkbox:last-child, .radio:last-child{
clear: right;
display: block;
}
.control-label {
display: block;
float: none;
}
.label {
display: block;
clear: left;
float: left!important;
}
在你的html中,我在这部分中添加了上面定义的类:
<div class="form-group">
<label class="label control-label col-sm-2" for="rate">Please rate the site:</label>
<div class="radio-container col-sm-offset-2 col-sm-10">
<div class="radio">
<label><input type="radio" name="optradio1">Excellent</label>
</div>
<div class="radio">
<label><input type="radio" name="optradio2">Very Good</label>
</div>
<div class="radio">
<label><input type="radio" name="optradio3" >Good</label>
</div>
<div class="radio">
<label><input type="radio" name="optradio4">Fair</label>
</div>
<div class="radio">
<label><input type="radio" name="optradio5">Poor</label>
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="label control-label col-sm-2" for="part">Best Part of Site :</label>
<div class="checkbox-container col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label><input type="checkbox" value="home">Home</label>
</div>
<div class="checkbox">
<label><input type="checkbox" value="experience">Experience</label>
</div>
<div class="checkbox ">
<label><input type="checkbox" value="video">Videos</label>
</div>
<div class="checkbox ">
<label><input type="checkbox" value="hkust">HKUST Life</label>
</div>
</div>
</div>
<div class="form-group">
<label class="label control-label col-sm-2" for="part">Best Aspect of Site :</label>