关闭响应式菜单

时间:2015-07-08 10:52:41

标签: html css

我的响应式菜单有问题,我无法弄清楚它在哪里。

很难解释,请访问我的网站http://untruste.altervista.org/home.html

现在调整窗口大小,因为您获得了响应版本,打开菜单并关闭它。

自获得桌面版本后调整窗口大小,因为您可以看到菜单消失了! (如果你刷新页面它会回来)

desktopstyle:

    header {
    padding-bottom: 2%;
    border-radius: 10px;
    width: 70%;
    margin: auto;
}

#headerTitle h1{
    display: block;
}

#headerTitle {
    padding-top: 1%;
    text-align: center;
    line-height: 1.8em;
}

header img {
    display: block;
    margin: 2%;
    width:7em;
}

header h1 {
    width: 80%;
    margin: auto;
    font-size: 1.8em;
    letter-spacing: -0.04em;
}

header h2 {
    width: 50%;
    margin: auto;
    text-align: center;
    font-size: 1.5em;
    letter-spacing: -0.06em;
}

#menu {
    display: block;
    width: 80%;
    margin: auto;
    border:none
}

#menu ul li {
    display: inline-block;
    width:auto;
    margin-left:auto;
    margin-right: auto;
    padding:2px;
    border: none;
    font-size: 0.9em;
}

#selected {
    background: #00715f;
    padding:0 1em;
    color: #ffffff !important;
    border-radius: 10px;
}


article {
    width: 70%;
    padding-top: 1%;
    border-radius: 10px;
    font-size: 0.9em;
}

article a {
    color: #004040
}

article h1 {
    padding: 7px 7px 7px 30px;
    width:auto;
    margin-left: -30px;
    margin-right: 30%;
    text-align: left;
}

article h2 {
    margin-left: -30px;
    margin-right: 60%;
}

.articleText {
    width:70%;
    margin:auto;
}

#linkmap {
    display: none;
}

iframe {
    display: block;
    border: none;
}

footer {
    width:70%;
    margin: auto;
    border-radius: 10px;
    font-size: 0.9em;
    font-family: Times, serif;
}

mobilestyle

body {
}

header {
}

footer {
    font-size: 0.7em;
}

#headerTitle h1{
    display: none;
}

.icon {
    margin-right:10px;
    font-size:2em
}

.icon::after
{
    content:'≡';
}
.icon-close::after
{
    margin-right:10px;
    font-size:2em;
    content:'×';
    font-weight: normal;
    font-style: normal;
}

#headerTitle {
    padding-top: 5px;
}

header img {
    display:none
}

header h1 {
    font-size: 1.4em;
    letter-spacing: -0.04em;

}

header h2 {
    font-size: 1.1em;
}


#menu {
    border-bottom: 1em solid #00715f;
}


#menu ul li {
    display: block;
    height:2em;
    width:100%;
    margin-left:-3.5%;
    font-size:1.2em
}

.menu_button {
    display: block;
    text-decoration: none;
    text-align: right;
    box-shadow:0 1px 1px rgba(0,0,0,0.15);
    background: #00715f;
    color: #ececec;
}

#selected {
    background: #00715f;
    padding:0 5em;
    color: #ffffff !important;
    border-radius: 10px;
}

article {
    width: 100%;
    font-size: 0.8em;
}

article h1 {
    width:100%;
    margin-right: 20%;
    padding:7px 0 7px 0;
    text-align: center;
}

article h2 {
    margin-right: 10%;
}

.articleText {
    width:90%;
    margin:auto
}

#linkmap{
    display: block;
    border: none;
}

iframe {
    display: none;
}

式:

body {
    background:#004040;
    color: #005b4d;
    text-align: center;
    font-family: "Georgia", "Times", serif;
}

a {
    color: #00715f;
}

a:hover {
    font-style: italic;
}

header {
    background: white;
    width: 100%;
    height:auto
}

header h1,h2 {
    display: block;
    font-weight: normal;
}

footer {
    background-color: #ffffff;
    width: 100%;
    padding: 2% 0;
}

#menu ul li {
    list-style: none;
    text-align: center;
}

#menu ul li a {
    text-decoration: none;
    color: #005b4d;
}

article {
    background: white;
    text-align: justify !important;
    padding-bottom: 1%;
    margin: 5% auto;
}

article h1 {
    background: #00715f;
    color: #fff;
    width:100%;
    margin-right: 20%;
    text-shadow: 0 1px 0 #403232;
    font-weight: normal;
    text-align: center;
}

article h2 {
    background: #00715f;
    color:#fff;
    padding: 7px 7px 7px 30px;
    font-weight: normal;
    font-size: 1.2em;
}

这是html

  <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <link rel="stylesheet"  type="text/css" href="css/style.css">
        <link rel="stylesheet" media= "(min-width: 240px) and (max-width:1023px)" type="text/css"
              href="css/mobilestyle.css">
        <link rel="stylesheet" media="(min-width:1024px)" type="text/css" href="css/desktopstyle.css">
        <meta name="viewport" content="width=device-width">
        <link rel="icon" href="favicon.ico">
        <script src="jquery-1.11.3.js" type="text/javascript"></script>
        <script src="script.js"></script>
        <!--[if lt IE 9]>       <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
        <title>ArteLab Responsive</title>
    </head>

    <body>
    <header>
        <img style="float:left" src="logos/artelab.png" alt="logo_artelab">
        <img style="float: right" src="logos/insubria.png" alt="logo_insubria">
        <div id="headerTitle">
            <h1>Applied Recognition Technology Laboratory</h1>
            <h2>Department of Theoretical and Applied Science</h2>
        </div>
        <a class="menu_button"  href="#"><span class="icon">≡</span> </a>
        <div id='menu'>
            <nav>
                <ul>
                    <li><a href="link">LINK1</a></li>
                    <li><a href="link">lINK2</a></li>
                    <li><a href="link">LINK3</a></li>
                    <li><a href="link">LINK4</a></li>
                    <li><a href="link">LINK5</a></li>
                    <li><a id="selected" href="link">LINK6</a></li>
                </ul>
            </nav>
        </div>
    </header>

这是我用来在响应式版本中打开菜单的脚本

jQuery(document).ready(function() {
    $('.menu_button').click(function() {
        $("#menu").slideToggle();
        $(this).find('span').toggleClass('icon icon-close');
    });
});

1 个答案:

答案 0 :(得分:2)

你可以试试这个:

在桌面样式中,只需执行以下操作:

#menu { 
    display: block!important;
}

您的slideToggle()菜单会导致它在样式属性中显示display:none。所以我们只是在桌面上覆盖它。