Home Web Front-end CSS Tutorial CSS photo album

CSS photo album

Feb 24, 2017 pm 01:13 PM

I have been studying JavaScript recently, and CSS is a bit unfamiliar. It’s time to get something to practice your hands on.

<dl>
  <dt>
    <a href="#index6">6</a><a href="#index5">5</a><a href="#index4">4</a><a href="#index3">3</a><a href="#index2">2</a><a href="#index1">1</a>
  </dt>
  <dd>
    <img id="index1" src="https://img.php.cn/upload/article/000/000/013/4bf6ad50455219fb4dbd78e1710b7b78-0.jpg" />
    <img id="index2" src="https://img.php.cn/upload/article/000/000/013/4bf6ad50455219fb4dbd78e1710b7b78-1.jpg" />
    <img id="index3" src="https://img.php.cn/upload/article/000/000/013/4bf6ad50455219fb4dbd78e1710b7b78-2.jpg" />
    <img id="index4" src="https://img.php.cn/upload/article/000/000/013/4bf6ad50455219fb4dbd78e1710b7b78-3.jpg" />
    <img id="index5" src="https://img.php.cn/upload/article/000/000/013/4bf6ad50455219fb4dbd78e1710b7b78-4.jpg" />
    <img id="index6" src="https://img.php.cn/upload/article/000/000/013/e3e768bc0ad403b7acd7b90162e40116-5.jpg" />
  </dd>
</dl>
Copy after login

Please forgive me for being stingy. Since Google Photos has been blocked, the space in the Blog Park photo album is really tight. The above structure is very fixed, and everyone can just memorize it by rote. It will be easier if you have ideals in the future. Those who are familiar with it will recognize at a glance that anchor points need to be used. If you don’t know what an anchor point is, please google it. The numbers in dt are a bit strange. They are written upside down. You will understand soon.

People who often visit my blog may notice that the HTML code of my run box is very concise and strange, and it is very different from the web page template generated by Dreamweave. Don’t worry, this is HTML5 code that has passed verification. It doesn’t matter if there are html, head, body and other tags.

Let me first describe to you what the photo album will look like in the future. The album will be about the same size as one of these images because we're going to create a page-turning effect. It has a border, which is implemented using dl's border without even thinking about it. It has a page turning bar, implemented by dt. The image display interface is implemented by dd. We can use absolute positioning to place the page turning bar below the image. The picture display interface only displays one picture at a time, and we can use overflow:hidden to hide the multi-point parts. In this way, the size of the album (excluding the border) is the size of the picture plus the page turning bar. Now each picture is 160 x 120, and I set the page turning bar to 160 x 24 (the same width). In other words, the width of dl is 160px and the height is 142px (we need to ensure that the album is rectangular, which is in line with our common sense in life. ) We'd better also set a 2px wide black border on the image, because we have fixed the size of the image and hide the excess part. In other words, the right and bottom sides will be hidden by then. When combined with the original large frame, it has a very three-dimensional effect, as if the picture is embedded in the album with a piece of glass outside. Okay, that’s all for now. Let’s talk about it later after the buttons in the page turning bar are pinned. All of them are float:right.

  dl {/*相册*/
    position:relative;
    width:160px;
    height:142px;
    border:10px solid #EFEFDA;/*相册边框*/
  }
  dd {/*相册的内容显示区,包含相片与下面的翻页栏*/
    margin:0;/*去除浏览器的默认设置*/
    padding:0;/*去除浏览器的默认设置*/
    width:160px;
    height:120px;
    overflow:hidden;/*重点,让每次只显示一张图片*/
  }
  img {
    border:2px solid #000;/*增加立体感*/
  }
  dt {/*翻页栏*/
    position:absolute;
    right:0px;
    bottom:0px;
    /*上面三步是用于把它固定于图片下方*/
    width:160px;
    height:22px;
    background:#FBFBEA;
  }
  a {
     float:right;
  }
Copy after login

Oh my god, I found that we are so efficient in doing things. The photo album is organized in one go, and you can switch pictures by clicking on the link. Do you understand why you can switch pictures? ! If we do not set overflow:hidden, the web page will actually move up and down when clicking on the image, which we can observe through the scroll bar on the right. What does this mean? It means that the scrollTop of javascript has taken effect. scrollTop is usually zero. When it is a positive number, things in the original visual area are shifted downwards. What if we fix the visual area and don't display the scroll bar? ! How can the things below be displayed above? ? The answer is obvious, scrollTop becomes a negative number at this time. Test it yourself, the logic is like this.

Let's look at the links again. Float:right has a side effect, which is to make the leftmost one run to the right of the right ones, so our numbers have to be written backwards. The final finishing part is very simple, just implement it as you would to implement the ul horizontal menu. To make it look better, we add translucency and suspension effects.

 a {
    display:block;/*让其拥有盒子模型*/
    float:right;
    margin:2px;/*错开格子*/
    width:18px;/*呈正方形*/
    height:18px;
    text-align:center;/*居中显示*/
    color:#fff;/*默认是蓝色,所以一定要重写*/
    text-decoration:none;/*消除下划线*/
    background:#666;
    filter:alpha(opacity=70);
    opacity:.7;
  }
  a:hover {
    background:#000
  }
Copy after login

The finished product is very nice and elegant, except that the page turning bar is a bit big due to the small picture. Because Firefox has some problems with the mechanism for opening new windows, when we click on a link, it runs back to the original page to find the corresponding anchor point, instead of the anchor point on the local window. But don’t worry, when you make a photo album, you definitely won’t make it in the running box.

  • 654321

  • CSS相册 CSS相册 CSS相册 CSS相册 CSS相册 CSS相册

#Now all are compatible except for Tiansha's opera.

For more CSS photo album related articles, please pay attention to the PHP Chinese website!


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Vue 3 Vue 3 Apr 02, 2025 pm 06:32 PM

It&#039;s out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

Can you get valid CSS property values from the browser? Can you get valid CSS property values from the browser? Apr 02, 2025 pm 06:17 PM

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That&#039;s like this.

A bit on ci/cd A bit on ci/cd Apr 02, 2025 pm 06:21 PM

I&#039;d say "website" fits better than "mobile app" but I like this framing from Max Lynch:

Stacked Cards with Sticky Positioning and a Dash of Sass Stacked Cards with Sticky Positioning and a Dash of Sass Apr 03, 2025 am 10:30 AM

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

Using Markdown and Localization in the WordPress Block Editor Using Markdown and Localization in the WordPress Block Editor Apr 02, 2025 am 04:27 AM

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

Comparing Browsers for Responsive Design Comparing Browsers for Responsive Design Apr 02, 2025 pm 06:25 PM

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Apr 05, 2025 pm 05:51 PM

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...

How to Use CSS Grid for Sticky Headers and Footers How to Use CSS Grid for Sticky Headers and Footers Apr 02, 2025 pm 06:29 PM

CSS Grid is a collection of properties designed to make layout easier than it’s ever been. Like anything, there&#039;s a bit of a learning curve, but Grid is

See all articles