html - 粘性底部按钮仅适用于移动设备

标签 html css

我计划添加一个按钮,该按钮将粘在屏幕底部居中,仅在移动网站上。我不希望它显示在桌面或任何其他设备上。

有人可以帮我写CSS吗?

感谢所有帮助。非常感谢!

HTML:

<div class="mobileShow">
<a href="tel:+90123123123"><img src="http://cizgiaydinlatma.com/wp-content/uploads/2016/09/pi5MKo6zT.png"></a>
</div>

CSS:

<style type="text/css">
.mobileShow {
  display: none;
}
/* Smartphone Portrait and Landscape */
@media only screen and (min-device-width: 320px) and (max-device-width: 480px) {
  .mobileShow {
    display: inline;
    width: 40%;
    position: fixed;
    bottom: 0;
    margin-left: auto;
    margin-right: auto;
  }
}
</style>

最佳答案

你就快到了!我已将您的代码放在 jsfiddle 中并对其进行调整,使按钮居中,如下所示:

.mobileShow {
  display: none;
}

/* full width of parent */
.mobileShow img{
    width: 100%;
}

/* Smartphone Portrait and Landscape */
@media only screen and (min-device-width: 320px) and (max-device-width: 480px) {
  .mobileShow {
    display: block;
    width: 40%;
    position: fixed;
    bottom: 0;
    left: 50%;
    margin: 0 0 0 -20%;
  }
}

关于html - 粘性底部按钮仅适用于移动设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39617803/

相关文章:

javascript - JS 和 HTML 隐藏 div 不起作用

css - 在 native react 中顺利增加高度?

html - 如何减小字体大小?

javascript - 列中 Bootstrap3 工具提示的 z-index 是特定于浏览器的

css - IE9 复选框在焦点上呈现异常

html - 无边距居中

HTML/CSS - 横向和纵​​向选项

javascript - 如何以水平方式溢出元素?

css - 当表格不在页面顶部时,滚动带有固定标题的全高表格主体

css - 为什么我的绝对定位的 div 在 IE 中不会停留在顶层?