2016-10-24 3 views
0

Ich weiß, dass ein Rand anstelle des horizontalen Linienetiketts (hr) verwendet werden kann. In diesem Fall möchte ich jedoch nicht, dass die Leitung 100% Breite aufnimmt; die aktuellen div tut und so würde die Grenze, wenn ich in einen Rahmen setzen war.Horizontale Linie, die weniger als 100% Breite einnimmt

So würde Ich mag eine horizontale Linie setzen (hr) mit 80% Breite aber es zeigt nicht auf, und speziell die Breite ist nicht 80%. Der Ort, an dem ich es einfügen möchte, ist die erste Zeile nach der Klasse bottom in meinem Code.

Meine Absicht ist es, die horizontale Linie (hr) direkt über die Cola (<p class="center1">Cola</p>) auf der Seite zu setzen. Auch das Styling scheint hier für die hr Klasse nicht zu funktionieren; versuche, eine Breite und eine Farbe darauf zu setzen.

* { 
 
    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

Die Eltern Ihrer Linie ist das div 'sam', das eine Breite von 134px hat. Wenn Sie die "hr" -Breite auf 80% setzen, geben Sie an, dass sie 80% von 134 px beträgt. – Santi

Antwort

1

können Sie ändern Ihre CSS, wie folgend:

hinzufügen Breite 100% der Klasse sam:

.sam { 
    width: 100%; 
} 

hinzufügen zur Klasse Zentrierung style1:

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

Sie haben Fehler im Markup

Wenn Sie horizantal Linie 100% Breite

Änderung <hr class="style1">-<hr class="style1"/>

wollen Dies behebt es

+2

Direktes Zitat von OP: "...In diesem Fall ** möchte ich nicht, dass die Zeile 100% Breite einnimmt. ** " – Santi

+0

Wenn Sie etwas anderes als den XHTML DOCTYPE verwenden, müssen Sie selbstschließende Tags nicht schließen. –

1

Ihr hr ist in einem Container, der eine kleinere Breite hat (div .sam), also ist die Breite 80% dieses Containers. bewegen Sie es einfach in den HTML-Code nach oben, über dem .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

Oh thanks. Ich habe eine Frage, also bevor ich das gemacht habe, habe ich es versehentlich vor 'sam' gestellt, aber nach 'bottom' und es komplett durch alles in den Wahnsinn. Obwohl ich weiß, dass es falsch ist, warum hat es das getan? Ich habe es mit Ihrer Version korrigiert, aber ich möchte nur wissen, warum dieser Fehler so ist, wie er ist.-Danke –

+0

Wie ich geschrieben habe: Die 'hr' war in der' .sam'div, also war sie darin zentriert div, und es waren nur 80% der DIVs breit. – Johannes

1

Die hr innen .sam div ist, die nicht die volle Breite erhält. Deshalb sehen Sie die hr mit kleinen width (aber es nimmt 80% Breite).

.sam{ 
    width:100% 
} 

Dies wird das Problem beheben.

0

versuchen es

<hr align="left" width="50%"> 
Verwandte Themen