CSS. Размер картинки в зависимости от размера родительского компонента
На каждой странице сайта есть <div>-компонент, который имеет свои свойства: длину и ширину.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Указаны в px */ | |
block { | |
height:400 px; | |
width: 400 px; | |
} | |
/* Зависят от родительского компонента и браузер автоматически расчитывает их для браузера с различным разрешением */ | |
block { | |
height: 90%; | |
width: 90%; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Указаны в px */ | |
<div width="400 px" height="400 px"> ... </div> | |
/* Зависят от родительского компонента и браузер автоматически расчитывает их для браузера с различным разрешением */ | |
<div width="90%" height="90%"> ... </div> |
Мы будем использовать второй способ из предыдущих примеров для адаптивного дизайна сайта. Решим следуюшую задачу: необходимо в данный блок вставить любой другой компонент. Это может быть еще один блок <div> или картинка.
К ним добавим следующие параментры:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
height: 90%; | |
width: 90%; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
width="90%" height="90%" |
Соотношение в процентах выбирается в зависмости от требуемого результата.
Мы можем определить свой стиль, который в последствии можем добавить к любому другому элементу страницы. В нашем случае мы создаем новый класс block в файле .css, а затем редактируем файл .html.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="block">...</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
block { | |
height: 90%; | |
width: 90%; | |
} |
Комментарии
Отправить комментарий