[英]Twitter Bootstrap: Unable to make website responsive for smaller device
我正在为学校开发一个项目,我对 Bootstrap 还很陌生,我在为不同的分辨率缩放网站时一直遇到一些问题。 当我将其更改为移动设备时,图像位于文本之上。 如果有人可以帮助我,我将不胜感激。 我已经尝试了一切,但仍然找不到解决方案。
<body>
<div class="container">
<nav class="navbar-fixed-top sticky-top navbar" style="width: 100%; background-color: white; box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);">
<div class="navbar-header">
<a class="navbar-brand"><img src="transferir.png" alt="" style="height: 65; width: 60px"></a>
</div>
<div>
<ul id="menu">
<li><a href="#home">Home</a></li>
<li><a href="#sobre">About</a></li>
<li><a href="#features">Features</a></li>
<li><a href="#contact">Contacta-nos</a></li>
</ul>
</div>
</nav>
<div class="site-index">
<div id="home" class="block home-block">
<div class="container">
<div class="col-sm-6 left-block">
<div class="text-centered">
<h1>Texter</h1>
<p class="info-text">Send text messages, voice messages, video messages or video call with all your friends and family easily, quickly and securely.</p>
<p class="Medium-text">Download Em Breve</p>
<a href="https://play.google.com/?hl=pt-PT" target="_blank"><img src="playstore.png" alt="Playstore" class="d-img"></a>
<a href="https://www.apple.com/pt/ios/app-store/" target="_blank"><img src="appstore.png" alt="Apple App Store" class="d-img"></a>
</div>
</div>
<div class="col-sm-5 right-block">
<img src="phones.png" style="height: 350px; float: right; vertical-align: middle; width: auto !important; position: relative">
</div>
</div>
<hr class="sombra">
</div>
</div>
css
html{
scroll-behavior: smooth;
}
body{
padding-top: 1%;
font-family: 'Lato', sans-serif;
}
.block{
padding: 35px;
}
.home-block{
min-height: calc(100vh - 90px);
}
#home .container{
height: 500px;
}
.left-block{
text-align: center;
top: 30%;
}
.right-block{
bottom: 35%;
margin-left: 25%;
}
.container{
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}
首先,您可能忘记在<div class="container">...</div>
元素中包含<div class="row"></div>
包装器,就像这里所说的那样。
其次,我强烈建议您不要过多地使用 CSS 属性,例如position: relative
/ absolute
、 top: ...; left: ...; right: ...; bottom: ...
top: ...; left: ...; right: ...; bottom: ...
top: ...; left: ...; right: ...; bottom: ...
,因为它们中的大多数破坏了 CSS 原生文档流,只有在其他工具没有多大帮助时才应该使用它们。
如果你有足够的时间,我建议你阅读这一系列文章: CSS 布局
我关闭了大多数此类属性,它看起来已经好多了:
如果我不提供一些代码帮助,这个答案将只是一个巨大的建议,所以就在这里。
首先在 DevTools 中禁用这些属性:
.home-block{
/* min-height: calc(100vh - 90px); */
}
#home .container{
/* height: 500px; */
}
.left-block{
/* text-align: center; */
/* top: 30%; */
}
.right-block{
/* bottom: 35%; */
/* margin-left: 25%; */
}
修复 Bootstrap 标记:
<div id="home" class="block home-block">
<div class="container">
<!-- Added this wrapper, changed .col-* classes to responsive -->
<div class="row">
<!-- Removed .left-block class -->
<div class="col-sm-12 col-lg-6 left-block">
<div class="text-centered">
<h1>Texter</h1>
<p class="info-text">Send text messages, voice messages, video messages or video call with all your friends and family easily, quickly and securely.</p>
<p class="Medium-text">Download Em Breve</p>
<a href="https://play.google.com/?hl=pt-PT" target="_blank"><img src="playstore.png" alt="Playstore" style="height: 40px;"></a>
<a href="https://www.apple.com/pt/ios/app-store/" target="_blank"><img src="appstore.png" alt="Apple App Store" style="height: 40px"></a>
</div>
</div>
<!-- Removed .right-block class, added .text-centered class -->
<div class="col-sm-12 col-lg-6 text-centered">
<!-- Removed inline styles (bad practice), changed "height" to be an attribute -->
<img src="phones.png" height="350">
</div>
</div>
</div>
</div>
然后你会得到这张图片(图片和顶部按钮之间没有间隔):
这个是通过应用margin-top: ...px;
解决的margin-top: ...px;
到图像块,以.col-md-*
分辨率和更低的分辨率包装在@media
查询中。 有关确切值,请参阅Bootstrap 网格选项。 有关应用@media
查询的更多信息,请参阅MDN 文档
至于导航栏,我首先建议您在ul#menu
元素上禁用padding-left
:
#menu {
padding-left: 0;
}
尽管它在sm
分辨率下修复了它,但导航菜单仍然在分辨率小于520px
包裹在徽标下。 我建议您在脑海中或在诸如https://app.diagrams.net/ 之类的标记服务中想象如何处理这种情况,然后开发您决定的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.