我正在做一个桌面和移动屏幕的网站.在台式机屏幕上没有错误.但当我在手机屏幕上显示时.我的设计在缩水.而且İt也不适合手机屏幕.我使用的 bootstrap 版本号是5.但我try 使用的宽度:100%;但ıt不起作用.另外,我正在制作.Net网络应用程序.我怎么才能修好它呢?

您可以查看:

enter image description here

İ的期待:(ipad版)

enter image description here

以下是我的代码:

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">  

  </head>



    <header class="head navigation fixed-top ">
        <img />
        <nav class="navigation">
            <a href="Index">Main Page</a>

            <a href="blog">Blog</a>
            <a href="https://api.whatsapp.com/send?phone=905304500247&amp;text=&amp;source=&amp;data=">Contact</a>

        </nav>

    </header>
    <br />


    <div style="width: 100%; height: 750px; background-color: yellow;  ">

     



        <div class="example">
            <img style="width: 100%; height: 750px;" class="background-image" src="~/Img/web_site.png">
            <div class="overlay-text">
                <h1>Welcome to our Web Page</h1>
                <p> </p>
            </div>




        </div>


    </div>


    <div style="width: 100%; height: 450px; background-color: black; padding-left: 20px; text-align: center; ">
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />

        <h2 style="color: white; top: 50%; right: 50%; ">We're happy to be a leading software</h2>
        <h2 style="color: white; top: 50%; right: 50%;">company in İstanbul</h2>
        <h2 style="color: white; top: 50%; right: 50%;">solutions for today's enterprise companies.</h2>

        <br />
        <br />
        <a href="https://api.whatsapp.com/send?phone=905304500247&amp;text=&amp;source=&amp;data="><button onclick="window.location.href='/Home/login_page'" class="btncomminicate">Contact Us</button></a>

    </div>

Css代码:

   @@media only screen and (max-width: 600px) {
        .body {
            margin: 0;
            padding: 0;
        }

        }

    }

    html, body {
        margin: 0px;
        height: 100%;
        padding-top: 0px;
        padding-bottom: 0px;
    }

    .example {
        position: relative;
    }

    .overlay-text {
        background-color: rgba(255, 255, 255, 0.5);
        padding: 20px;
        text-align: center;
        position: absolute;
        top: 50%;
        right: 50%;
        transform: translate(50%, -50%);
    }


    .head {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        padding: 20px 100px;
        height: 70px;
        background-color: #000000;
        display: flex;
        /*  justify-content: center; */
        justify-content: center;
        align-items: center;
        z-index: 99;
    }

    .navigation a {
        position: relative;
        font-size: 1.1em;
        color: white;
        text-decoration: none;
        font-weight: 500;
        margin-left: 40px;
    }

        .navigation a::after {
            content: '';
            position: absolute;
            left: 0;
            bottom: -6px;
            width: 100%;
            height: 3px;
            background: white;
            border-radius: 5px;
            transform-origin: right;
            transform: scaleX(0);
            transition: transform .5s;
        }

        .navigation a:hover::after {
            transform-origin: left;
            transform: scaleX(1);
        }

    .btncomminicate {
        width: 500px;
        height: 50px;
        background: transparent;
        border: 2px solid yellow;
        outline: none;
        border-radius: 6px;
        cursor: pointer;
        font-size: 1.1em;
        color: yellow;
        font-weight: 500;
        margin-left: 40px;
    }

        .btncomminicate:hover {
            width: 500px;
            height: 50px;
            background: yellow;
            border: 2px solid yellow;
            outline: none;
            border-radius: 6px;
            cursor: pointer;
            font-size: 1.1em;
            color: black;
            font-weight: 500;
            margin-left: 40px;
        }

推荐答案

这是因为一旦你的宽度小于500px,设置为500px的"Contact Us"按钮就会比100%的宽度宽,并在右边留下空白.

具体地说,下面这几行:


.btncomminicate {
  width: 500px;
}

.btncomminicate:hover {
      width: 500px;
}

您可以将其调整为百分比宽度(width: 75%),也可以让宽度自动计算(删除上面的两行).

就我个人而言,我通常处理按钮的方式是添加填充,而不是设置宽度和高度(如果使用这种方法,您的height: 50px可以被删除):

/* Something like this - adjust units to your tastes */
.btncomminicate {
  padding: 1rem 2rem;
}

Html相关问答推荐

将多个内联元素置于中心,而无需访问父级上的CSS

Vue.js复选框对齐问题:在表格单元格中居中复选框

隐藏滚动条和禁用文本 Select 的CSS技术?

为什么使用Google字体的SVG徽标内的文本不能在网页上正确呈现?

为什么根捕获上的`min-height`溢出,而`height`没有?

为什么我得不到有错误的字段?迈克尔·哈特尔教程.7.3.3

带有下拉菜单的完整css导航-链接不起作用?

CSS 伪类 Select 器未按预期工作

网格项未在同一行上对齐

太多的 Web 视图实例导致手机过热 Swift

在显示 swift ui 之前加载下一个 YouTube 视频

在 HTML 视频上环绕文本叠加

为什么溢出时overflow: auto框的底部有一个小间隙?

如何检测输入字段是否没有必填且没有占位符?

理解图像与其内容框之间的关系

如何将一个边框向下移动

CSS "overflow"不能显示整个单词

如何为Vuetify输入控件减小标签和字段之间的间距?

从 Vue 应用程序的容器元素渲染 HTML

在带有换行文本的工具提示中显示溢出文本