【问题标题】:My page isn't being responsive and looks odd in mobile view我的页面没有响应并且在移动视图中看起来很奇怪
【发布时间】:2019-09-24 03:50:17
【问题描述】:

这是有问题的网页:

https://www.sunnyenterprises.biz/del/

在浏览器中看起来非常好。我在样式表中设置了以像素为单位的 div 高度。但在手机中,它看起来很奇怪。如何修复我的 CSS 以使其在移动设备中也具有响应性?

另外,移动菜单存在问题,它并没有消失,即使我点击了其中的链接,下拉菜单仍然存在。如果您在移动设备上浏览该网站,则可以看到它。

我已尝试调整 DIV 高度,但无法正确调整。另外,我不知道为什么移动菜单不会消失并粘在上面。

这是我的 CSS 代码。

.subtext {
    color:#999999;
    font-size:18px;
    !important
}
html, body{
    margin: 0;
    padding: 0;
    background: #000D28;
}
.navbar-inverse{
    border: none;
    background: rgba(1, 32, 96, 0.93);
}
.navbar-inverse .navbar-toggle{
    border-color: white;
    color: white;
}
.navbar-inverse .navbar-toggle i{
    font-size: 20px;
}
.navbar-inverse .navbar-toggle:hover{
    background: white;
    color: black;
}
.navbar-inverse .navbar-toggle:focus{
    background: white;
    color: black;
}
.navbar-inverse a{
    margin-left: 46px;
}
.navbar-inverse .navbar-brand{
    color: white;
    transition: color 0.5s;
}
.navbar-inverse .navbar-brand:hover{
    color: #F0C12D;
}
.navbar-inverse .navbar-nav>li>a{
    color: white;
    transition: color 0.5s;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
.navbar-inverse .navbar-nav>li>a:hover{
    color: #F0C12D;
}
.container .iphone{
    margin: 0 auto;
    margin-top: 50px;
    width: 900px;
}
.container .margin-div{
    margin-top: 100px;
    background: #000D28;
}
.margin-div h1{
    color:#F0C12D;
    font-size: 60px;
    font-weight: 700;
}
.margin-div a{
    text-align: center;
}
.margin-div p{
    color:white;
    font-size: 30px;
}
.margin-div p>a{
    font-size: 25px;
    margin-left: 10px;
}
.del-rio{
    margin-top: 150px;
    width: 100%;
    height: 950px;
    background: #fff;
}
.shamrath{
    width: 100%;
    height: 950px;
    background: #fff;
}
@media only screen and (max-width: 600px) {
    shamrath {
    height: 400px;
    }
}
.container .margin-div-section{
    margin-top: 100px;
    background: #fff;
}
.margin-div-section h1{
    font-size: 60px;
    font-weight: 700;
}
.margin-div-section a{
    text-align: center;
}
.margin-div-section h2{
    color:#333333;
    font-size: 30px;
    font-weight: 700;
}
.margin-div-section p>a{
    font-size: 25px;
    margin-left: 10px;
}
.margin-div-section .ipad{
    margin: 0 auto;
    margin-top: 50px;
    width: 700px;
}
.silversand{
    width: 100%;
    height: 880px;
    background: #121117;
}
.concrete{
    width: 100%;
    height: 500px;
    background: #121117;
}
.container .margin-div-section-macbook{
    background: #121117;
    margin-top: 100px;
}
.margin-div-section-macbook .macbook{
    margin: 0 auto;
    width: 1500px;
    margin-top: 60px;
}
.margin-div-section-macbook h1{
    font-size: 60px;
    font-weight: 700;
    color: white;
}
.margin-div-section-macbook a{
    text-align: center;
}
.margin-div-section-macbook p{
    font-size: 30px;
    color: white
}
.margin-div-section-macbook p>a{
    font-size: 25px;
    margin-left: 10px;
    color: white;
}
.section-shop{
    width: 100%;
    background: #fff;
    padding: 15px 10px;
}
.img-row{
    margin-top: 20px;
    margin-left: 30px;
}


.carousel-inner {
    margin-bottom:-50px;
}

【问题讨论】:

  • 不清楚你想要什么?但是尝试调试您的代码,我们无法为您完成。附:没有看到菜单汉堡包的任何问题,我看到您的网站有列。

标签: html css mobile responsive


【解决方案1】:

要在代码中使用 jQuery 下方的点击隐藏菜单。

jQuery 代码:

$(document).ready(function(){
  $(".navbar-nav li a").click(function(){
    $("#menu").removeClass("in show");
  });
});

并且,要调整移动屏幕中 div 的高度,您可以尝试下面的 CSS 代码。

CSS 代码:

@media screen and (max-width: 576px){
.silversand, .del-rio, .shamrath {
    height: auto !important;
    padding-bottom: 100px;
}
}

【讨论】:

  • 谢谢。我已经修复了 div 高度问题。我添加了那个 javascript,但菜单仍然不会消失。
  • 我忘了链接到 jquery lib 文件,抱歉。它现在工作得很好。非常感谢。
【解决方案2】:

你错过了.shamrath课程的(.)请在shamrath之前添加(.)

@media (max-width: 600px) {
    .shamrath {
      height: 400px;
    }
}

在 Jquery 下面隐藏菜单使用

$(document).ready(function(){
  $(".navbar-nav li a").click(function(){
    $("#menu").removeClass(".show");
  });
});

【讨论】:

  • 这不会改变任何事情。在移动设备中查看时,“shamrath”部分的内容下方仍有巨大的空白。
  • 对不起,你错过了(。)类 shamrath 更新了我的答案,请检查
  • 哦,等等,我忘记添加 .在 shamrath 之前,将其声明为一个类。
  • 是的,谢谢它现在可以使用。非常感谢。手机菜单呢?点击链接后如何让它消失?
  • 对于菜单,您需要在单击菜单链接时再次调用折叠功能..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-08-12
  • 2016-03-02
  • 1970-01-01
  • 2021-01-26
  • 1970-01-01
  • 1970-01-01
  • 2016-06-18
相关资源
最近更新 更多