[英]Twitter Bootstrap: Unable to make website responsive for smaller device
I am developing a project for school and I am pretty new to Bootstrap and I keep having some problems with scaling the website for different resolutions.我正在为学校开发一个项目,我对 Bootstrap 还很陌生,我在为不同的分辨率缩放网站时一直遇到一些问题。 When I change it to mobile the images go on top of the text.当我将其更改为移动设备时,图像位于文本之上。 If anybody could help me I would appreciate it.如果有人可以帮助我,我将不胜感激。 I have tried everything and still cant find a solution.我已经尝试了一切,但仍然找不到解决方案。
<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 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;
}
First of all, you probably forgot to include <div class="row"></div>
wrapper inside your <div class="container">...</div>
element, just as it says here .首先,您可能忘记在<div class="container">...</div>
元素中包含<div class="row"></div>
包装器,就像这里所说的那样。
Secondly, I strongly recommend you to not play too much with CSS properties such as position: relative
/ absolute
, top: ...; left: ...; right: ...; bottom: ...
其次,我强烈建议您不要过多地使用 CSS 属性,例如position: relative
/ absolute
、 top: ...; left: ...; right: ...; bottom: ...
top: ...; left: ...; right: ...; bottom: ...
top: ...; left: ...; right: ...; bottom: ...
, because most of them break the CSS native document flow and they should be used only when other tools do not help much. top: ...; left: ...; right: ...; bottom: ...
,因为它们中的大多数破坏了 CSS 原生文档流,只有在其他工具没有多大帮助时才应该使用它们。
I suggest you reading this series of articles if you have enough time: CSS layout如果你有足够的时间,我建议你阅读这一系列文章: CSS 布局
I turned off most of the properties of that kind and it already looks much nicer:我关闭了大多数此类属性,它看起来已经好多了:
This answer would be just be a massive advice if I wouldn't provide some code help, so here it is.如果我不提供一些代码帮助,这个答案将只是一个巨大的建议,所以就在这里。
Start by disabling these properties in DevTools:首先在 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%; */
}
Fixing Bootstrap markup:修复 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>
Then you would get this picture (no interval between image and the button on the top):然后你会得到这张图片(图片和顶部按钮之间没有间隔):
This one is solved by applying margin-top: ...px;
这个是通过应用margin-top: ...px;
解决的margin-top: ...px;
to the image block, wrapped in @media
query at .col-md-*
resolutions and lower.到图像块,以.col-md-*
分辨率和更低的分辨率包装在@media
查询中。 For the exact values see Bootstrap grid options .有关确切值,请参阅Bootstrap 网格选项。 For more info on applying @media
queries see MDN docs有关应用@media
查询的更多信息,请参阅MDN 文档
As for navigation bar, I first suggest you disabling padding-left
on ul#menu
element:至于导航栏,我首先建议您在ul#menu
元素上禁用padding-left
:
#menu {
padding-left: 0;
}
Although it fixes it on sm
resolutions, the navigation menu still wraps under the logo on resolutions less than about 520px
.尽管它在sm
分辨率下修复了它,但导航菜单仍然在分辨率小于520px
包裹在徽标下。 I suggest you imagine what to do with this occasion in your mind or in some markup service like https://app.diagrams.net/ and then develop what you decided to.我建议您在脑海中或在诸如https://app.diagrams.net/ 之类的标记服务中想象如何处理这种情况,然后开发您决定的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.