HTML输入元素不占用100%宽度

时间:2016-01-28 10:58:49

标签: html css

我的角度代码on gitHub 正在使用ngRoute,其中page1.html在ngView中加载。

我在page1.html中有输入元素,其css设置为100%,因此预计会填充视图的宽度,但它只占大约70%左右。

如果主要元素宽度设置为100%,则页脚按钮消失,图像2。 不知道为什么?谢谢 enter image description here

* {
    margin: 0;
    padding: 0;
}

html {
    height: 100%;
}

body {
    height: 1%;
}

header > button {
    height: 1.5em;
    width: 1.5em;
    font-size: 1.5em;
    top: 0;
}

label.pageTitle {
    display: inline-block;
    width: calc(100% - 5em);
    text-align: center;
}

header {
    border-bottom: 1px solid black;
    width: 100%;
    position: fixed;
    top: 0;
}

main, .mainMenu {
    position: absolute;
    top: 2.5em;
}

main {
    z-index: -2;
}

footer {
    position: fixed;
    bottom: 0;
    width: 100%;
}

footer > button {
    font-size: 1em;
    padding: 0.5em 1em;

}
input {
    font-size: 1em;
    padding: 0.25em;
    margin: 0.25em;
    width: 100%;
}

header, footer {
    background-color: white;
}

.horizontal-style {
    display: table;
    width: 100%
}
.horizontal-style li {
    display: table-cell;
    padding: 2px;
}
.horizontal-style button {
    display: block;
    border: 1px solid black;
    text-align: center;
    background: #dfdfdf;
}

footer button {
    width: 100%;
    border-radius: 6px;
    font-size: 1.5em;
}

.mainMenu {
    padding-left: 1em;
    background-color: #dfdfdf;
    width: 70%;
    border-radius: 0 6px 10px 0;
}

ul {
    list-style-type: none;
}

ul li img {
    vertical-align: middle;
    padding-right: 0.25em;
}

a {
    display: block;
    padding: 1em 0em;
}
//   page1.html
<section>
    <input type="text" placeholder="page1-input1">
</section>

//   index.html

<!doctype html>
<html lang="en" ng-app="appModule">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="index.css">
    <meta name="viewport" content="width=device-width" />

    <base href="http://localhost:63342/students/">

    <!--<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js"></script>-->
    <!--<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular-route.js"></script>-->
    <script src="angular.js"></script>
    <script src="angular-route.js"></script>

    <script src="app.js"></script>

    <script src="services/routing.js"></script>
    <script src="services/menuToggle.js"></script>

    <script src="controllers/menuToggleCtrl.js"></script>
    <script src="controllers/mainMenuCtrl.js"></script>
    <script src="controllers/page1Ctrl.js"></script>
    <script src="controllers/page2Ctrl.js"></script>
</head>

<body>
<header ng-controller="MenuToggleCtrl">
    <button class="menuLeft" type="button" ng-model="clicked" ng-click="menuToggle()">&#9776;</button>
    <label id="pageTitle" class="pageTitle">Select item from list</label>
    <button class="menuRight" type="button">&#8942;</button>
</header>

<section class="mainMenu" ng-controller="MainMenuCtrl" ng-if="!clicked">
    <ul>
        <li ng-repeat="item in menuItems">
            <a href="#/{{item.name}}">
                <image ng-src="images/{{item.image}}.png"></image>
                {{item.name}}
            </a>
        </li>
    </ul>
</section>

<main ng-view></main>

<footer ng-controller="MenuToggleCtrl" ng-if="clicked">
    <ul class="horizontal-style">
        <li><button type="button">NO</button></li>
        <li><button type="button">EXTRA</button></li>
        <li><button type="button">YES</button></li>
    </ul>
</footer>

</body>
</html>

3 个答案:

答案 0 :(得分:2)

你的mainMenu被设置为70%的宽度,当你指定一个mainMenu宽度为100%的子节点时,它占用了它的父节点的整个宽度,所以最终你的输入将是你的父容器,这意味着70%。如果你希望它是100%的屏幕,你必须使mainMenu 100%。

答案 1 :(得分:2)

尝试在CSS代码中将输入字段的最小宽度设置为100%:

input {
    font-size: 1em;
    padding: 0.25em;
    margin: 0.25em;
    width: 100%;
    min-width: 100%; }

当输入没有达到其父级的100%宽度时,这应解决问题。

答案 2 :(得分:1)

输入元素将插入“main”容器中。因此,请将主标记的宽度设置为100%。

engine_prodJSON.php

这是修复

main, .mainMenu {
    position: absolute;
    top: 2.5em;
    width: 100%;
}
* {
    margin: 0;
    padding: 0;
}

html {
    height: 100%;
}

body {
    height: 1%;
}

header > button {
    height: 1.5em;
    width: 1.5em;
    font-size: 1.5em;
    top: 0;
}

label.pageTitle {
    display: inline-block;
    width: calc(100% - 5em);
    text-align: center;
}

header {
    border-bottom: 1px solid black;
    width: 100%;
    position: fixed;
    top: 0;
}

main, .mainMenu {
    position: absolute;
    top: 2.5em;
    width: 100%;
}

main {
    z-index: -2;
}

footer {
    position: fixed;
    bottom: 0;
    width: 100%;
}

footer > button {
    font-size: 1em;
    padding: 0.5em 1em;

}
input {
    font-size: 1em;
    padding: 0.25em;
    margin: 0.25em;
    width: 100%;
}

header, footer {
    background-color: white;
}

.horizontal-style {
    display: table;
    width: 100%
}
.horizontal-style li {
    display: table-cell;
    padding: 2px;
}
.horizontal-style button {
    display: block;
    border: 1px solid black;
    text-align: center;
    background: #dfdfdf;
}

footer button {
    width: 100%;
    border-radius: 6px;
    font-size: 1.5em;
}

.mainMenu {
    padding-left: 1em;
    background-color: #dfdfdf;
    width: 70%;
    border-radius: 0 6px 10px 0;
}

ul {
    list-style-type: none;
}

ul li img {
    vertical-align: middle;
    padding-right: 0.25em;
}

a {
    display: block;
    padding: 1em 0em;
}