2017-08-09 61 views
-1

我試圖對準section元素通過應用display: inline-block;屬性如下所示CSS顯示內嵌屬性不是爲我工作

enter image description here

在一排,這是我看到

enter image description here

由於某種原因,我似乎無法得到它的工作。我已經在下面包含了HTML和CSS代碼。

如果有人可以請教諮詢,這將是很大的幫助。

body { 
 
\t background-color: #edeff2; 
 
\t margin: 25px; 
 
} 
 

 
header { 
 
\t margin-top: 15px; 
 
\t padding-bottom: 8px; 
 
\t padding-top: 8px; 
 
\t background-color: #b8babc; 
 
\t text-align: center; 
 
\t color: #111; font-family: 'Helvetica Neue', sans-serif; font-size: 18px; font-weight: bold; letter-spacing: -1px; line-height: 1; text-align: center; 
 
\t /*I copied the above style from https://wdexplorer.com/20-examples-beautiful-css-typography-design/ */ 
 
} 
 

 
nav { 
 
\t padding-bottom: 5px; 
 
} 
 

 
a { 
 
\t text-decoration: none; 
 
} 
 

 
a:hover { 
 
\t border: 1px solid; 
 
} 
 

 
h2 { 
 
\t color: #111; font-family: 'Helvetica Neue', sans-serif; font-size: 20px; font-weight: bold; letter-spacing: -1px; line-height: 1; 
 

 
} 
 

 
section { 
 
\t display: inline-block; 
 
\t padding-top: 30px; 
 
\t padding-bottom: 30px; 
 
\t float: left; 
 
\t margin-right: 2%; 
 
} 
 

 
ul { 
 
    list-style-type: none; 
 
} 
 

 
progress { 
 
    color: #5ff4ef; 
 
    font-size: .7em; 
 
    line-height: 1.5em; 
 
    text-indent: .5em; 
 
    width: 15em; 
 
    height: 1.8em; 
 
    border: 1px solid #5ff4ef; 
 
    background: #5ff4ef; 
 
} 
 

 
details { 
 
\t font-size: 1.2em; 
 
\t color: #028402; 
 
} 
 

 
details p { 
 
\t font-style: italic; 
 
} 
 

 
footer { 
 
\t background-color: #b8babc; 
 
\t font-size: 1.2em; 
 
\t clear: both; 
 
} 
 

 
img { 
 
\t width: 105px; 
 
}
<!DOCTYPE html> 
 
<html lang="en"> 
 
<head> 
 
\t <meta charset="UTF-8"> 
 
\t <title>Colleen</title> 
 
\t <!-- ADD a LINK TO YOUR STYLE SHEET HERE!! --> 
 
\t <link rel="stylesheet" href="style.css"> 
 
</head> 
 

 
<body> 
 
\t <header> 
 
    \t <h1>ALOK</h1> 
 
\t \t \t <nav> 
 
\t \t \t  <a href = "">One</a> 
 
\t \t \t  <a href = "">Two</a> 
 
\t \t \t  <a href = "">Three</a> 
 
\t \t \t  <a href = "">Four</a> 
 
\t \t \t </nav> 
 
\t </header> 
 
\t <section class="half"> 
 
\t \t  <h2>Favorite Foods</h2> 
 
\t \t  <ul> 
 
\t \t \t  <li>Apples</li> 
 
\t \t \t  <li>Pizza</li> 
 
\t \t \t  <li>Crab</li> 
 
\t \t \t  <li>Chocolate Cake</li> 
 
\t \t  </ul> 
 
\t </section> 
 
    
 
\t \t <section class="half"> 
 
\t \t  <h2>Achievements</h2> 
 
     \t \t <p> \t Progress in this course (100%)</100%><progress value = "1"></progress><br/>Progress in the Specialization (20%) <progress max = "5" value = "1"></progress><br/> \t \t Progress in life goals (67%)<progress max = "100" value = "67"></progress></p> 
 
    \t \t </section> 
 

 
    \t \t <section class = "whole"> 
 
\t \t  <h2>More About Me</h2> 
 
\t \t  <details open><summary>My Childhood</summary> 
 
    \t \t <p>I grew up in Bangalore India. I lived near a Mango Grove and I used to steal a lot of them. </details> 
 
\t \t </section> 
 
\t 
 
    \t \t <footer> 
 
\t \t  <p><img src = "http://www.intro-webdesign.com/images/newlogo.png" alt = "logo"/> This page was created by your name &amp; Colleen van Lent. To learn more about web design, visit <a href="http://www.intro-webdesign.com">Intro to Web Design</a>.</p> 
 
\t </footer> 
 

 
</body> 
 

 
</html>

+0

我沒有看到一半或全部類別。 –

+0

它看起來對我很有用。你想要發生什麼? –

+0

我想要「更多關於我」與「最喜歡的食物」和「成就」排在同一行 –

回答

1

我已在你的HTML和部分標籤的CSS的一些變化。它會爲你工作

section.half { 
 
\t display: inline-block; 
 
\t padding-top: 30px; 
 
\t padding-bottom: 30px; 
 
\t float: left; 
 
\t margin-right: 2%; 
 
} 
 

 
ul { 
 
    list-style-type: none; 
 
}
\t <section class="half"> 
 
\t \t  <h2>Favorite Foods</h2> 
 
\t \t  <ul> 
 
\t \t \t  <li>Apples</li> 
 
