<div class="box">
<p>У цьому прикладі, Ви можете змінювати величину значення <strong>percent</strong>.</p>
<p><strong>percent</strong> встановлює ширину для елемента на сторінці. Результат дії властивості можна побачити за поведінкою другого блоку.</p>
<strong>width: </strong>
<input type="range" class="input" id="percent" value="100" min="0"> %<strong>;</strong>
</div>
<div class="block">
Моя ширина: <span>100%</span>
</div>
* {
box-sizing: border-box;
}
body {
font-family: monospace;
font-size: 16px;
line-height: 1.45;
height: 100vh;
}
.box {
background-color: #f7f7f7;
padding: 16px;
border: 8px solid #F74C32;
margin-bottom: 24px;
transition: all .15s ease-in;
}
.block {
background-color: fuchsia;
width: 100%;
height: 100px;
padding: 4px;
text-align: center;
font-weight: 700;
transition: height .15s ease-in;
font-size: 18px;
}
.input {
width: 75px;
position: relative;
bottom: -4px;
}
#select {
position: relative;
top: -4px;
width: 100px;
}
$('#percent').on('change', function() {
var num = $(this).val();
$('.block').css( 'width', num + '%' );
$('.block > span').html( num + '%' );
});
This Pen doesn't use any external CSS resources.