我对以下标题的唯一问题是,通过更改屏幕大小,两个按钮与搜索按钮重叠。我需要他们留在原地,在小屏幕上,没有足够的空间让搜索框和按钮在水平线上。两个按钮跳起来。在三个小图像的正下方。
我删除了一些与问题无关的css样式,以简化代码。
<!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>
html, body {
height: 100%;
}
body {
margin: 0;
padding: 0;
}
.show-xs {
display: none;
}
@media ( max-width : 480px) {
.top-center {
width: 100%;
}
.top-right {
padding-bottom: 4px;
}
#logo {
width: 120%;
}
.btn-search {
float: right;
}
.login {
margin-left: 10px;
margin-right: -23px;
}
.show-xs {
display: block;
}
.hide-xs {
display: none;
}
}
body {
margin: 0;
padding: 0;
}
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.top-part {
width: 100%;
background-color: green;
}
.top {
max-width: 1509px;
width: 100%;
height: 100%;
margin: 0 auto;
text-align: center;
position: relative;
}
.top-center {
display: inline-block;
width: 100%;
height: 100%;
}
.top-right {
display: inline-block;
float: right;
height: 100%;
margin-right: 3%; //
width: 200px; //
padding-left: 20px;
}
.left-part {
float: left;
height: 100%;
margin-left: 6%;
margin-top:-0.3%;
width: 7%;
}
.middle-part {
width: 82%;
float: left;
height: 100%;
text-align: left;
}
.logo {
text-align: left;
padding-bottom:3px;
padding-top:7px;
}
.login {
text-align: left;
}
@media only screen and (max-width: 600px) {
.top-center {
width: 100%;
}
}
.left-part img {
width: 100%;
display: block;
padding: 2px;
margin-top: 9px;
}
.logo img { //
height: 40px;
width: 70%;
max-width: 90%;
display: inline-block;
}
.login input, .login button {
display: inline-block;
}
.login input {
width: 44%;
}
@media only screen and (max-width: 600px) {
.login input {
width: 100%;
}
}
.social ul {
list-style: none;
margin: 0;
}
.social li {
height: 30px;
width: 30px;
float: right;
background-color: blue;
margin-left: 4px;
margin-top: 4px;
background-repeat: no-repeat;
background-size: cover;
}
.social li a {
display: inline-block;
width: 100%;
height: 100%;
}
.social1 {
background-image:
url();
}
.social2 {
background-image:
url();
}
.social3 {
background-image:
url();
}
.mybuttons {
margin-top: -63px;
float: right;
padding: 0;
}
.mybuttons a {
display: inline-block;
}
.btn-search {
background-color: green;
border-style: none;
}
.myBtns {
border-style: outset;
color: black;
background-color: green;
border-color: gray;
border-width: 1px;
padding: 2px 7px 3px 13px;
}
.myBtns:hover {
text-decoration: none;
color: white;
cursor: pointer;
}
</style>
</head>
<body>
<header>
<div class="top-part">
<div class="left-part show-xs">
<img
src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR4Aa9iHfxi_6jmKGL8stVsrJ98FBVmy5DK9c6BsGHweaQ5PBoc"
id="logo">
</div>
<div class="logo show-xs">
<img
src="https://pixabay.com/static/uploads/photo/2012/05/07/18/44/banner-48962_640.png">
</div>
<div class="top-right">
<div class="social">
<ul>
<li class="social3"><a href="www.googleplus.com"></a></li>
<li class="social2"><a href="www.twitter.com"></a></li>
<li class="social1"><a href="http://www.facebook.com"></a></li>
</ul>
</div>
</div>
<div class="top">
<div class="top-center">
<div class="left-part hide-xs">
<img id="logo" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR4Aa9iHfxi_6jmKGL8stVsrJ98FBVmy5DK9c6BsGHweaQ5PBoc" />
</div>
<div class="middle-part">
<div class="logo hide-xs">
<img src="https://pixabay.com/static/uploads/photo/2012/05/07/18/44/banner-48962_640.png" />
</div>
<div class="login">
<form>
<input id="searchType" type="hidden" name="searchType"
value="">
<input id="searchTerm" name="searchTerm"
class="form-control myInput" type="text" value="" />
<input id="searchBox2" name="searchBox2" class="form-control myInput"
type="text" value="" />
<button class="btn-search" type="submit" title="Search">
<div style="background-color: green;">
<span class="glyphicon glyphicon-search"
style="font-size: 20px;"></span>
</div>
</button>
</form>
<div id="msg" class="msg">
<p>Message goes here</p></div>
</div>
</div>
<div class="mybuttons">
<a id="Btn1" class="myBtns" >BTN1BTN1</a>
<a id="Btn2" class="myBtns">BTN2BTN2</a>
</div>
</div>
</div>
</div>
</header>
</body>
</html>
答案 0 :(得分:3)
要实现所需的布局,您需要在同一父容器中同时显示.login
表单和.mybuttons
inline-block
。如果您将容器div添加到.login
和.mybuttons
,则可以非常轻松地执行此操作。
这是您更新的fiddle。
<强>解释强>:
在您的标记中,我将两个区域放在.middle-part
div中并添加容器以设置为display: inline-block
。
<div class="middle-part">
...
<div class="login-outer>
<div class="login">
(put your login <form> and <inputs> here)
</div>
</div>
<div class="buttons-outer">
<div class="mybuttons">
<a id="Btn1" class="myBtns" >BTN1BTN1</a>
<a id="Btn2" class="myBtns">BTN2BTN2</a>
</div>
</div>
</div>
然后在你的css中:
// set both containers to inline-block
.login-outer, .buttons-outer
{
position: relative;
display: inline-block;
vertical-align: top;
}
// Specify breakpoint widths. When there isn't enough space
// to display these widths in the same line, they will stack instead.
.login-outer
{
min-width: 500px; // or whatever
}
.buttons-outer
{
min-width: 190px;
}
希望这有帮助!
答案 1 :(得分:0)
请确保使用正确的bootstrap结构。 您可以根据所需的屏幕尺寸使用col-md-12或col-sm-12等。
<div class="row">
<div class="col-md-12">
<div class="mybuttons">
<a id="Btn1" class="myBtns" >BTN1BTN1</a>
<a id="Btn2" class="myBtns">BTN2BTN2</a>
</div>
</div>
您可以在http://getbootstrap.com/getting-started/查找教程 这是学习引导程序的最佳站点。 Bootstrap中的网格系统:http://getbootstrap.com/css/#grid-example-basic
答案 2 :(得分:-1)
你需要删除margin-top:-63px; on .mybuttons停止重叠。
如果您正在使用引导程序,则可以查看推拉以在较小的屏幕尺寸上移动对象。
您还可以重复按钮并显示/隐藏它们,具体取决于您所处的媒体查询大小。
答案 3 :(得分:-2)
您可以通过在html页面中使用以下代码来避免过度流量
<div style="overflow:hidden;">
Your code here
</div>
隐藏溢出