\t \t \t  <li>Pizza</li> 
 
\t \t \t  <li>Crab</li> 
 
\t \t \t  <li>Chocolate Cake</li> 
 
\t \t  </ul> 
 
\t </section> 
 
    
 
\t \t <section class="half"> 
 
\t \t  <h2>Achievements</h2> 
 
     \t \t <p> \t Progress in this course (100%)</100%><progress value = "1"></progress><br/>Progress in the Specialization (20%) <progress max = "5" value = "1"></progress><br/> \t \t Progress in life goals (67%)<progress max = "100" value = "67"></progress></p> 
 
    \t \t </section> 
 

 
    \t \t <section class = " half whole"> 
 
\t \t  <h2>More About Me</h2> 
 
\t \t  <details open><summary>My Childhood</summary> 
 
    \t \t <p>I grew up in Bangalore India. I lived near a Mango Grove and I used to steal a lot of them. </details> 
 
\t \t </section>

+0

這也適用。謝謝。 –

2

您需要添加一個width,像30%

body { 
 
\t background-color: #edeff2; 
 
\t margin: 25px; 
 
} 
 

 
header { 
 
\t margin-top: 15px; 
 
\t padding-bottom: 8px; 
 
\t padding-top: 8px; 
 
\t background-color: #b8babc; 
 
\t text-align: center; 
 
\t color: #111; font-family: 'Helvetica Neue', sans-serif; font-size: 18px; font-weight: bold; letter-spacing: -1px; line-height: 1; text-align: center; 
 
\t /*I copied the above style from https://wdexplorer.com/20-examples-beautiful-css-typography-design/ */ 
 
} 
 

 
nav { 
 
\t padding-bottom: 5px; 
 
} 
 

 
a { 
 
\t text-decoration: none; 
 
} 
 

 
a:hover { 
 
\t border: 1px solid; 
 
} 
 

 
h2 { 
 
\t color: #111; font-family: 'Helvetica Neue', sans-serif; font-size: 20px; font-weight: bold; letter-spacing: -1px; line-height: 1; 
 

 
} 
 

 
section { 
 
\t display: inline-block; 
 
    width: 30%; 
 
\t padding-top: 30px; 
 
\t padding-bottom: 30px; 
 
\t float: left; 
 
\t margin-right: 2%; 
 
} 
 

 
ul { 
 
    list-style-type: none; 
 
} 
 

 
progress { 
 
    color: #5ff4ef; 
 
    font-size: .7em; 
 
    line-height: 1.5em; 
 
    text-indent: .5em; 
 
    width: 15em; 
 
    height: 1.8em; 
 
    border: 1px solid #5ff4ef; 
 
    background: #5ff4ef; 
 
} 
 

 
details { 
 
\t font-size: 1.2em; 
 
\t color: #028402; 
 
} 
 

 
details p { 
 
\t font-style: italic; 
 
} 
 

 
footer { 
 
\t background-color: #b8babc; 
 
\t font-size: 1.2em; 
 
\t clear: both; 
 
} 
 

 
img { 
 
\t width: 105px; 
 
}
<!DOCTYPE html> 
 
<html lang="en"> 
 
<head> 
 
\t <meta charset="UTF-8"> 
 
\t <title>Colleen</title> 
 
\t <!-- ADD a LINK TO YOUR STYLE SHEET HERE!! --> 
 
\t <link rel="stylesheet" href="style.css"> 
 
</head> 
 

 
<body> 
 
\t <header> 
 
    \t <h1>ALOK</h1> 
 
\t \t \t <nav> 
 
\t \t \t  <a href = "">One</a> 
 
\t \t \t  <a href = "">Two</a> 
 
\t \t \t  <a href = "">Three</a> 
 
\t \t \t  <a href = "">Four</a> 
 
\t \t \t </nav> 
 
\t </header> 
 
\t <section class="half"> 
 
\t \t  <h2>Favorite Foods</h2> 
 
\t \t  <ul> 
 
\t \t \t  <li>Apples</li> 
 
\t \t \t  <li>Pizza</li> 
 
\t \t \t  <li>Crab</li> 
 
\t \t \t  <li>Chocolate Cake</li> 
 
\t \t  </ul> 
 
\t </section> 
 
    
 
\t \t <section class="half"> 
 
\t \t  <h2>Achievements</h2> 
 
     \t \t <p> \t Progress in this course (100%)</100%><progress value = "1"></progress><br/>Progress in the Specialization (20%) <progress max = "5" value = "1"></progress><br/> \t \t Progress in life goals (67%)<progress max = "100" value = "67"></progress></p> 
 
    \t \t </section> 
 

 
    \t \t <section class = "whole"> 
 
\t \t  <h2>More About Me</h2> 
 
\t \t  <details open><summary>My Childhood</summary> 
 
    \t \t <p>I grew up in Bangalore India. I lived near a Mango Grove and I used to steal a lot of them. </details> 
 
\t \t </section> 
 
\t 
 
    \t \t <footer> 
 
\t \t  <p><img src = "http://www.intro-webdesign.com/images/newlogo.png" alt = "logo"/> This page was created by your name &amp; Colleen van Lent. To learn more about web design, visit <a href="http://www.intro-webdesign.com">Intro to Web Design</a>.</p> 
 
\t </footer> 
 

 
</body> 
 

 
</html>

+0

這可以工作。謝謝。 –