添加按钮会替换侧面的浮动div

时间:2015-12-13 06:47:17

标签: html css button layout css-position

当我添加此按钮时,它会使侧面的浮动元素向下移动(粉红色块)。我不明白为什么,我不想通过改变各地的利润来解决问题。并且absolute定位不起作用,因为它弄乱了我的花车。我还是个新手,所以有些事可能是错的。

正如你在这里看到的那样,当放置按钮时,粉红色的盒子向下移动:

enter image description here



/* BUTTON */
.button {
    display: inline-block;
    outline: none;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    font: 20px;
    padding: .5em 2em .55em;
    -webkit-border-radius: .5em;
    -moz-border-radius: .5em;
    border-radius: .5em;
}

h1 {
    font-size: 4em;
}

header {
    position: fixed;
    top: 0;
    left: 0;
    width: 1640px;
    margin-left: 110px;
    height: 50px;
    background-color: #00a087;
}

#toprow {
    position: fixed;
    width: 100%;
    height: 35px;
    top: 0;
    left: 0;
    margin: 0;
    padding: 0;
    background-color: #00a087;
    margin-top: 50px;
}

body {
    font-family: 'Oswald', sans-serif;
    background-color: #fff;
}

.clearFix {
    clear: both;
}

#largeBox {
    margin-top: 85px;
    width: 750px;
    height: 950px;
    background-color: red;
    margin-left: 240px;
    background: url('football2.jpg');
}

#botRightBox {
    width: 750px;
    height: 475px;
    background-color: green;
    margin-left: 750px;
}

#botTopLeft {
    width: 750px;
    height: 475px;
    background-color: pink;
    margin-left: 750px;
    float: right;
}

#row {
    width: 1500px;
    height: 100px;
    background-color: yellow;
    margin-left: 240px;
}

#content {
    width: 1500px;
    height: 850px;
    background-color: blue;
    margin-left: 240px;
}

#footer {
    width: 2000px;
    height: 350px;
    background-color: #00a087;
}


#sideNav {
    margin-left: 110px;
    width: 130px;
    float: left;
    display: inline;
    padding: 0;
    max-height: 1900px;
    background-color: #00a087;
}

.menu {
    line-height: 48px;
    border-bottom: 1px solid black;
    color: #fff;
    border: 1px initial black;
    border-left: 1px solid black;
    display: block;
}

ul {
    list-style-type: none;
    margin: 0;
    padding: 0.5em;
}

a {
    text-decoration: none;
    font-size: 1.1em;
}

    a:hover {
        background-color: #fff;
    }

#lazy {
    line-height: 650px;
}

<header id="navbar">2222222222222222222222222222</header>
<div id="toprow">djksadkd</div>
<div id="sideNav">
    <ul>
        <li><a class="menu" href="#"></a></li>
        <li><a class="menu" href="#">Account</a></li>
        <li><a class="menu" href="#">Live Events </a></li>
        <li><a class="menu" href="#">Football</a></li>
        <li><a class="menu" href="#">Baseball</a></li>
        <li><a class="menu" href="#">Soccer</a></li>
        <li><a class="menu" href="#">Basketball</a></li>
        <li><a class="menu" href="#">Hockey</a></li>
        <li><a class="menu" href="#">MMA</a></li>
        <li><a class="menu" href="#">eSports</a></li>
        <li><a class="menu" href="#">Tennis</a></li>
        <li><a class="menu" href="#">Cricket</a></li>
        <li><a class="menu" href="#">Golf</a></li>
        <li><a class="menu" href="#">Badminton</a></li>
        <li><a class="menu" href="#">Handball</a></li>
        <li><a class="menu" href="#">Rugby</a></li>
        <li><a class="menu" href="#">Snooker</a></li>
        <li><a class="menu" href="#">Table Tennis</a></li>
        <li><a class="menu" href="#">Volleyball</a></li>
        <li><a id="lazy" href="#"><font color="#00a087">LAZYSOLUTION</font></a></li>
    </ul>
</div>
<div id="largeBox">
    <div style="text-align: center;">
        <a href="final.html">
            <button type="button" id="topBtn">Sign Up Now</button></a>
    </div>
    <div id="botTopLeft">
        <h1>OUR
            <br>
            PROMOTIONS</h1>
    </div>
    <div id="botRightBox"></div>
    <div class="clearFix"></div>
</div>
<div id="row"></div>
<div id="content"></div>
<div id="footer">...</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

如果我理解正确,为什么不能将按钮插入#botTopLeft div?

