• Что бы вступить в ряды "Принятый кодер" Вам нужно:
    Написать 10 полезных сообщений или тем и Получить 10 симпатий.
    Для того кто не хочет терять время,может пожертвовать средства для поддержки сервеса, и вступить в ряды VIP на месяц, дополнительная информация в лс.

  • Пользаватели которые будут спамить, уходят в бан без предупреждения. Спам сообщения определяется администрацией и модератором.

  • Гость, Что бы Вы хотели увидеть на нашем Форуме? Изложить свои идеи и пожелания по улучшению форума Вы можете поделиться с нами здесь. ----> Перейдите сюда
  • Все пользователи не прошедшие проверку электронной почты будут заблокированы. Все вопросы с разблокировкой обращайтесь по адресу электронной почте : info@guardianelinks.com . Не пришло сообщение о проверке или о сбросе также сообщите нам.

How to Create an Image Gallery with a Horizontal Scroll Bar using CSS Only

Lomanu4 Оффлайн

Lomanu4

Команда форума
Администратор
Регистрация
1 Мар 2015
Сообщения
1,481
Баллы
155
Image Gallery

How To, for Front End and Web Applications



An image gallery for a webpage is a set of pictures. This tutorial explains How to Create an Image Gallery with a Horizontal Scroll Bar using CSS Only. The images are in a row. There is a horizontal scroll-bar at the bottom of the row, to access images that are not currently visible.

The complete webpage code is at the end of this tutorial. The reader should copy the complete code into a text editor. Save the file with any name, but with the extension, .html . Open the file in the browser. Locate the horizontal scroll bar at the bottom of the row of images. Scroll left and right to see the rest of the pictures. The images are in the website, broad-network.com . So the reader must be hooked up to the Internet before doing this. The reader is advised to do this before carrying on to read the rest of this tutorial.

The Webpage Skeleton Code

The skeleton code for the webpage to which more useful code will be added is:


<!DOCTYPE html>
<html>
<head>
<title>Horizontal Scrollable Image Gallery</title>
<link rel='icon' href='

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

' type='image/x-icon'>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Description of the Web Page.">

<style>

</style>

<script type="text/javascript">
</script>
</head>
<body>

</body>
</html>

Any modern professional webpage should have at least the first four tags in the HTML head element above. The HTML style element will have just two CSS rules. The JavaScript will be left empty. The HTML body element will have the HTML div for the images.

Content of the HTML body Element

The content of the HTML body element is:


<h2>Image Gallery With Horizontal Scroll</h2>
<p>Use the horizontal scrollbar to see the other images.</p>

<div class="scroll-container">
<img src="

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

" alt="Cinque Terre" width="600" height="400">
<img src="

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

" alt="Forest" width="600" height="400">
<img src="

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

" alt="Northern Lights" width="600" height="400">
<img src="

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

" alt="Mountains" width="600" height="400">
</div>

There are four images. They are all in the div with the class-name, "scroll-container".

Content for the HTML Style Element


There are only two CSS rules. They are all within the start and end tags of the HTML style element, in the HTML head element.

Styling the Container div

The CSS rule for the container div is:


div.scroll-container {
white-space: nowrap;
overflow: auto;
background-color: #333;
padding: 10px;
}

The white-space property with value, nowrap, means that if the total width of the images is longer then the width of its container, all the images should be in one row. The property, overflow, with value, auto, means that the browser should decide whether to provide a horizontal scroll bar or not. As soon as the total width of the images is more than the width of the container, the browser will provide a horizontal scroll bar. The background color for the container is #333 (dark gray). The padding for all the sides of the row container div, is 10px.

Styling the Images

Each image is within a rectangle. The gap between the actual image and the border, is called the padding. The CSS rule for each image is:


div.scroll-container img {
padding: 10px;
}

The padding for all the four sides is 10px.

The Complete Webpage Code


And there you have it: the complete webpage code is:


<!DOCTYPE html>
<html>
<head>
<title>Horizontal Scrollable Image Gallery</title>
<link rel='icon' href='

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

' type='image/x-icon'>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Description of the Web Page.">

<style>
div.scroll-container {
white-space: nowrap;
overflow: auto;
background-color: #333;
padding: 10px;
}

div.scroll-container img {
padding: 10px;
}
</style>

<script type="text/javascript">

</script>
</head>
<body>
<h2>Image Gallery With Horizontal Scrolling</h2>
<p>Use the horizontal scrollbar to see the other images.</p>

<div class="scroll-container">
<img src="

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

" alt="Cinque Terre" width="600" height="400">
<img src="

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

" alt="Forest" width="600" height="400">
<img src="

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

" alt="Northern Lights" width="600" height="400">
<img src="

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

" alt="Mountains" width="600" height="400">
</div>
</body>
</html>

The reader should copy the complete code into a text editor. Save the file with any name, but with the extension, .html . Open the file in the browser. Locate the horizontal scroll bar at the bottom of the row of images. Scroll left and right to see the rest of the pictures. The images are in the website, broad-network.com . So the reader must be hooked up to the Internet before doing this.

To read next (click):

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



Chrys


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

 
Вверх Снизу