【问题标题】:<button> is not being positioned where I want it to go<button> 没有被定位在我想要它去的地方
【发布时间】:2022-11-22 12:03:46
【问题描述】:

我正在尝试为学校项目创建一个虚假网站。到目前为止,我已经添加了一个交叉淡入淡出的图像横幅。接下来我要添加的是一个栏,您可以在其中转到不同的页面,例如“食品”、“促销”等。我希望这个栏位于图像横幅下方。但是,当我添加标签时,它们位于我的横幅之上。之前,我使用了一个简单的图像横幅,当我添加标签时,它们会像往常一样将自己定位在图像下方。但是因为我使用了多个图像和动画,它的行为有所不同,我不知道如何修复它。

下面是我想要的效果(但这是因为我禁用了淡入淡出)

我得到的最接近的解决方案是更改 .fadein{height:1000px} 并将按钮向下移动,但我不确定这有多可行。我还更改了按钮的相对位置、绝对位置等,但没有一个能达到我想要的效果。

这是我的代码。

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style type="text/css">
/* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}

img {display:block}
    
.button {
    background-color:black;
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 20px;
    font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
}
.button:hover{background-color:aqua}

.header {
    background-color: #DB912B;
}
p {
    font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
}

.blackFriday{
    line-height: 40px;
    height: 40px;
    position: relative;
    overflow: hidden;
    background-color: antiquewhite z-index: 1;
    font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
}

/*.fadein{height:100px;}*/
    
/*Animated Banner*/
.fadein img {
    position:absolute;
    -webkit-animation-name: fade;
    -webkit-animation-iteration-count: infinite;
    -webkit-animation-duration: 12s;
    animation-name: fade;
    animation-iteration-count: infinite;
    animation-duration: 12s;
}

@-webkit-keyframes fade {
    0% {opacity: 0;}
    20% {opacity: 1;}
    33% {opacity: 1;}
    53% {opacity: 0;}
    100% {opacity: 0;}
}
@keyframes fade {
    0% {opacity: 0;}
    20% {opacity: 1;}
    33% {opacity: 1;}
    53% {opacity: 0;}
    100% {opacity: 0;}
}

#f1 {
    background-color: lightblue;
}
#f2 {
    -webkit-animation-delay: -8s;
    background-color: yellow;
}
#f3 {
    -webkit-animation-delay: -4s;
    background-color: lightgreen;
}
    
    
</style>

</head>

<body>
    <center>
      <p class="blackFriday" style="background-color:#191616; color: white; font-weight:bold;">BLACK FRIDAY SALE!</p>
    </center>
<div class="fadein">
    <img id="f3" src="banner1.png" width="100%" alt="">
    <img id="f2" src="banner2.png" width="100%"  alt="">
    <img id="f1" src="banner3.png" width="100%"   alt="">
</div>

<!--Buttons-->
<center>
    <p style="background-color:black; position:relative;" >
        <button class="button">food</button>
        <button class="button">toys</button>
        <button class="button">medicine</button>
        <button class="button">holiday sale</button>
        <button class="button">about us</button>
    </p>
</center>
    
</body>
</html>

谢谢,对不起,如果这是一个简单的解决方案,我不熟悉 html。

【问题讨论】:

    标签: html


    【解决方案1】:

    我稍微修改了您的代码,它完全按照您的预期工作。这里是。希望能帮助到你!

    /* http://meyerweb.com/eric/tools/css/reset/ 
       v2.0 | 20110126
       License: none (public domain)
    */
    
    html,
    body,
    div,
    span,
    applet,
    object,
    iframe,
    h1,
    h2,
    h3,
    h4,
    h5,
    h6,
    p,
    blockquote,
    pre,
    a,
    abbr,
    acronym,
    address,
    big,
    cite,
    code,
    del,
    dfn,
    em,
    img,
    ins,
    kbd,
    q,
    s,
    samp,
    small,
    strike,
    strong,
    sub,
    sup,
    tt,
    var,
    b,
    u,
    i,
    center,
    dl,
    dt,
    dd,
    ol,
    ul,
    li,
    fieldset,
    form,
    label,
    legend,
    table,
    caption,
    tbody,
    tfoot,
    thead,
    tr,
    th,
    td,
    article,
    aside,
    canvas,
    details,
    embed,
    figure,
    figcaption,
    footer,
    header,
    hgroup,
    menu,
    nav,
    output,
    ruby,
    section,
    summary,
    time,
    mark,
    audio,
    video {
      margin: 0;
      padding: 0;
      border: 0;
      font-size: 100%;
      font: inherit;
      vertical-align: baseline;
    }
    
    
    /* HTML5 display-role reset for older browsers */
    
    article,
    aside,
    details,
    figcaption,
    figure,
    footer,
    header,
    hgroup,
    menu,
    nav,
    section {
      display: block;
    }
    
    body {
      line-height: 1;
    }
    
    ol,
    ul {
      list-style: none;
    }
    
    blockquote,
    q {
      quotes: none;
    }
    
    blockquote:before,
    blockquote:after,
    q:before,
    q:after {
      content: '';
      content: none;
    }
    
    .button {
      background-color: black;
      border: none;
      color: white;
      padding: 15px 32px;
      text-align: center;
      text-decoration: none;
      display: inline-block;
      font-size: 20px;
      font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
    }
    
    .button:hover {
      background-color: aqua
    }
    
    .header {
      background-color: #DB912B;
    }
    
    p {
      font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
    }
    
    .blackFriday {
      line-height: 40px;
      height: 40px;
      position: relative;
      overflow: hidden;
      background-color: antiquewhite z-index: 1;
      font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
    }
    
    .fadein {
      position: relative;
      margin: 0;
      width: 100%;
      height: 90vh;
    }
    
    
    /*Animated Banner*/
    
    .fadein img {
      position: absolute;
      inset: 0;
      width: 100%;
      height: 100%;
      object-fit: cover;
      -webkit-animation-name: fade;
      -webkit-animation-iteration-count: infinite;
      -webkit-animation-duration: 12s;
      animation-name: fade;
      animation-iteration-count: infinite;
      animation-duration: 12s;
    }
    
    @-webkit-keyframes fade {
      0% {
        opacity: 0;
      }
      20% {
        opacity: 1;
      }
      33% {
        opacity: 1;
      }
      53% {
        opacity: 0;
      }
      100% {
        opacity: 0;
      }
    }
    
    @keyframes fade {
      0% {
        opacity: 0;
      }
      20% {
        opacity: 1;
      }
      33% {
        opacity: 1;
      }
      53% {
        opacity: 0;
      }
      100% {
        opacity: 0;
      }
    }
    
    #f1 {
      background-color: lightblue;
    }
    
    #f2 {
      -webkit-animation-delay: -8s;
      background-color: yellow;
    }
    
    #f3 {
      -webkit-animation-delay: -4s;
      background-color: lightgreen;
    }
    <body>
      <center>
        <p class="blackFriday" style="background-color:#191616; color: white; font-weight:bold;">BLACK FRIDAY SALE!</p>
      </center>
      <div class="fadein">
        <img id="f3" src="https://picsum.photos/550/350" alt="">
        <img id="f2" src="https://picsum.photos/540/340" alt="">
        <img id="f1" src="https://picsum.photos/530/330" alt="">
      </div>
    
      <!--Buttons-->
      <center>
        <p style="background-color:black; position:relative;">
          <button class="button">food</button>
          <button class="button">toys</button>
          <button class="button">medicine</button>
          <button class="button">holiday sale</button>
          <button class="button">about us</button>
        </p>
      </center>
    
    </body>
    
    </html>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-05
      • 2013-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多