2016-09-01 6 views
-2

Я создал левую панель на моей веб-странице. Я хочу добавить еще одну панель, которая выходит с правой стороны на той же странице. скажите, пожалуйста, html, css, а также скрипт для этого. ПОЖАЛУЙСТА, помогите!Правая боковая панель

+2

Пожалуйста, обеспечивают некоторый код человека –

+0

я хочу эту вещь случиться с правой стороны http://www.w3schools.com/howto/tryit .asp? имя_файла = tryhow_js_sidenav_push_opacity – sanchit

ответ

0

function openNav() { 
 
    document.getElementById("mySidenav").style.width = "250px"; 
 
    document.getElementById("main").style.marginRight = "250px"; 
 
    document.body.style.backgroundColor = "rgba(0,0,0,0.4)"; 
 
} 
 

 
function closeNav() { 
 
    document.getElementById("mySidenav").style.width = "0"; 
 
    document.getElementById("main").style.marginRight= "0"; 
 
    document.body.style.backgroundColor = "white"; 
 
}
body { 
 
    font-family: "Lato", sans-serif; 
 
    transition: background-color .5s; 
 
} 
 

 
.sidenav { 
 
    height: 100%; 
 
    width: 0; 
 
    position: fixed; 
 
    z-index: 1; 
 
    top: 0; 
 
    right: 0; 
 
    background-color: #111; 
 
    overflow-x: hidden; 
 
    transition: 0.5s; 
 
    padding-top: 60px; 
 
} 
 

 
.sidenav a { 
 
    padding: 8px 8px 8px 32px; 
 
    text-decoration: none; 
 
    font-size: 25px; 
 
    color: #818181; 
 
    display: block; 
 
    transition: 0.3s 
 
} 
 

 
.sidenav a:hover, .offcanvas a:focus{ 
 
    color: #f1f1f1; 
 
} 
 

 
.sidenav .closebtn { 
 
    position: absolute; 
 
    top: 0; 
 
    right: 25px; 
 
    font-size: 36px; 
 
    margin-left: 50px; 
 
} 
 

 
#main { 
 
    transition: margin-left .5s; 
 
    padding: 16px; 
 
} 
 

 
@media screen and (max-height: 450px) { 
 
    .sidenav {padding-top: 15px;} 
 
    .sidenav a {font-size: 18px;} 
 
}
<div id="mySidenav" class="sidenav"> 
 
    <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a> 
 
    <a href="#">About</a> 
 
    <a href="#">Services</a> 
 
    <a href="#">Clients</a> 
 
    <a href="#">Contact</a> 
 
</div> 
 

 
<div id="main"> 
 
    <h2>Sidenav Push Example</h2> 
 
    <p>Click on the element below to open the side navigation menu, and push this content to the right. Notice that we add a black see-through background-color to body when the sidenav is opened.</p> 
 
    <span style="font-size:30px; position:absolute; right:0px;cursor:pointer" onclick="openNav()">&#9776; open</span> 
 
</div>

+0

, спасибо большое брах! – sanchit

0

Добавить

display:table-cell; 

для обеих панелей. Или сначала добавить

float:left; 

и для второй панели добавить

float:right; 
+0

я хочу эту вещь случиться с правой стороны http://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_sidenav_push_opacity – sanchit

1

.header{ 
 
    width:100%; 
 
    height:100px; 
 
    background:#ff8800; 
 
} 
 
.left{ 
 
    width:50%; 
 
    float:left; 
 
    height:100px; 
 
    background:red; 
 
} 
 
.right{ 
 
    width:50%; 
 
    float:left; 
 
    height:100px; 
 
    background:blue; 
 
} 
 
.bottom{ 
 
clear:both; 
 
width:100%; 
 
    height:100px; 
 
    background:#ff8855; 
 
}
<div class="header">Header</div> 
 
<div class="left">Left Content</div> 
 
<div class="right">Right Content</div> 
 
<div class="bottom">Bottom Content</div>

Try This Is Пример вашего требования.

+0

я хочу эту вещь случиться с правой стороны http://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_sidenav_push_opacity – sanchit

+0

к регистрации После At My Next Ans –

+0

Я Добавлено Отрывок Check После –

0

Сохранить это как index.css

