php - 我如何使用 css 对齐我的 div 容器

标签 php html css

如何在另一个容器内水平对齐我的容器。我还想在调整窗口大小时将它们居中对齐,因为每次我尝试它时,容器都会在某个地方弹出,我不希望它们出现,请帮助我,谢谢。下面是代码:

我的索引页

<html>
<head>
<title> Kwiktable </title>
<link rel="stylesheet" type="text/css" href="jssor.css">
</head>
<body>
<div class="headercontainer" style="z-index:1000;">
  <div class="header clearfix"> <span class="logo"><img src="img/kwiktable.png"><a href = "index.php">&nbsp <img src = "img/kwik.png"> </a></span>
    <input type="text" class="textbox" style="color:#888;" 
    value="Search" onfocus="inputFocus(this)" onblur="inputBlur(this)">
    <script>
        =function inputFocus(i){
    if(i.value==i.defaultValue){ i.value=""; i.style.color="#000"; }
        }
    function inputBlur(i){
    if(i.value==""){ i.value=i.defaultValue; i.style.color="#888"; }
        }
    </script>
    <div class="nav">
      <input type="checkbox" id="toggle">
      <label for="toggle" class="toggle" onclick=""></label>
      <ul class="menu">
        <li><a class="current" href="index.php">Home</a></li>
        <li><a href="aboutus.php">About Us</a></li>
        <li><a href="reserve.php">Reservations</a></li>
        <li><a href="login.php">Log in</a> </li>
      </ul>
    </div>
  </div>
</div>
<center>
<br>    <br>    <br>    <br>
<div style="margin:0 auto;width:100%;max-width:1050px;background-color:#E8E8E8;overflow:hidden; border: 1px solid #000000;">
<div class="container" style=" margin-left: 10px; width 100%; max-width: 450px; background-color:#E8E8E8;overflow:hidden;">
  <?php include 'content1.html';?>
  <?php include 'content.html'; ?>
</div>
<div class="container1" style="margin-right: 10px; margin-top: 10px; width 100%; max-width: 450px; background-color:#E8E8E8;overflow:hidden; "> </div>
<div  class="container2">
  <?php 
    echo "<br><h1>Kwiktable's Best</h1>";
    include 'best.php';
    ?>
  <br>      <br>      <br>      <br>
</div>
</center>
<?php include 'footer.php'; ?>
</body>
</html>

我的 CSS 文件:

* {
    margin: 0;
    padding: 0;
    outline: 0;
}

html, body {
    height: 100%;
    background: #fff;
}

body, a {
    font: normal 16px Helvetica, Verdana, Geneva, sans-serif;
    color: #3f3f3f
}

.textbox {
    margin-top: 25px;
    width: 500px;
    height: 30px;
    background-color: #FFEAEA;
    border: solid 1px #646464;
    border-radius: 5px;
    outline: none;
    padding: 2px 2px;
}

.textbox:hover {
    background-color: #F7C4C4;
    -webkit-transition: all .25s linear;
    -moz-transition: all .25s linear;
    -o-transition: all .25s linear;
    transition: all .25s linear
}

.textbox:focus {
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.83);
    -webkit-transition: all .25s linear;
    -moz-transition: all .25s linear;
    -o-transition: all .25s linear;
    transition: all .25s linear
}

iframe {
    margin-top: 15px;
    margin-right: 15px;
    margin-left: 15px;
    margin-bottom: 15px;
    border-radius: 10px;
    border: solid 1px #000;
}

.headercontainer {
    opacity: 0.95;
    display: block;
    margin: 0 auto;
    margin: 0 auto;
    background-image: url(img/menubar.jpg);
    background-color: #D93625;
    z-index: 1000;
    position: fixed;
    width: 100%;
    top: 0;
    left: 0;
    border-bottom: 1px solid #000;
    box-shadow: 0px 1px 1px #888888;
}

.headercontainer:after {
    content: '';
    display: block;
    clear: both
}

.footer {
    bottom: 0;
    margin: 0 auto;
    height: 60px;
    padding: 0 0;
    background: #bbbfbf;
    font-size: 12px;
    width: 100%;
    border-top: 1px solid #51c1f1
}
 @media only screen and (max-width:480px) {

.copyright { display: none }
}

body {
    -webkit-animation: bugfix infinite 1s;
    -webkit-font-smoothing: antialiased
}
 @-webkit-keyframes 
bugfix {  from {
 padding:0;
}

to { padding: 0; }
}

.header {
    position: relative;
    top: 0;
    left: 0;
    margin: 0 auto;
}

#toggle, .toggle { display: none }

.menu>li {
    list-style: none;
    float: left
}

.clearfix:before, .clearfix:after {
    display: table;
    content: ""
}

.clearfix:after { clear: both }
 @media only screen and (max-width:768px) {

.textbox {
    width: auto;
    -webkit-transition: all .2s linear;
    -moz-transition: all .2s linear;
    -o-transition: all .2s linear;
    transition: all .2s linear;
}

.menu {
    display: none;
    opacity: 0;
    width: 100%;
    position: absolute;
    right: 0
}

.menu>li {
    display: block;
    width: 100%;
    margin: 0
}

.menu>li>a {
    display: block;
    width: 100%;
    text-decoration: none;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box
}

.toggle {
    display: block;
    position: relative;
    cursor: pointer;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    margin-top: 8px
}

#toggle:checked~.menu {
    display: block;
    opacity: 1
}
}

