2017-04-08 53 views
0

我正在尝试创建一个Web服务器,该服务器使用node.js而不使用快速或任何其他框架从文件夹提供html,css和jpeg文件。到目前为止,它正在解决一个问题。标题和前几句没有出现。我怎样才能解决它而不触及CSS和HTML?这里是什么样子http://imgur.com/G3LgtVWCSS布局有点偏离(不显示段落和标题)

我的文件夹结构如下所示:

folderName  
├── index.html  
├── style.css  
├── penguin.jpg  
test.js (which contains) 
html, body { 
     height: 100%; 
    } 

    body, h1 { 
     margin: 10px; 
    } 

    body { 
     display: flex; 
     justify-content: center; 
     align-items: center; 
    } 

    main { 
     text-align: center; 
     color: navy; 
    } 

    figcaption { 
     font-size: 1.5em; 
     font-family: cursive; 
     font-size: 0.8em; 
     color: #001125; 
    } 
<!--index.html--> 

<!DOCTYPE html> 
<html> 
    <head> 
     <link rel="stylesheet" href="style.css"/> 
     <title>Penguin</title> 
    </head> 
    <body> 
     <main> 
      <h1>Penguins</h1> 
      <p>Penguins (order Sphenisciformes, family Spheniscidae) are a group of aquatic, flightless birds. They live almost exclusively in the Southern Hemisphere, with only one species, the Galapagos penguin, found north of the equator. Highly adapted for life in the water, penguins have countershaded dark and white plumage, and their wings have evolved into flippers. Most penguins feed on krill, fish, squid and other forms of sealife caught while swimming underwater. They spend about half of their lives on land and half in the oceans. 

    Although almost all penguin species are native to the Southern Hemisphere, they are not found only in cold climates, such as Antarctica. In fact, only a few species of penguin live so far south. Several species are found in the temperate zone, and one species, the Galápagos penguin, lives near the equator..The largest living species is the emperor penguin (Aptenodytes forsteri): on average adults are about 1.1 m (3 ft 7 in) tall and weigh 35 kg (77 lb) or more. The smallest penguin species is the little blue penguin (Eudyptula minor), also known as the fairy penguin, which stands around 40 cm (16 in) tall and weighs 1 kg (2.2 lb). Among extant penguins, larger penguins inhabit colder regions, while smaller penguins are generally found in temperate or even tropical climates (see also Bergmann's rule). Some prehistoric species attained enormous sizes, becoming as tall or as heavy as an adult human. These were not restricted to Antarctic regions; on the contrary, subantarctic regions harboured high diversity, and at least one giant penguin occurred in a region around 2,000 km south of the equator 35 mya, in a climate decidedly warmer than today.</p> 
      <figure> 
       <img src="penguin.jpg" alt="Penguin"/> 
       <figcaption>Adélie penguin (Pygoscelis adeliae) feeding young. Like its relatives, a neatly bi-coloured species with a head marking. </figcaption> 
      </figure> 
     </main> 
    </body> 
</html> 

回答

1

“的标题和前几句没有显示出来,”因为你定义body的显示为flex并居中其内容。

为了您的HTML内容,我觉得flex-direction应该是column(垂直内容布局),而不是默认值row,因此下面的CSS变化将解决这个问题:

body { 
    ... 
    flex-direction: column; 
    justify-content: flex-start; 
} 

html, body { 
 
     height: 100%; 
 
    } 
 
    
 
    body, h1 { 
 
     margin: 10px; 
 
    } 
 
    
 
    body { 
 
     display: flex; 
 
     flex-direction: column; 
 
     justify-content: flex-start; 
 
     align-items: center; 
 
    } 
 
    
 
    main { 
 
     text-align: center; 
 
     color: navy; 
 
    } 
 
    
 
    figcaption { 
 
     font-size: 1.5em; 
 
     font-family: cursive; 
 
    \t font-size: 0.8em; 
 
     color: #001125; 
 
    }
<!--index.html--> 
 

 
<!DOCTYPE html> 
 
<html> 
 
    <head> 
 
     <link rel="stylesheet" href="style.css"/> 
 
     <title>Penguin</title> 
 
    </head> 
 
    <body> 
 
     <main> 
 
      <h1>Penguins</h1> 
 
    \t \t <p>Penguins (order Sphenisciformes, family Spheniscidae) are a group of aquatic, flightless birds. They live almost exclusively in the Southern Hemisphere, with only one species, the Galapagos penguin, found north of the equator. Highly adapted for life in the water, penguins have countershaded dark and white plumage, and their wings have evolved into flippers. Most penguins feed on krill, fish, squid and other forms of sealife caught while swimming underwater. They spend about half of their lives on land and half in the oceans. 
 
    
 
    Although almost all penguin species are native to the Southern Hemisphere, they are not found only in cold climates, such as Antarctica. In fact, only a few species of penguin live so far south. Several species are found in the temperate zone, and one species, the Galápagos penguin, lives near the equator..The largest living species is the emperor penguin (Aptenodytes forsteri): on average adults are about 1.1 m (3 ft 7 in) tall and weigh 35 kg (77 lb) or more. The smallest penguin species is the little blue penguin (Eudyptula minor), also known as the fairy penguin, which stands around 40 cm (16 in) tall and weighs 1 kg (2.2 lb). Among extant penguins, larger penguins inhabit colder regions, while smaller penguins are generally found in temperate or even tropical climates (see also Bergmann's rule). Some prehistoric species attained enormous sizes, becoming as tall or as heavy as an adult human. These were not restricted to Antarctic regions; on the contrary, subantarctic regions harboured high diversity, and at least one giant penguin occurred in a region around 2,000 km south of the equator 35 mya, in a climate decidedly warmer than today.</p> 
 
      <figure> 
 
       <img src="penguin.jpg" alt="Penguin"/> 
 
       <figcaption>Adélie penguin (Pygoscelis adeliae) feeding young. Like its relatives, a neatly bi-coloured species with a head marking. </figcaption> 
 
      </figure> 
 
     </main> 
 
    </body> 
 
</html>

+0

很酷谢谢!现在工作。我认为我的.js文件存在问题 – user7836693

+0

我编辑了问题,因为问题不在我的.js文件中,而是在使用css文件。再次感谢! – user7836693

+0

@ user7836693是你的问题解决了吗?如果是的话,也许你可以“接受”这个答案? – shaochuancs