.btn-dark { 
     border-radius: 0; 
     color: #fff; 
     background-color: rgba(0,0,0,0.4); 
    } 

    .btn-dark:hover, 
    .btn-dark:focus, 
    .btn-dark:active { 
     color: #fff; 
     background-color: rgba(0,0,0,0.7); 
    } 

    .btn-light { 
     border-radius: 0; 
     color: #333; 
     background-color: rgb(255,255,255); 
    } 

    .btn-light:hover, 
    .btn-light:focus, 
    .btn-light:active { 
     color: #333; 
     background-color: rgba(255,255,255,0.8); 
    } 

    #sidebar-wrapper { 
     z-index: 1000; 
     position: fixed; 
     right: 0; 
     width: 250px; 
     height: 100%; 
     margin-right: -250px; 
     overflow-y: auto; 
     background: #222; 
     -webkit-transition: all 0.4s ease 0s; 
     -moz-transition: all 0.4s ease 0s; 
     -ms-transition: all 0.4s ease 0s; 
     -o-transition: all 0.4s ease 0s; 
     transition: all 0.4s ease 0s; 
    } 

    .sidebar-nav { 
     position: absolute; 
     top: 0; 
     width: 250px; 
     margin: 0; 
     padding: 0; 
     list-style: none; 
    } 

    .sidebar-nav li { 
     text-indent: 20px; 
     line-height: 40px; 
    } 

    .sidebar-nav li a { 
     display: block; 
     text-decoration: none; 
     color: #999; 
    } 

    .sidebar-nav li a:hover { 
     text-decoration: none; 
     color: #fff; 
     background: rgba(255,255,255,0.2); 
    } 

    .sidebar-nav li a:active, 
    .sidebar-nav li a:focus { 
     text-decoration: none; 
    } 

    .sidebar-nav > .sidebar-brand { 
     height: 55px; 
     font-size: 18px; 
     line-height: 55px; 
    } 

    .sidebar-nav > .sidebar-brand a { 
     color: #999; 
    } 

    .sidebar-nav > .sidebar-brand a:hover { 
     color: #fff; 
     background: none; 
    } 

    #menu-toggle { 
     z-index: 1; 
     position: fixed; 
     top: 0; 
     right: 0; 
    } 

    #sidebar-wrapper.active { 
     right: 250px; 
     width: 250px; 
     -webkit-transition: all 0.4s ease 0s; 
     -moz-transition: all 0.4s ease 0s; 
     -ms-transition: all 0.4s ease 0s; 
     -o-transition: all 0.4s ease 0s; 
     transition: all 0.4s ease 0s; 
    } 

    .toggle { 
     margin: 5px 5px 0 0; 
    } 

Это HTML документ. Сохраните это как index.html.

<link href="index.css" rel="styleshet"> 
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> 

    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 

    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
    <a id="menu-toggle" href="#" class="btn btn-dark btn-lg toggle"><i class="material-icons">menu</i></a> 
    <nav id="sidebar-wrapper"> 
     <ul class="sidebar-nav"> 
      <a id="menu-close" href="#" class="btn btn-light btn-lg pull-right toggle"><i class="material-icons">close</i></a> 
      <li> 
       <a onclick=$("#menu-close").click();>Item</a> 
      </li> 
      <li> 
       <a onclick=$("#menu-close").click();>Item</a> 
      </li> 
      <li> 
       <a onclick=$("#menu-close").click();>Item</a> 
      </li> 
     </ul> 
    </nav> 

    <script> 
    // Closes the sidebar menu 
    $("#menu-close").click(function(e) { 
     e.preventDefault(); 
     $("#sidebar-wrapper").toggleClass("active"); 
    }); 

    // Opens the sidebar menu 
    $("#menu-toggle").click(function(e) { 
     e.preventDefault(); 
     $("#sidebar-wrapper").toggleClass("active"); 
    }); 
    </script> 
</body> 
</html> 
+0

я хочу эту вещь случиться с правой стороны HTTP://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_sidenav_push_opacity – sanchit

+0

, пожалуйста, отправьте фрагмент кода – sanchit

0

function openNav() { 
 
    document.getElementById("mySidenav").style.width = "250px"; 
 
    document.getElementById("main").style.marginLeft = "250px"; 
 
    document.body.style.backgroundColor = "rgba(0,0,0,0.4)"; 
 
} 
 

 
function closeNav() { 
 
    document.getElementById("mySidenav").style.width = "0"; 
 
    document.getElementById("main").style.marginLeft= "0"; 
 
    document.body.style.backgroundColor = "white"; 
 
}
body { 
 
    font-family: "Lato", sans-serif; 
 
    transition: background-color .5s; 
 
} 
 

 
.sidenav { 
 
    height: 100%; 
 
    width: 0; 
 
    position: fixed; 
 
    z-index: 1; 
 
    top: 0; 
 
    right: 0; 
 
    background-color: #111; 
 
    overflow-x: hidden; 
 
    transition: 0.5s; 
 
    padding-top: 60px; 
 
} 
 

 
.sidenav a { 
 
    padding: 8px 8px 8px 32px; 
 
    text-decoration: none; 
 
    font-size: 25px; 
 
    color: #818181; 
 
    display: block; 
 
    transition: 0.3s 
 
} 
 

 
.sidenav a:hover, .offcanvas a:focus{ 
 
    color: #f1f1f1; 
 
} 
 

 
.sidenav .closebtn { 
 
    position: absolute; 
 
    top: 0; 
 
    right: 25px; 
 
    font-size: 36px; 
 
    margin-left: 50px; 
 
} 
 

 
#main { 
 
    transition: margin-left .5s; 
 
    padding: 16px; 
 
} 
 

 
@media screen and (max-height: 450px) { 
 
    .sidenav {padding-top: 15px;} 
 
    .sidenav a {font-size: 18px;} 
 
}
<div id="mySidenav" class="sidenav"> 
 
    <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a> 
 
    <a href="#">About</a> 
 
    <a href="#">Services</a> 
 
    <a href="#">Clients</a> 
 
    <a href="#">Contact</a> 
 