.header {
    min-height: 80px;
    max-width: 1500px;
    height: 100%;
    padding: 0 20px;
    background: #D93625;
    color: #fff;
}

.header>.logo {
    float: left;
    padding: 10px 50px;
    font-style: italic;
    font-size: 28px;
    line-height: 50px
}

.nav {
    display: block;
    float: right;
    text-align: right
}

.nav, .menu, .menu>li, .menu>li>a { height: 100% }

.menu>li>a {
    display: block;
    padding: 20px 17px;
    text-decoration: none;
    font-weight: normal;
    font-size: 16px;
    line-height: 2.8;
    color: #fff;
    border-radius: 10px;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    -webkit-transition: all .25s linear;
    -moz-transition: all .25s linear;
    -o-transition: all .25s linear;
    transition: all .25s linear
}

.menu>li>a:hover, .menu>li>a:focus {
    background: #8B0000;
    border-radius: 10px;
    color: #fff;
    background-color: #8B0000;
    box-shadow: 1px 1px 1px 1px #3D0000 inset;
    border-bottom: solid 1px #FF9292;
    text-shadow: 0px 0px 10px #E6FF00;
}

.menu>li>a.current {
    color: #fff;
    font-weight: 900
}

.toggle { z-index: 2 }
 @media only screen and (max-width:820px) {

.textbox {
    width: auto;
    -webkit-transition: all .2s linear;
    -moz-transition: all .2s linear;
    -o-transition: all .2s linear;
    transition: all .2s linear;
}

.menu {
    background: #363636;
    border-top: 1px solid #fff;
}

.menu, .menu>li, .menu>li>a { height: auto }

.menu>li>a {
    padding: 15px 15px;
    text-align: center;
    background-color: #363636;
    border-bottom: 1px solid #fff;
}

.menu>li>a:hover, .menu>li>a:focus {
    background: #D70000;
    padding: 15px 15px 15px 25px;
}

.toggle:after {
    content: 'Menu';
    box-shadow: 0px 0px 5px 0px #3D0000 inset;
    text-shadow: 0px 0px 10px #E6FF00;
    display: block;
    width: 80px;
    margin: 0 0;
    margin-top: 25px;
    padding: 10px 0;
    background: #D70000;
    -webkit-border-radius: 2px;
    border-radius: 2px;
    text-align: center;
    font-size: 12px;
    color: #fff;
    -webkit-transition: all .5s linear;
    -moz-transition: all .5s linear;
    -o-transition: all .5s linear;
    transition: all .5s linear;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box
}

.toggle:hover:after { background: #920000 }

h1 {
    margin: auto;
    width: 70%;
}

.container {
    width: 700px;
    margin-left: auto;
    margin-right: auto;
}

.container1 {
    margin-left: auto;
    margin-right: auto;
    width: 100%;
}

#toggle:checked+.toggle:after { content: 'Close' }
}

.share-icon {
    display: inline-block;
    float: left;
    margin: 4px;
    width: 32px;
    height: 32px;
    cursor: pointer;
    vertical-align: middle;
    background-image: url(img/share/share-icons.png)
}

最佳答案

看起来您缺少结尾 </div>标签,这很可能是它在整个页面上跳跃的原因。使用这样的工具来帮助您:http://www.freeformatter.com/html-validator.html

很高兴采用响应式设计,但您可能不想更多地关注 HTML 和 CSS。

<center>标签是一个糟糕的黑客。你应该用 CSS 来做到这一点。此外,您对 <br> 的使用间距的 s 也应该用 CSS 来完成。查看填充和边距。

如果你想 <center>一个 div,css 替代方案是这样的:

<div class="container">
    <div style="margin:0 auto; width: 800px;">This will be centered </div>
</div>

只是为了让你开始。

这里发生的是容器 div 像标准 div 一样填充 100%。子 div(带有 style 标签的那个)将其上下边距设置为 0,将左右边距设置为 auto。这里的重要部分是 div 也有一个固定的宽度。因此,在这种情况下,div 将占用 800px,任何剩余空间将 auto matically 按边距均匀分布。

我敢肯定,您可以用 Google 搜索并得到更好的解释。

关于php - 我如何使用 css 对齐我的 div 容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24277091/

相关文章:

javascript - 尝试动态设置 MetaTag

javascript - 通过 HTML 设置 TinyMCE 文本区域的内容

css - 与其他选择器一起选择 MAIN 是否有优势?

css - Jquery Mobile 表单未对齐

php - Sql 查询查找两个给定日期之间的 View 百分比差异

php - 在页面加载之前将 CSS img max-height + max-width 属性动态设置为窗口大小?

php - 替代值应存储在 php 数组中的替代位置

c# - 如何更改没有 ID 的类 css 的属性?

html - 隐藏的 div 使我的网站太长

php - 如何在 woocommerce 中按日期获取用户订单?