Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

277
Vistas
sidebar navigation text not smooth while transition

i try to change css but not work for text short text is ok but i have to put long paragraph when click it not smooth while transition working i use template from w3school, i want text show up smooth like button or short text please advise me how I should use it to remember for next time i can help in community if i saw someone ask like me thank you.

/* Set the width of the side navigation to 250px */
function openNav() {
    document.getElementById("mySidenav").style.width = "400px";
}

/* Set the width of the side navigation to 0 */
function closeNav() {
    document.getElementById("mySidenav").style.width = "0";
}
/* The side navigation menu */
.sidenav {
    height: 100%; /* 100% Full-height */
    width: 0; /* 0 width - change this with JavaScript */
    position: fixed; /* Stay in place */
    z-index: 1; /* Stay on top */
    top: 0;
    left: 0;
    background-color: #111; /* Black*/
    overflow-x: hidden; /* Disable horizontal scroll */
    padding-top: 60px; /* Place content 60px from the top */
    transition: 0.5s; /* 0.5 second transition effect to slide in the sidenav */
}

/* The navigation menu links */
.sidenav a {
    padding: 8px 8px 8px 32px;
    text-decoration: none;
    font-size: 25px;
    font-family: Gotham;
    color: #818181;
    display: block;
    transition: 0.3s
}

/* When you mouse over the navigation links, change their color */
.sidenav a:hover, .offcanvas a:focus{
    color: #f1f1f1;
}

/* Position and style the close button (top right corner) */
.sidenav .closebtn {
    position: absolute;
    top: 0;
    right: 25px;
    font-size: 36px;
    margin-left: 50px;
}

/* Style page content - use this if you want to push the page content to the right when you open the side navigation */
#main {
    transition: margin-left .5s;
    padding: 20px;
}

/* On smaller screens, where height is less than 450px, change the style of the sidenav (less padding and a smaller font size) */
@media screen and (max-height: 450px) {
    .sidenav {padding-top: 15px;}
    .sidenav a {font-size: 18px;}
}
<body bgcolor="#E6E6FA">
  <div id="mySidenav" class="sidenav">
  <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
     
    <p style=color:white>TEST TEST TEST TEST TEST TEST TEST TEST
    TEST TEST TEST TEST
    TEST TEST TEST TEST
    TEST TEST TEST TEST
    TEST TEST TEST TEST</p>
 
</div>

<span onclick="openNav()"><img src="https://cdn4.iconfinder.com/data/icons/wirecons-free-vector-icons/32/menu-alt-512.png" width="40px" style="padding-top: 40px; padding-left: 40px;"></span>

<div id="main">
</div>

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

  • You don't need two separate JavaScript functions. Only one called toggleNav
  • Use Element.classList.toggle() to toggle a CSS class
  • Don't animate the width. Use transform: translateX(-100%) to hide the Nav, and translateX(0%) to show (open).
  • Don't use links if you actually want buttons. Links (Anchors) are used to navigate
  • Don't use inline on* JS attributes and style attributes

const toggleNav = () => {
  document.querySelector("#mySidenav").classList.toggle("is-open");
};

document.querySelectorAll(".toggleNav").forEach(el => {
  el.addEventListener("click", toggleNav)
});
/* QuickReset */ * {margin:0; box-sizing: border-box;}

#mySidenav {
  position: relative;
  overflow-x: hidden;
  width: calc(100vw - 200px); /* try not to use fixed px */
  height: 100vh;
  position: fixed;
  z-index: 1;
  top: 0;
  left: 0;
  background-color: #111;
  color: #fff;
  padding: 60px;
  transition: 0.5s;
  transform: translateX(-100%); /* hide it by minus own width */
}

#mySidenav.is-open {
  transform: translateX(0%); /* show it */
}

.toggleNav {
  background: none;
  border: none;
  font-family: Gotham;
  font-size: 2rem;
  padding: 1rem 1.3rem;
  cursor: pointer;
}

.toggleNav:hover {
  color: #999;
}

#mySidenav .toggleNav {
  color: #777;
  top: 0;
  right: 0;
  position: absolute;
}
<div id="mySidenav">
  <button type="button" class="toggleNav">&#x2715;</button>
  <p>
    TEST TEST TEST TEST TEST TEST 
    TEST TEST TEST TEST TEST TEST
    TEST TEST TEST TEST TEST TEST 
    TEST TEST TEST TEST TEST TEST
  </p>
</div>

<button type="button" class="toggleNav">&#x2630;</button>

<div id="main"></div>

about 4 years ago · Juan Pablo Isaza Denunciar

0

If I haven't understood it wrong you want to make text word position won't change then write the following code:

<p id="sidenavText">TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST</p>

Set width on the text too

var sidenavWidth = 400;
document.querySelector("#sidenavText").style.width = sidenavWidth + "px";
function openNav() {
    document.getElementById("mySidenav").style.width = sidenavWidth + "px";
}

function closeNav() {
    document.getElementById("mySidenav").style.width = "0";
}

var sidenavWidth = 400;
document.querySelector("#sidenavText").style.width = sidenavWidth + "px";
function openNav() {
    document.getElementById("mySidenav").style.width = sidenavWidth + "px";
}

function closeNav() {
    document.getElementById("mySidenav").style.width = "0";
}
.sidenav {
    height: 100%; /* 100% Full-height */
    width: 0; /* 0 width - change this with JavaScript */
    position: fixed; /* Stay in place */
    z-index: 1; /* Stay on top */
    top: 0;
    left: 0;
    background-color: #111; /* Black*/
    overflow-x: hidden; /* Disable horizontal scroll */
    padding-top: 60px; /* Place content 60px from the top */
    transition: 0.5s; /* 0.5 second transition effect to slide in the sidenav */
}

/* The navigation menu links */
.sidenav a {
    padding: 8px 8px 8px 32px;
    text-decoration: none;
    font-size: 25px;
    font-family: Gotham;
    color: #818181;
    display: block;
    transition: 0.3s
}

/* When you mouse over the navigation links, change their color */
.sidenav a:hover, .offcanvas a:focus{
    color: #f1f1f1;
}

/* Position and style the close button (top right corner) */
.sidenav .closebtn {
    position: absolute;
    top: 0;
    right: 25px;
    font-size: 36px;
    margin-left: 50px;
}

/* Style page content - use this if you want to push the page content to the right when you open the side navigation */
#main {
    transition: margin-left .5s;
    padding: 20px;
}

/* On smaller screens, where height is less than 450px, change the style of the sidenav (less padding and a smaller font size) */
@media screen and (max-height: 450px) {
    .sidenav {padding-top: 15px;}
    .sidenav a {font-size: 18px;}
}
<body bgcolor="#E6E6FA">
  <div id="mySidenav" class="sidenav">
  <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
     <p id="sidenavText" style="color:white">TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST</p> 
</div>

<span onclick="openNav()"><img src="https://cdn4.iconfinder.com/data/icons/wirecons-free-vector-icons/32/menu-alt-512.png" width="40px" style="padding-top: 40px; padding-left: 40px;"></span>

<div id="main">
</div>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda