解决:当浏览器窗口缩小时,文本内容被“挤”下来的问题

目录

一、问题分析及解决办法

 二、重点总结

 三、完整代码

四、最终效果


一、问题分析及解决办法

  

问题产生原因:在编写代码时没有给包裹文本的父盒子设置宽度,导致当浏览器页面缩小到一定程度时(即父盒子宽度缩小到一定程度),文本内容因为父盒子宽度不够而被挤到下一行排列显示。

解决办法:给包裹文本的父盒子设置宽度(即网页版心宽度)。

 二、重点总结

 1、头部如何布局

第一步 设置头部版心宽度;

第二步 将头部分成两个部分,一个左浮动和另一个右浮动。

2、版心横幅、登录区如何布局?

先给横幅(绿色线)设置宽度(版心宽度)和高度,然后设置横幅背景图片;

最后,给登录模块(蓝色线)设置右浮动 即可贴在版心右侧。

 三、完整代码

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./css/iconfont.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
            text-decoration: none;
        }

        .w {
            width: 990px;
            margin: 0 auto;
        }

        header {
            height: 80px;
        }

        header li:first-of-type {
            float: left;
        }

        header li:last-of-type {
            float: right;
        }

        h1 {
            float: left;
            margin-top: 10px;
        }

        header p {
            float: left;
            margin: 30px 0 0 20px;
        }

        a>i {
            display: inline-block;
            vertical-align: middle;
            width: 18px;
            height: 14px;
            background: url(./images/q-icon.png) no-repeat;
            margin-right: -1px;
        }

        header li:last-of-type a {
            position: relative;
            top: 48px;
            color: #999;
            font-size: 12px;
            font-family: "\5b8b\4f53";
        }

        header li>a:hover {
            color: #E4393C;
            text-decoration: underline;
        }

        /* 主体区 */
        main>section {
            height: 39px;
            line-height: 39px;
            background-color: #FFF8F0;
        }

        main>section>p {
            font-size: 12px;
            color: #999;
            text-align: center;
            font-family: "\5b8b\4f53";
        }

        .iconfont {
            vertical-align: middle;
            font-size: 23px;
        }

        main>p>a {
            color: #333;
        }

        main>section>p>a:hover {
            color: #333;
        }

        /* 中间红色区 */
        main>div {
            height: 475px;
            background-color: #e93854;
        }

        .banner {
            height: 475px;
            background: url(./images/background.png) no-repeat;
        }

        .banner>article {
            float: right;
            width: 346px;
            margin-top: 10px;
            background-color: white;
        }

        article>p {
            height: 39px;
            line-height: 39px;
            color: #999;
            font-size: 12px;
            text-align: center;
            font-family: "\5b8b\4f53";
            background-color: #FFF8F0;
        }

        article>ul {
            height: 54px;
            line-height: 54px;
            border-bottom: 1px solid #F4F4F4;
        }

        article ul>li {
            float: left;
        }

        article ul>li>a {
            display: inline-block;
            width: 172px;
            font-size: 18px;
            line-height: 18px;
            text-align: center;
        }

        article ul>li:first-child>a {
            border-right: 1px solid #F4F4F4;
            color: #666666;
        }

        article ul>li:last-child>a {
            color: #e4393c;
            font-weight: 700;
        }

        article ul>li>a:hover {
            text-decoration: none;
            color: #E4393C;
            font-weight: 700;
        }

        /* 表单form */
        #loginname,
        #pwd {
            width: 267px;
            height: 40px;
            box-sizing: border-box;
            border: 1px solid #BBBBBB;
            outline: none;
            text-indent: 12px;
        }

        form p>label>span {
            display: inline-block;
            vertical-align: middle;
            width: 40px;
            height: 40px;
            background-color: red;
            box-sizing: border-box;
            border: 1px solid #BBBBBB;
            margin-right: -6px;
        }

        form p:first-child {
            margin: 33px 0 20px 20px;
        }

        form p:first-child>label>span {
            background: url(./images/pwd-icons-new.png) no-repeat;
        }

        form p:nth-child(2) {
            margin-left: 20px;
        }

        form p:nth-child(2)>label>span {
            background: url(./images/pwd-icons-new.png) no-repeat -48px 0;
        }

        form p:nth-child(3)>a {
            float: right;
            font-size: 12px;
            color: #666666;
            margin: 20px 21px 21px 0;
        }

        form p:nth-child(3)>a:hover {
            color: #E4393C;
            text-decoration: underline;
        }

        /* 红色长条“登录” */
        form p:nth-child(4)>a {
            display: inline-block;
            width: 305px;
            height: 30px;
            line-height: 30px;
            margin: 0 0 31px 21px;
            text-align: center;
            border: 2px solid #e85356;
            background-color: #e4393c;
            font-size: 20px;
            color: white;
        }

        form p:nth-child(4)>a:active {
            border: 2px solid #4D90FE;
        }

        form p:nth-child(4)>a:hover {
            text-decoration: none;
        }

        /* qq 微信 */
        section {
            height: 50px;
            line-height: 50px;
            border-top: 1px solid #F4F4F4;
        }

        section a {
            font-size: 12px;
            color: #666666;
        }

        section>a:first-child>i {
            width: 19px;
            height: 18px;
            background: url(./images/QQ-weixin.png);
            margin: -4px 2px 0 21px;
        }

        /* qq、微信中间竖线 */
        section>.line {
            color: #ccc;
            font-size: 12px;
            padding: 0 6px;
        }

        section>a:nth-of-type(2)>i {
            margin: -4px 2px 0 0;
            width: 19px;
            height: 18px;
            background: url(./images/QQ-weixin.png) no-repeat -19px 0;
        }

        section>a:nth-of-type(3) {
            float: right;
            margin-right: 21px;
            font-size: 14px;
            color: #B61D1D;
        }

        section>a:nth-of-type(3)>i {
            width: 16px;
            height: 16px;
            background: url(./images/pwd-icons-new.png) no-repeat -104px -75px;
            margin-top: -4px;
        }

        /* 底部 */
        footer>div {
            font-size: 12px;
            color: #666;
            text-align: center;
        }

        .links {
            margin: 21px 0 14px 0;
        }

        .links>a {
            margin: 0 9px;
            color: #666666;
        }

        a:hover {
            color: #E4393C;
            text-decoration: underline;
        }
    </style>
</head>

<body>
    <header class="w">
        <ul>
            <li>
                <a href="#">
                    <h1>
                        <img src="./images/logo-201305-b.png" alt="logo">
                    </h1>
                </a>
                <p>
                    <img src="./images/wecome-icon.png" alt="欢迎登录">
                </p>
            </li>
            <li>
                <a href="#">
                    <i></i>
                    登录页面,调查问卷
                </a>
            </li>
        </ul>
    </header>
    <main>
        <section>
            <p class="w">
                <span class="iconfont s1">&#xe8e5;</span>依据《网络安全法》,为保障您的账户安全和正常使用,请尽快完成手机号验证! 新版<a
                    href="#">《京东隐私政策》</a>已上线,将更有利于保护您的个人隐私。
            </p>
        </section>
        <div>
            <div class="banner w">
                <!-- 中间浅色区域 -->
                <article>
                    <p><span class="iconfont">&#xe8e5;</span>京东不会以任何理由要求您转账汇款,谨防诈骗。</p>
                    <ul>
                        <li><a href="#">扫码登录</a></li>
                        <li><a href="#">账户登录</a></li>
                    </ul>
                    <form action="qn.java" method="post">
                        <p>
                            <!-- 输入用户名 -->
                            <label for="loginname"><span></span></label>
                            <input type="text" name="loginname" id="loginname" placeholder="邮箱/账号名/登录手机">
                        </p>
                        <p>
                            <!-- 输入密码 -->
                            <label for="pwd"><span></span></label>
                            <input type="password" name="pwd" id="pwd" placeholder="密码">
                        </p>
                        <p><a href="#">忘记密码</a></p>
                        <p><a href="#">登&nbsp;&nbsp;&nbsp;&nbsp; 录</a></p>
                    </form>
                    <!-- qq 微信 -->
                    <section>
                        <a href="#">
                            <i></i>
                            QQ</a>
                        <span class="line">|</span>
                        <a href="#">
                            <i></i>
                            微信</a>
                        <a href="#">
                            <i></i>
                            立即注册</a>
                    </section>
                </article>

            </div>
        </div>
    </main>
    <footer class="w">
        <div class="links">
            <a href="#">关于我们</a>|
            <a href="#">联系我们</a>|
            <a href="#">人才招聘</a>|
            <a href="#">商家入驻</a>|
            <a href="#">广告服务</a>|
            <a href="#">手机京东</a>|
            <a href="#">友情链接</a>|
            <a href="#">销售联盟</a>|
            <a href="#">京东社区</a>|
            <a href="#">京东公益</a>|
            <a href="#">关于我们</a>|
            <a href="#">English Site</a>
        </div>
        <div class="copyright">
            Copyright © 2004-2022&nbsp;&nbsp;京东JD.com&nbsp;版权所有
        </div>
    </footer>
</body>

</html>

四、最终效果

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值