92. Responsive and Fixed Navigation Menu - Responsive Web Design

1. 引用下曹刘阳写的《编写高质量代码-web前端开发修炼之道》一书中看到的一句话:
position:absolute和float会隐式地改变display类型,不论之前什么类型的元素(display:none除外),
只要设置了position:absolute、 float中任意一个,都会让元素以display:inline-block的方式显示:可以设置长宽,默认宽度并不占满父元素

以span为例子,如何让元素变为inline-block。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <span style="height:100px;width:200px;background:yellowgreen">normal span, width and height doesn't work.</span>
    <br>
    <br>
    <span style="height:100px;width:200px;background:pink;position:absolute">span with position:absolute, width and
        height work.</span>
    <br>
    <br>
    <br>
    <br>
    <br>
    <span style="height:100px;width:200px;background:orange;float:left">span with float:left, width and height
        work.</span>
    <br>
    <br>
    <br>
    <br>
    <br>
    <div style="display: flex">
        <span style="height:100px;width:200px;background:gold;">span's father with display:flex, width and height
            work.</span>
    </div>
    <br>
    <span style="height:100px;width:200px;background:deeppink;position:fixed">span with position:fixed, width and height
        work.</span>
</body>
</html>

2. Fixed未解之谜

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        body{
            margin: 0;
            padding: 0;
        }
        .box1{
            width: 100%;
            position: fixed;
            height:80px;
            background: yellowgreen;
        }

        p{
            margin:30px;
        }
    </style>
</head>
<body>
    <div class="box1"></div>
    <p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin
        literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney
        College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and
        going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum
        comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by
        Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance.
        The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
        
        The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections
        1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original
        form, accompanied by English versions from the 1914 translation by H. Rackham.</p>
        <p style="color:red">去掉段落,box1没有top margin, 加上段落后,就会出现top margin,margin来自于p的margin Why</p>
        <p>生成绝对定位的元素,相对于浏览器窗口进行定位。这不对啊</p>
</body>
</html>

3. background-size 详述

   contain:自由伸展,直到有一边贴边。 包含,但是会有富裕

   cover: 等比例覆盖,没有空白,图片会有显示不到的地方。

   percentage: X% Y% 宽高均参考父元素。

   length:具体数值。只给一个值,另外一个值为auto, 50% (auto), auto 50%, background-size默认情况是(auto auto),使用图片自己本身的尺寸。

4. background 的image居中 可以使用background-position:50% 50%

5. 设置多个相同元素间隔,可以使用margin-left/right

好的,以下是一个使用Python编写的爬虫代码,可以爬取该网页的相关数据: ```python import requests from bs4 import BeautifulSoup # 设置请求头信息 headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3' } # 定义爬取网页数据的函数 def get_data(): # 指定要爬取的网页链接 url = 'https://www.mafengwo.cn/travel-scenic-spot/mafengwo/84711.html' # 发送HTTP请求 response = requests.get(url, headers=headers) # 解析HTML文档 soup = BeautifulSoup(response.text, 'html.parser') # 获取景点名称 spot_name = soup.find('h1', class_='t-title').text # 获取景点评分 score = soup.find('span', class_='score').text # 获取景点地址 spot_address = soup.find('span', class_='item-address').text.strip() # 获取景点介绍 spot_intro = soup.find('div', class_='summary').text.strip() # 获取景点图片链接 image_url = soup.find('img', class_='img-responsive')['src'] # 输出景点信息 print('景点名称:', spot_name) print('评分:', score) print('地址:', spot_address) print('介绍:', spot_intro) print('图片链接:', image_url) # 主函数 if __name__ == '__main__': # 调用爬取网页数据的函数 get_data() ``` 在代码中,我们首先使用`requests`库发送HTTP请求,然后使用`BeautifulSoup`库解析HTML文档。通过分析网页的HTML结构,我们可以使用`find`方法获取到需要的景点名称、评分、地址、介绍和图片链接等数据。最后,我们输出这些数据到控制台中。当然,您可以将这些数据存储到文件或数据库中,以便后续分析。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值