css - 为什么这个元素在移动版本中没有出现在中心?html 或 css 有什么问题?

标签 css html

我附上了电脑版和手机版的截图

我附上了 2 个不同的屏幕截图 - 一个桌面版和一个移动版 (iPhone 6)

如何使代码在所有设备上都相似?

mobile view

desktop view

为什么卡片没有出现在移动 View 的中心,我只是一个初学者,我正在尝试使用 Ionic、Angular、HTML、CSS 实现一个汽车预订应用程序。

还有一点空间被浪费在左边 - 看截图。

我的代码是

 <center>
    <div style="margin-top:80%;width:100%;position:absolute;" class="card">
    <div style="background-color:#002b45;height: 200px;" class="item item-avatar">

  <!-- <div align="center"> -->

   <div class="bottom" style="color: #b4ccda">
   <img style="height:60px;width:120px;border-radius:50%;" class="img_car"    src="assets/images/car1.png">
    <br>Honda City
    <br>HK 1234 5678

      </div>


        <br>
    <button style="width:250px;margin-top:-15px;" class="button button-    positive">
    Book Car
</button>
</div>
</center>

请提出问题所在。我想要桌面和移动设备的单一解决方案

最佳答案

enter image description here

CSS

电话

user-select: none;
    max-width: 3600px;
    margin: 0;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%)

桌面

width: auto;
    margin: 0px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    height: auto;

编辑

-------------------------------------------- ------

两者皆有

width: auto;
    margin: 0px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    height: auto;

或使用媒体查询

@media screen and (min-width: 480px) {
    img{
       user-select: none;
       max-width: 3600px;
       margin: 0;
        position: absolute;
       top: 50%;
       left: 50%;
       transform: translate(-50%, -50%)
    }
}

@media screen and (max-width: 480px) {
    img{
       user-select: none;
       max-width: 3600px;
       margin: 0;
        position: absolute;
       top: 50%;
       left: 50%;
       transform: translate(-50%, -50%)
    }
}

是的,您可以在 css 文件中添加代码,但更改类名 要阅读有关媒体查询的更多信息,请查看 herehere

关于css - 为什么这个元素在移动版本中没有出现在中心?html 或 css 有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41662331/

相关文章:

html - 使某些元素可能消失的菜单居中

html - 使用 Bootstrap 响应方案的框之间的间距

html - 对不同元素使用相同的 CSS 类标识符时,浏览器是否存在兼容性问题?

javascript - 我想在按下“提交”按钮后在 iframe 中的 index.html 上加载 get.php 文件

html - 名称长度的 CSS 家谱对齐问题

html - 复制 HTML 内容时如何查看被复制的隐藏格式?

html - FIELDSET 中包含绝对定位的 DIV 中的信息框被截断

html - 覆盖 html input[type=number] 样式以更改箭头

html - 尽管使用了位置 :absolute,但表头并未保持固定

jquery - 使用 jquery mobile 和 html5 的标签栏 iOS 应用程序