【问题标题】:Why is at my Phonegap app only the padding-left applied with a min-width of 100%?为什么在我的 Phonegap 应用程序中只应用了最小宽度为 100% 的 padding-left?
【发布时间】:2016-02-10 22:49:12
【问题描述】:

我确实是 CSS 的初学者,但遇到了一些问题。对于这个问题,我真的试图找到答案(并阅读了几页关于边距、填充、框系统...),但我找不到解决方案。

我正在开发一款 Phonegap 应用程序,现在我尝试让该应用程序看起来更好看。为此,我希望所有元素都居中,灰色背景应该在整个页面上。为了实现这一点,我将其全部放在一个 div 类中,该类的 min-width 和 min-height 设置为 100%。现在我希望元素在左侧和右侧有一个填充,这样它们就不会完全粘在页面的边缘。我的问题是只应用了 padding-left (如果我将值设置得更大,那么左侧的填充也会变大,并且在太大时将元素移出屏幕)但 padding-right 被完全忽略。

我的 HTML 标记:

<html>
<head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="msapplication-tap-highlight" content="no" />
    <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
    <script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
    <title>Home Automatization</title>

</head>

<body>

    <div class="app">
        <h1>Relay switch</h1>
        <br>
        <br>
        <br>
        <br>
        <h2> TextTextTextTextTextTextTextTextText</h2>
        <br>
        <form>
        <label for="relay-switch">Relay:</label>
        <input type="checkbox" data-role="flipswitch" name="flip-checkbox-1" id="flip-checkbox-1" onchange="changeHandler()">
        </form>
        <br>
        <br>
        <button id="logout">Logout</button>
    </div>

</body>

相关的 CSS:

.app {
background-color:#E4E4E4; 
position:fixed;             
min-height:100%;
min-width:100%;
padding-top:60px;
padding-left:5px;
padding-right:5px;
text-align:center;

如果有人可以帮助我,请提前非常感谢。

【问题讨论】:

    标签: css cordova


    【解决方案1】:

    请注意,padding 不会在元素外部创建空间,为此请使用 margin

    我想我已经在你的width: 上使用calc(100% - 12px) 解决了你的问题

    https://jsfiddle.net/bb1yb9w2/

    【讨论】:

    • 首先:非常感谢您的回答问题是它不能 100% 解决我的问题。我已经尝试过类似你的方法。问题只是我不希望我的应用程序边缘有任何白色边框。 bg-color 应该是页面的 100%,但元素应该在里面。我知道填充不会在元素外部创建空间。我想要元素框的边缘和里面的元素之间的空间。
    • @DesperateEi 抱歉 26 天内没有回复,哈哈。这是一个我认为可能是答案的小提琴:jsfiddle.net/bb1yb9w2/2
    • 非常感谢您的回答。有时间我会试试看。与此同时,我为我的项目转向了 jQuery mobile,它基本上以一种非常简单的方式提供了我需要的东西(不必太关心 CSS)。
    猜你喜欢
    • 1970-01-01
    • 2017-03-31
    • 1970-01-01
    • 2014-08-05
    • 2017-03-12
    • 1970-01-01
    • 2012-08-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多