</div> 
 

 
<div id="main"> 
 
    <h2>Sidenav Push Example</h2> 
 
    <p>Click on the element below to open the side navigation menu, and push this content to the right. Notice that we add a black see-through background-color to body when the sidenav is opened.</p> 
 
    <span style="font-size:30px; position:absolute; right:0px;cursor:pointer" onclick="openNav()">&#9776; open</span> 
 
</div>

+0

, как только я нажму кнопку «Открыть панель кнопок», но текст фона по-прежнему перемещается вправо ... пусть он также перемещается в том же направлении, что и панель – sanchit

+0

k Я пытаюсь исправить –

+0

Check My Next Snippet –

0

Изменение MarginLeft Для MarginRight В скрипте

function openNav() { 
 
     document.getElementById("mySidenav").style.width = "250px"; 
 
     document.getElementById("main").style.marginRight = "250px"; 
 
     document.body.style.backgroundColor = "rgba(0,0,0,0.4)"; 
 
    } 
 

 
    function closeNav() { 
 
     document.getElementById("mySidenav").style.width = "0"; 
 
     document.getElementById("main").style.marginLeft= "0"; 
 
     document.body.style.backgroundColor = "white"; 
 
    }
body { 
 
     font-family: "Lato", sans-serif; 
 
     transition: background-color .5s; 
 
    } 
 

 
    .sidenav { 
 
     height: 100%; 
 
     width: 0; 
 
     position: fixed; 
 
     z-index: 1; 
 
     top: 0; 
 
     right: 0; 
 
     background-color: #111; 
 
     overflow-x: hidden; 
 
     transition: 0.5s; 
 
     padding-top: 60px; 
 
    } 
 

 
    .sidenav a { 
 
     padding: 8px 8px 8px 32px; 
 
     text-decoration: none; 
 
     font-size: 25px; 
 
     color: #818181; 
 
     display: block; 
 
     transition: 0.3s 
 
    } 
 

 
    .sidenav a:hover, .offcanvas a:focus{ 
 
     color: #f1f1f1; 
 
    } 
 

 
    .sidenav .closebtn { 
 
     position: absolute; 
 
     top: 0; 
 
     right: 25px; 
 
     font-size: 36px; 
 
     margin-left: 50px; 
 
    } 
 

 
    #main { 
 
     transition: margin-left .5s; 
 
     padding: 16px; 
 
    } 
 

 
    @media screen and (max-height: 450px) { 
 
     .sidenav {padding-top: 15px;} 
 
     .sidenav a {font-size: 18px;} 
 
    }
<div id="mySidenav" class="sidenav"> 
 
     <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a> 
 
     <a href="#">About</a> 
 
     <a href="#">Services</a> 
 
     <a href="#">Clients</a> 
 
     <a href="#">Contact</a> 
 
    </div> 
 

 
    <div id="main"> 
 
     <h2>Sidenav Push Example</h2> 
 
     <p>Click on the element below to open the side navigation menu, and push this content to the right. Notice that we add a black see-through background-color to body when the sidenav is opened.</p> 
 
     <span style="font-size:30px; position:absolute; right:0px;cursor:pointer" onclick="openNav()">&#9776; open</span> 
 
    </div>

+0

Cool..thanks , но текст остается таким же, как после щелчка по открытию один раз.пусть это займет целую страницу (так же, как и до нажатия кнопки «Открыть»), как когда я нажимаю кнопку перекрестки с панели – sanchit

0
//**Add This In Your Script** 
function closeNav() { 
    document.getElementById("mySidenav").style.width = "0"; 
    document.getElementById("main").style.marginRight= "0"; 
    document.body.style.backgroundColor = "white"; 
} 
1
document.getElementById("main").style.marginRight= "0"; 
enter code here 

Добавить этот код На ваш сценарий

Смежные вопросы