&#13;
&#13;
.button {
    display: inline-block;
    outline: none;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    font: 20px;
    padding: .5em 2em .55em;
    -webkit-border-radius: .5em;
    -moz-border-radius: .5em;
    border-radius: .5em;
}

h1 {
    font-size: 4em;
}

header {
    position: fixed;
    top: 0;
    left: 0;
    width: 1640px;
    margin-left: 110px;
    height: 50px;
    background-color: #00a087;
}

#toprow {
    position: fixed;
    width: 100%;
    height: 35px;
    top: 0;
    left: 0;
    margin: 0;
    padding: 0;
    background-color: #00a087;
    margin-top: 50px;
}

body {
    font-family: 'Oswald', sans-serif;
    background-color: #fff;
}

.clearFix {
    clear: both;
}

#largeBox {
    margin-top: 85px;
    width: 750px;
    height: 950px;
    background-color: red;
    margin-left: 240px;
    background: url('football2.jpg');
}

#botRightBox {
    width: 750px;
    height: 475px;
    background-color: green;
    margin-left: 750px;
}

#botTopLeft {
    width: 750px;
    height: 475px;
    background-color: pink;
    margin-left: 750px;
    float: right;
}

#row {
    width: 1500px;
    height: 100px;
    background-color: yellow;
    margin-left: 240px;
}

#content {
    width: 1500px;
    height: 850px;
    background-color: blue;
    margin-left: 240px;
}

#footer {
    width: 2000px;
    height: 350px;
    background-color: #00a087;
}


#sideNav {
    margin-left: 110px;
    width: 130px;
    float: left;
    display: inline;
    padding: 0;
    max-height: 1900px;
    background-color: #00a087;
}

.menu {
    line-height: 48px;
    border-bottom: 1px solid black;
    color: #fff;
    border: 1px initial black;
    border-left: 1px solid black;
    display: block;
}

ul {
    list-style-type: none;
    margin: 0;
    padding: 0.5em;
}

a {
    text-decoration: none;
    font-size: 1.1em;
}

    a:hover {
        background-color: #fff;
    }

#lazy {
    line-height: 650px;
}

/* ADD THIS STYLE */
.button-wrapper {
  text-align:center;
}
&#13;
<header id="navbar">2222222222222222222222222222</header>
<div id="toprow">djksadkd</div>
<div id="sideNav">
    <ul>
        <li><a class="menu" href="#"></a></li>
        <li><a class="menu" href="#">Account</a></li>
        <li><a class="menu" href="#">Live Events </a></li>
        <li><a class="menu" href="#">Football</a></li>
        <li><a class="menu" href="#">Baseball</a></li>
        <li><a class="menu" href="#">Soccer</a></li>
        <li><a class="menu" href="#">Basketball</a></li>
        <li><a class="menu" href="#">Hockey</a></li>
        <li><a class="menu" href="#">MMA</a></li>
        <li><a class="menu" href="#">eSports</a></li>
        <li><a class="menu" href="#">Tennis</a></li>
        <li><a class="menu" href="#">Cricket</a></li>
        <li><a class="menu" href="#">Golf</a></li>
        <li><a class="menu" href="#">Badminton</a></li>
        <li><a class="menu" href="#">Handball</a></li>
        <li><a class="menu" href="#">Rugby</a></li>
        <li><a class="menu" href="#">Snooker</a></li>
        <li><a class="menu" href="#">Table Tennis</a></li>
        <li><a class="menu" href="#">Volleyball</a></li>
        <li><a id="lazy" href="#"><font color="#00a087">LAZYSOLUTION</font></a></li>
    </ul>
</div>
<div id="largeBox">
    <!--REPLACE THIS <div style="text-align: center">-->
    <div id="botTopLeft">
      <div class="button-wrapper">
        <a href="final.html">
            <button type="button" id="topBtn">Sign Up Now</button></a>
      </div>
        <h1>OUR
            <br>
            PROMOTIONS</h1>
    </div>
    <div id="botRightBox"></div>
    <div class="clearFix"></div>
</div>
<div id="row"></div>
<div id="content"></div>
<div id="footer">...</div>
&#13;
&#13;
&#13;

备注:

  1. 您不会将button放入a标记。如果您想要使用button样式链接,请使用css
  2. 设置样式
  3. 您需要使用a而不是</a>关闭<a>代码。
  4. 您无法设置float:bottom right。您可以将float设置为rightleft - 而不是bottom,而不是多个。