I'm trying to make a bar with text and image appear at the click of a button (as if it were a notification), this bar will grow until reaching the maximum size and revealing the content, however while the animation happens the text goes re-positioning, I would like it to stay in place and only the bar move.
<!DOCTYPE html>
<html>
<head>
<style>
.notificacao {
width: 0px;
height: 100px;
background: whitesmoke;
display: flex;
overflow: hidden;
-webkit-transition: width 2s;
transition: width 2s;
}
.show {
width: 450px;
}
.avatar img {
width: 70px;
height: 70px;
margin: 20px;
}
.text {
margin: 5px 20px;
}
</style>
</head>
<body>
<div class="notificacao">
<div class="avatar">
<img src="https://cdn.icon-icons.com/icons2/1147/PNG/512/1486486303-alert-bell-notification-education-christmas-bell-church-bell-ring_81235.png"></div><divclass="text">
<p><strong>Chamando Notificação</strong></p>
<p>Recebeu uma notificação de determinada pessoa - <strong>NOME DA PESSOA</strong></p>
</div>
</div>
<br><br>
<button>Notificação</button>
<script type="text/javascript">
let notificacao = document.querySelector('.notificacao');
document.querySelector('button').addEventListener('click', function(){
notificacao.classList.add('show');
});
</script>
</body>
</html>
I've tried adding white-space: nowrap.
.text {
white-space: nowrap;
margin: 5px 20px;
}
It even works as I wanted it to, but if the text is too large (greater than the width of the bar) it will be hidden by the overflow: hidden property.
<!DOCTYPE html>
<html>
<head>
<style>
.notificacao {
width: 0px;
height: 100px;
background: whitesmoke;
display: flex;
overflow: hidden;
-webkit-transition: width 2s;
transition: width 2s;
}
.show {
width: 450px;
}
.avatar img {
width: 70px;
height: 70px;
margin: 20px;
}
.text {
white-space: nowrap;
margin: 5px 20px;
}
</style>
</head>
<body>
<div class="notificacao">
<div class="avatar">
<img src="https://cdn.icon-icons.com/icons2/1147/PNG/512/1486486303-alert-bell-notification-education-christmas-bell-church-bell-ring_81235.png"></div><divclass="text">
<p><strong>Chamando Notificação</strong></p>
<p>Recebeu uma notificação de determinada pessoa - <strong>NOME DA PESSOA</strong></p>
</div>
</div>
<br><br>
<button>Notificação</button>
<script type="text/javascript">
let notificacao = document.querySelector('.notificacao');
document.querySelector('button').addEventListener('click', function(){
notificacao.classList.add('show');
});
</script>
</body>
</html>
Does anyone know how to help me solve this?