Menu
CoddyTech

关于部分

本课属于 Coddy HTML 学习旅程的“使用 CSS 添加样式”单元。第 69 课,共 76 课。

challenge icon

挑战

简单

接下来,我们将使用流式布局和灵活的图像来设置 About 单元的样式,确保它在各种屏幕尺寸下都能呈现良好效果。

你的任务是为 class 为 about 的单元应用流式布局技巧和灵活的图像,让它具有响应式效果。请按以下步骤操作:

1. 设置单元容器的样式

  1. 编写一条 CSS 规则,选择 class 为 about 的 <section> 元素。
  2. 添加内边距,为内部留出空间。
  3. 设置 max-width,防止单元变得过宽。

2. 设置文本样式

  1. 编写一条 CSS 规则,选择 h2 元素并设置其颜色。
  2. 编写一条 CSS 规则,选择 p 元素并设置易于阅读的文本颜色。

3. 设置图像样式

  1. 编写一条 CSS 规则,选择 img 元素。
  2. 将其 width 设置为 40vw,让图像具有响应式效果。
  3. 使用 float: right; 将图像放在文本旁边。
  4. 添加 10px 的外边距,为图像周围留出间距。

亲手试试

<html>
    <head>
        <title>Swim with Whales in Tonga</title>
        <link rel="stylesheet" href="styles.css">  
    </head>
    <body>
        <nav class="menu">
            <a href="#">About</a>
            <a href="#">Experience</a>
            <a href="#">Contact</a>
        </nav>    
        <header class="welcome">
            <h1>Swim with Whales in Tonga</h1>
            <p>Experience the magic of swimming alongside majestic humpback whales.</p>
        </header>    
        <section class="about">
            <h2>About Tonga</h2>
            <img src="https://upload.wikimedia.org/wikipedia/commons/8/88/Hawaiian_Islands_Humpback_Whale_National_Marine_Sanctuary_breaching_2018.png">
            <p>Tonga is a stunning Polynesian archipelago in the South Pacific, famous for its crystal-clear waters and vibrant marine life. From July to October, humpback whales migrate here to breed, offering a rare chance to swim with these gentle giants. Beyond whale encounters, Tonga boasts pristine beaches, lush tropical landscapes, and a rich cultural heritage. Visitors can explore traditional villages, experience authentic Tongan hospitality, and enjoy activities like snorkeling, diving, and sailing. Whether you're seeking adventure or relaxation, Tonga provides an unforgettable escape into nature’s beauty.</p>
            </section>      
        <section class="contact">
            <h2>Plan Your Adventure</h2>
            <table>
                <tr>
                    <td>Phone Number</td>
                    <td>+676 123 4567</td>
                </tr>
                <tr>
                    <td>Email</td>
                    <td>info@tongawhales.com</td>
                </tr>
            </table>
    </section>
</body>
</html>

使用 CSS 添加样式中的所有课

自己练习: Web 在线编辑器