簡體   English   中英

如何使用CSS在html頁面中添加3列?

[英]how can i add 3 columns in an html page using css?

我想在html頁面中添加3個垂直列:

#navbar {width:15%}

#content {width:70%}

#right {width:15%}

這是我過去常用的樣式表:

 #container { position: fixed; float: none; overflow: visible; height: auto; width: 100%; border: none; margin-left: 0%; margin-right: 0%; padding-left: 0%; padding-right: 0%; } #navbar { float: left; display: block; position: relative; text-align: justify; width: 15%; background: black; } #content { float: none; display: block; position: static; background-size: 100%; width: 75%; margin-left: 15%; right: 10%; bottom: 0; padding: 0; } #right { float: right; display: block; position: static; text-align: justify; width: 10%; background: black; left: 85%; } .page { position: fixed; margin-left: 0%; margin-right: 0%; padding-left: 0%; padding-right: 0%; } 
 <div class="page"> <div id="container"> <div id="navbar"> navbar </div> <div id="content"> content </div> <div id="right"> <form action="SessionDestroy" method="POST"> right panel </form> </div> </div> </div> 

即使邊距設置為0%,每次運行時都運行此代碼。 主顯示器和container之間有一個空間。

在Web視圖中顯示頁面

顯示器和容器之間的空間

那么,我該如何解決這個問題呢?

HTML

<body>
<div class="page">
        <div id = "container">
            <div id = "navbar">
                navbar
            </div>
            <div id = "content">
                content
            </div>
            <div id = "right">
                <form action="SessionDestroy" method="POST">
                    right panel
                </form>
            </div>
        </div>
    </div>
</body>

CSS

    body{margin:0px;}
#container{
            position: fixed;
            float:none;
            overflow: visible;
            height: auto;
            width: 100%;
            border: none;
            margin-left: 0%;
            margin-right: 0%;
            padding-left: 0%;
            padding-right: 0%;

    }
    #navbar{
            float: left;
            display:block;
            position:relative;
            text-align: justify;
            width: 15%;
            background: black;
    }


    #content{
        float: left;
        display: block;
        position: static;
        background-size:100%;
        width: 70%;      
        right: 10%;
        bottom: 0;
        padding: 0;
        text-align:center
}

#right{
        float: right;
        display:block;
        position: static;
        text-align: justify;
        width:10%;
        background: black;
        left: 85%;
}
.page{
        position: fixed;
        margin-left: 0%;
        margin-right: 0%;
        padding-left: 0%;
        padding-right: 0%;
}

問題似乎是margin: 8pxmargin: 8px由於容器的可用面積是100% - 8px,這就是為什么有8px的差距。

嘗試使用body{margin:0px;}

希望這可以幫助。

這會奏效。

#content {
  /*float: none;*/
  display: block;
  float: left;      /* Add this line */
  position: static;
  background-size: 100%;
  width: 75%;
  /*margin-left: 15%;*/
  right: 10%;
  bottom: 0;
  padding: 0;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM