2016-10-24 36 views
0

我知道可以使用邊框代替水平線標記(hr)。但是,在這種情況下,我不希望線路佔用100%寬度;當前div不和所以想如果我是把邊框的邊框。水平線佔據小於100%的寬度

所以我想提出一個水平線(hr)與80%的寬度,但它沒有顯示出來,還有專門的寬度不是80%。我想插入它的地方是代碼中bottom類之後的第一行。

我的意圖是將水平線(hr)放在頁面上的可樂<p class="center1">Cola</p>)的正上方。此外,造型在hr類中似乎不起作用;試圖把它的寬度和顏色。

* { 
 
    margin: 0; 
 
} 
 
body { 
 
    background-color: green; 
 
} 
 
html, 
 
body { 
 
    height: 100%; 
 
} 
 
#subnav { 
 
    height: 10%; 
 
    text-align: center; 
 
} 
 
#subnav ul { 
 
    list-style-type: none; 
 
    margin: 0; 
 
    padding: 0; 
 
    overflow: hidden; 
 
    background-color: red; 
 
    text-align: center; 
 
    width: 100%; 
 
    font-weight: bold; 
 
} 
 
#subnav li { 
 
    display: inline-block; 
 
} 
 
#subnav li a { 
 
    display: block; 
 
    color: white; 
 
    text-align: center; 
 
    padding: 14px 16px; 
 
    text-decoration: none; 
 
} 
 
#subnav li a:hover { 
 
    color: yellow; 
 
} 
 
#subnav li a:active { 
 
    color: yellow; 
 
} 
 
#bigwrap { 
 
    height: 100%; 
 
} 
 
.container { 
 
    display: flex; 
 
    position: relative; 
 
    flex-flow: row wrap; 
 
    justify-content: center; 
 
    align-items: stretch; 
 
    min-height: 100vh; 
 
    width: 80%; 
 
    margin: 0 auto; 
 
    background-color: white; 
 
    font-size: 20px; 
 
} 
 
.top { 
 
    display: flex; 
 
    flex-flow: row wrap; 
 
    justify-content: flex-start; 
 
    align-items: center; 
 
} 
 
.bottom { 
 
    display: flex; 
 
    flex-flow: row wrap; 
 
    justify-content: space-around; 
 
    align-items: flex-start; 
 
} 
 
.bottom { 
 
    flex: 0 0 100%; 
 
    height: 50%; 
 
} 
 
hr.style1 { 
 
    border-top: 1px solid #8c8b8b; 
 
    width: 80%; 
 
} 
 
.top { 
 
    flex: 0 0 100%; 
 
    height: 50%; 
 
} 
 
.topa { 
 
    display: flex; 
 
    flex-flow: column wrap; 
 
    justify-content: center; 
 
    align-items: flex-start; 
 
    margin-left: 3%; 
 
    width: 45%; 
 
    height: 100%; 
 
} 
 
.topb { 
 
    display: flex; 
 
    flex-flow: row wrap; 
 
    justify-content: center; 
 
    align-content: center; 
 
    width: 50%; 
 
    height: 100%; 
 
} 
 
li { 
 
    list-style-type: none; 
 
    font-size: 18px; 
 
} 
 
.advisory { 
 
    background-color: white; 
 
    margin: auto; 
 
    width: 100%; 
 
} 
 
#advisory ul li { 
 
    margin-bottom: 2%; 
 
} 
 
.center { 
 
    text-align: center; 
 
} 
 
.center1 { 
 
    text-align: center; 
 
    color: green; 
 
    font-size: 28px; 
 
} 
 
.tpoint { 
 
    font-size: 24px; 
 
    color: orange; 
 
}
<div class="container"> 
 
    <div id="subnav"> 
 
    <ul> 
 
     <li> <a href="#">Sam </a> 
 
     </li> 
 
     <li> <a href="#">Sam </a> 
 
     </li> 
 
     <li> <a class="active" href="#">Corn </a> 
 
     </li> 
 
     <li> <a href="#">Sam </a> 
 
     </li> 
 
     <li> <a href="#">Sam </a> 
 
     </li> 
 
     <li> <a href="#">Sam </a> 
 
     </li> 
 
     <li> <a href="#">Sam </a> 
 
     </li> 
 
    </ul> 
 
    </div> 
 
    <div class="top"> 
 
    <div class="topa"> 
 
     <img src="ham.jpg" width="209" height="205" alt="Picture of kid" /> 
 
     <img src="bacon.jpg" width="209" height="205" alt="Picture of kid\" /> 
 
    </div> 
 
    <div class="topb"> 
 
     <h2> Sams </h2> 
 
     <p>Sample sentence this Sample sentence this Sample sentence this Sample sentence this Sample sentence this Sample sentence this Sample sentence this Sample sentence this Sample sentence this Sample sentence this Sample sentence this Sample sentence 
 
     this Sample sentence this Sample sentence this Sample sentence this Sample sentence this Sample sentence this Sample sentence this Sample sentence this Sample sentence this Sample sentence this Sample sentence this Sample sentence this Sample 
 
     sentence this Sample sentence this Sample sentence this Sample sentence this</p> 
 
    </div> 
 
    </div> 
 
    <div class="bottom"> 
 
    <div class="sam"> 
 
     <hr class="style1"> 
 
     <p class="center1">Cola</p> 
 
     <p class="center tpoint">Sample</p> 
 
     <ul> 
 
     <li>Sample 
 
      <ul> 
 
      <li>Sample</li> 
 
      <li>rsam</li> 
 
      </ul> 
 
     </li> 
 
     <li>san 
 
      <ul> 
 
      <li>sam</li> 
 
      <li>sam</li> 
 
      </ul> 
 
     </li> 
 
     <li>sam 
 
      <ul> 
 
      <li>sam</li> 
 
      <li>sam</li> 
 
      </ul> 
 
     </li> 
 
     <li>sam 
 
      <ul> 
 
      <li>sam</li> 
 
      <li>sam</li> 
 
      </ul> 
 
     </li> 
 
     <li>sam 
 
      <ul> 
 
      <li>sam</li> 
 
      <li>sam</li> 
 
      </ul> 
 
     </li> 
 
     </ul> 
 
     <p class="center tpoint">The sam</p> 
 
     <ul> 
 
     <li>sam 
 
      <ul> 
 
      <li>sam</li> 
 
      </ul> 
 
     </li> 
 
     <li>sam</li> 
 
     <li>sam</li> 
 
     <li>sam</li> 
 
     <li>sam</li> 
 
     <li>sam</li> 
 
     <li>sam</li> 
 
     <li>sam</li> 
 
     </ul> 
 
     <p class="center tpoint">Eggs</p> 
 
     <ul> 
 
     <li>sam 
 
      <ul> 
 
      <li>san</li> 
 
      </ul> 
 

 
     </li> 
 
     <li>Eri 
 
      <ul> 
 
      <li>Sam</li> 
 
      </ul> 
 
     </li> 
 
     </ul> 
 
    </div> 
 
    </div> 
 
</div>

+1

你的線路的父母是div'sam',它的寬度爲134px。通過將「hr」寬度設置爲80%,您可以告訴它是134px的80%。 – Santi

回答

1

您可以修改CSS如下:

添加寬度100%到類sam

.sam { 
    width: 100%; 
} 

添加中心到類style1

.style1 { 
    width: 80%; 
    margin-left: auto; 
    margin-right: auto; 
} 
-1

你有錯誤的標記

如果你想horizantal線寬度爲100%

變化<hr class="style1"><hr class="style1"/>

這修復它

+2

OP的直接引用:「...在這種情況下**我不希望該行佔用100%的寬度**「 – Santi

+0

另外,當使用除XHTML DOCTYPE以外的任何內容時,您不必關閉自閉標記 –

1

您的hr位於寬度較小的容器內(div .sam),因此其寬度爲該容器的80%。只要將它在HTML代碼中,.bottom DIV以上:

* { 
 
margin: 0; 
 
} 
 
body { 
 
\t background-color: green; 
 
} 
 
html, 
 
body { 
 
\t height: 100%; 
 
} 
 

 
#subnav { 
 
\t height: 10%; 
 
\t text-align: center; 
 
} 
 
#subnav ul { 
 
\t list-style-type: none; 
 
\t margin: 0; 
 
\t padding: 0; 
 
\t overflow: hidden; 
 
\t background-color: red; 
 
\t text-align: center; 
 
\t width: 100%; 
 
\t font-weight: bold; 
 
} 
 
#subnav li { 
 
\t display: inline-block; 
 
} 
 
#subnav li a { 
 
\t display: block; 
 
\t color: white; 
 
\t text-align: center; 
 
\t padding: 14px 16px; 
 
\t text-decoration: none; 
 
} 
 
#subnav li a:hover { 
 
\t color: yellow; 
 
} 
 
#subnav li a:active { 
 
\t color: yellow; 
 
} 
 
#bigwrap { 
 
\t height: 100%; 
 
} 
 
.container { 
 
    display: flex; 
 
    position: relative; 
 
    flex-flow: row wrap; 
 
    justify-content: center; 
 
    align-items: stretch; 
 
    min-height: 100vh; 
 
    width: 80%; \t 
 
\t margin: 0 auto; 
 
\t background-color: white; 
 
\t font-size: 20px; 
 
} 
 

 
.top { 
 
\t display: flex; 
 
\t flex-flow: row wrap; 
 
\t justify-content: flex-start; 
 
\t align-items: center; \t 
 
} 
 
.bottom { 
 
\t display: flex; 
 
\t flex-flow: row wrap; 
 
\t justify-content: space-around; 
 
\t align-items: flex-start; 
 
} 
 
.bottom { 
 
\t flex: 0 0 100%; 
 
\t height: 50%; 
 
} 
 
hr.style1{ 
 
\t border-top: 1px solid #8c8b8b; 
 
\t width: 80%; 
 
} 
 
.top { 
 
\t flex: 0 0 100%; 
 
\t height: 50%; \t 
 
} 
 
.topa { 
 
\t display: flex; 
 
\t flex-flow: column wrap; 
 
\t justify-content: center; 
 
\t align-items: flex-start; 
 
\t margin-left: 3%; 
 
\t width: 45%; 
 
\t height: 100%; 
 
} 
 
.topb { 
 
\t display: flex; 
 
\t flex-flow: row wrap; 
 
\t justify-content: center; 
 
\t align-content: center; 
 
\t width: 50%; 
 
\t height: 100%; 
 
} 
 
\t 
 
li { 
 
list-style-type: none; 
 
font-size: 18px; 
 
} 
 
.advisory { 
 
\t background-color: white; 
 
\t margin: auto; 
 
\t width: 100%; \t 
 
} 
 
#advisory ul li { 
 
\t margin-bottom: 2%; 
 
} 
 
.center { 
 
\t text-align: center; 
 
} 
 
.center1 { 
 
\t text-align: center; 
 
\t color: green; 
 
\t font-size: 28px; 
 
} 
 
.tpoint { 
 
\t font-size: 24px; 
 
\t color: orange; 
 
}
<div class="container"> 
 
    \t <div id="subnav"> 
 
      \t <ul> 
 
    \t \t \t <li> <a href="#">Sam </a></li> 
 
     \t \t <li> <a href="#">Sam </a></li> 
 
    \t \t \t <li> <a class="active" href="#">Corn </a></li> 
 
    \t \t \t <li> <a href="#">Sam </a></li> 
 
      \t <li> <a href="#">Sam </a></li> 
 
       <li> <a href="#">Sam </a></li> 
 
       <li> <a href="#">Sam </a></li> 
 
    \t \t </ul> 
 
     </div> 
 
    \t <div class="top"> 
 
     \t <div class="topa"> 
 
    \t  \t \t <img src="ham.jpg" width="209" height="205" alt="Picture of kid" /> 
 
    \t \t \t \t <img src="bacon.jpg" width="209" height="205" alt="Picture of kid\" /> 
 
      </div>   
 
     \t <div class="topb"> 
 
      \t <h2> Sams </h2> 
 
      \t <p>Sample sentence this Sample sentence this Sample sentence this Sample sentence this 
 
       Sample sentence this Sample sentence this Sample sentence this Sample sentence this 
 
       Sample sentence this Sample sentence this Sample sentence this Sample sentence this 
 
       Sample sentence this Sample sentence this Sample sentence this Sample sentence this 
 
       Sample sentence this Sample sentence this Sample sentence this Sample sentence this 
 
       Sample sentence this Sample sentence this Sample sentence this Sample sentence this 
 
       Sample sentence this Sample sentence this Sample sentence this </p> 
 
     \t </div> 
 
     </div> 
 
      \t <hr class="style1"> 
 
     <div class="bottom"> 
 
     \t <div class="sam"> 
 
      \t \t <p class="center1"> Cola </p> 
 
      \t \t <p class="center tpoint"> Sample </p> 
 
       <ul> 
 
       \t <li> Sample 
 
        \t <ul> 
 
         \t <li> Sample </li> 
 
          <li> rsam </li>      
 
         </ul> 
 
        </li> 
 
        <li> san 
 
        \t <ul> 
 
         \t <li> sam </li> 
 
          <li> sam </li> 
 
         </ul> 
 
        </li> 
 
        <li> sam 
 
        \t <ul> 
 
         \t <li> sam </li> 
 
          <li> sam </li> 
 
         </ul> 
 
        </li> 
 
        <li> sam 
 
        \t <ul> 
 
         \t <li> sam </li> 
 
          <li> sam </li> 
 
         </ul> 
 
        </li> 
 
        <li> sam 
 
        \t <ul> 
 
         \t <li> sam </li> 
 
          <li> sam </li> 
 
         </ul> 
 
        </li> 
 
       </ul> 
 
      <p class="center tpoint"> The sam</p> 
 
       <ul> 
 
       \t <li> sam 
 
        \t <ul> 
 
         \t <li> sam </li> 
 
         </ul> 
 
        </li> 
 
        <li> sam </li> 
 
        <li> sam </li> 
 
        <li> sam </li> 
 
        <li> sam </li> 
 
        <li> sam </li> 
 
        <li> sam </li> 
 
        <li> sam </li> \t 
 
       </ul> 
 
       <p class="center tpoint" > Eggs </p> 
 
       <ul> 
 
       \t <li> sam 
 
        \t <ul> 
 
         \t <li> san </li> 
 
         </ul> 
 
        
 
        </li> 
 
        <li> Eri 
 
        \t <ul> 
 
         \t <li> Sam </li> 
 
         </ul> 
 
        </li> 
 
       </ul> 
 
      </div> 
 
     </div> 
 
    \t </div>

+0

噢,謝謝。我有一個問題,所以在我做之前,我不小心把它放在'sam'之前,但是在'bottom'之後,它完全通過所有的東西變成怪人,儘管我知道這是錯誤的,爲什麼它會這樣做呢? t居中我糾正了它使用你的版本,但我只想知道爲什麼這種錯誤是這樣的 - 感謝 –

+0

正如我寫道:'hr'是'.sam'的div,所以它被集中在裏面div,只有DIV寬度的80%。 – Johannes

1

hr裏面.sam DIV這是沒有得到充分的寬度。這就是爲什麼你看到hr與小width(但它佔80%的寬度)。

.sam{ 
    width:100% 
} 

這將解決問題。

0

試試它

<hr align="left" width="50%"> 
相關問題