2016-09-21 62 views
0

我想創建一個3列網頁。如何將標題和段落放在中間欄上?當我在最後一欄中輸入信息時,如何將文本對齊?感謝幫助,謝謝。如何對齊列中的文本?

另外,如何將頁面中間的版權對齊到右側?

*{ 
 
    font-family: Melvetica; 
 
    margin: 0px; 
 
    padding: 0px; 
 
    } 
 

 
body{ 
 
    background-color: #6B6A67; 
 
    }  
 
#container{ 
 
    width: 920px; 
 
    background-color: white; 
 
    padding: 10px; 
 
    margin-left: auto; /*will center your page*/ 
 
    margin-right: auto; /*will center your page*/ 
 
    } 
 
    
 
h1, h2{ 
 
    text-align: center; 
 
    } 
 

 

 

 
li{ 
 
    text-align: center; 
 
    padding: 5px; 
 
    } 
 
h4{ 
 
    padding: 5px; 
 
    text-align: center; 
 
    } 
 

 
/*To style an ID within an ID under it use the parent ID--start with header then call the ID you want to select*/ 
 
#container #header{ 
 
    height: 80px; 
 
    background-color: #ADA9A0; 
 
    padding-top: 20px; 
 
    padding-left: 10px; 
 
    padding-right: 20px; 
 
    margin-bottom: 5px; /*To add empty space to bottom of the element*/ 
 
    } 
 
#container #navigation{ 
 
    margin-top: 5px; 
 
    background-color: #ADA9A0; 
 
    color: white; 
 
    padding-top: 5px; 
 
    padding-bottom: 5px; 
 
    border: 2px solid #ADA9A0; 
 
    }  
 
    
 
#container #content{ 
 
    background-color: #D9D5CE; 
 
    min-height: 300px; 
 
    margin-top: 5px; 
 
    margin-bottom: 5px; /*To add empty space to bottom of the element*/ 
 
    } 
 
    
 
#container #content #sidebar1{ 
 
    background-color: #ADA9A0; 
 
    float: left; 
 
    width: 200px; 
 
    min-height: 300px; 
 
    margin-bottom: 3px; 
 
    }  
 
#container #content #column1{ 
 
    background-color: white; 
 
    min-height: 300px; 
 
    margin-bottom: 3px; 
 
    margin-left: 200px; 
 
    margin-right: 200px; 
 
    margin: 0; 
 
    }   
 
#container #content #sidebar2{ 
 
    background-color: #ADA9A0; 
 
    float: right; 
 
    width: 200px; 
 
    min-height: 300px; 
 
    margin-bottom: 3px; 
 
    margin-top:-300px; 
 
    } 
 
    
 
#container #footer{ 
 
    padding-top: 1px; 
 
    border-top: 1px solid black; 
 
} 
 
.CR{ 
 
     text-align: left; 
 
     position: fixed;  
 
} 
 
.Instructor{ 
 
    text-align: right; 
 
    position: fixed right; 
 
    } 
 

 
/*NAV LINKS - add an "a" to style items under the ID'S*/ 
 
#container #navigation a{ 
 
    color: white; 
 
    text-decoration: none; /*gets rid of the underlining effect*/ 
 
    padding-top: 5px; 
 
    padding-bottom: 6px; 
 
    padding-left: 10px; 
 
    padding-right: 10px; 
 
    } 
 
    
 

 
    
 
/*To add a hover put a:hover*/ 
 
#container #navigation a:hover{ 
 
    color: red; 
 
    background-color: white; 
 
    } 
 
    
 
    
 
#container #content #left { 
 
    font-family: Arial; 
 
    } 
 
    
 

 
<!DOCTYPE html> 
 

 
<html> 
 
<head> 
 

 
    <link type="text/css" rel="stylesheet" href="stylesheet.css" /> 
 

 
<title> My Portfolio </title> 
 
</head> 
 

 
<body> 
 
\t <div id="container"> 
 
     <div id="header"> 
 
      <h1> CIS 2336- Internet Applications </h1> 
 
      <h2> DeVoll </h2> 
 
     </div> 
 
     <div id="navigation"> 
 
      <a href="http://tdevoll16f.heyuhnem.com/index1.html/CIS 2336/My Portfolio/MyPage1.html">Home</a> 
 
      <a href="#">HTML/CSS</a> 
 
      <a href="#">PHP</a>  
 
     </div> 
 
     <div id="content"> 
 
     
 
      <div id="sidebar1"> 
 
       <h4> Instuctor: Natalia Fofanova </h4> 
 
       <ul> 
 
        <li> Lectures </li> 
 
        <li> Syllabus </li> 
 
        <li> Helpful Videos </li> 
 
       </ul> 
 
      </div> 
 
      
 
      <div id="column1"> 
 
       <h2> HTML and CSS </h2> 
 
       <p>HTML (Hypertext Markup Language) 
 
       and CSS (Cascading Style Sheets) are two 
 
       of the core technologies 
 
       for bulding a website. <p> 
 
       
 
<p>HTML provides a structure for the page by using "Hypertext" which refers to the hyperlinks that an HTML page may contain. Also, "Markup language" refers to the way tags are used to define the page layout and elements within the page. </p> 
 
<p>CSS provides the visual layout of web pages. They can be used to define text styles, table sizes, and other aspects of Web pages that previously could only be defined in a page's HTML. CSS helps Web developers create a uniform look across several pages of a Web site. Instead of defining the style of each table and each block of text within a page's HTML, commonly used styles need to be defined only once in a CSS document. </p> 
 
</p> 
 
      </div> 
 
      
 
      <div id="sidebar2"> 
 
      dddd 
 
      </div> 
 
     
 
     </div> 
 
     
 
     <footer> 
 
      <div id="footer"> 
 
       <div class="CR"> 
 
        <h4> Copyright 2016 </h4> 
 
      </div> 
 
       <div class="Instructor"> 
 
        <a href="http://heyuhnem.com/"><h4>Copyright Natalie Fofanova </h4> </a> 
 
      </div> 
 
       
 
     </footer> 
 

 
</body> 
 
</html>

+1

這是一個純HTML/CSS問題,什麼都沒有做與PHP的。 –

+0

這裏是一個工作小提琴:https://jsfiddle.net/15pz3t6b/ –

+0

也與'html5'無關...... – vsync

回答

0

您需要簡單地使用文本對齊

即:text-align : righttext-align : center

0

我加入float: left;width: calc(100% - 400px);#column1400像素的側邊欄的總寬度)我提出了margin-leftmargin-right#column1#sidebar2margin-top:-300px;不再需要

對於版權的文字,我說:

.Instructor h4 { 
    text-align: right; 
} 

* { 
 
    font-family: Melvetica; 
 
    margin: 0px; 
 
    padding: 0px; 
 
} 
 

 
body { 
 
    background-color: #6B6A67; 
 
} 
 

 
#container { 
 
    width: 920px; 
 
    background-color: white; 
 
    padding: 10px; 
 
    margin-left: auto; 
 
    /*will center your page*/ 
 
    margin-right: auto; 
 
    /*will center your page*/ 
 
} 
 

 
h1, 
 
h2 { 
 
    text-align: center; 
 
} 
 

 
li { 
 
    text-align: center; 
 
    padding: 5px; 
 
} 
 

 
h4 { 
 
    padding: 5px; 
 
    text-align: center; 
 
} 
 

 

 
/*To style an ID within an ID under it use the parent ID--start with header then call the ID you want to select*/ 
 

 
#container #header { 
 
    height: 80px; 
 
    background-color: #ADA9A0; 
 
    padding-top: 20px; 
 
    padding-left: 10px; 
 
    padding-right: 20px; 
 
    margin-bottom: 5px; 
 
    /*To add empty space to bottom of the element*/ 
 
} 
 

 
#container #navigation { 
 
    margin-top: 5px; 
 
    background-color: #ADA9A0; 
 
    color: white; 
 
    padding-top: 5px; 
 
    padding-bottom: 5px; 
 
    border: 2px solid #ADA9A0; 
 
} 
 

 
#container #content { 
 
    background-color: #D9D5CE; 
 
    min-height: 300px; 
 
    margin-top: 5px; 
 
    margin-bottom: 5px; 
 
    /*To add empty space to bottom of the element*/ 
 
} 
 

 
#container #content #sidebar1 { 
 
    background-color: #ADA9A0; 
 
    float: left; 
 
    width: 200px; 
 
    min-height: 300px; 
 
    margin-bottom: 3px; 
 
} 
 

 
#container #content #column1 { 
 
    background-color: white; 
 
    min-height: 300px; 
 
    margin-bottom: 3px; 
 
    width: calc(100% - 400px); 
 
    margin: 0; 
 
    float: left; 
 
} 
 

 
#container #content #sidebar2 { 
 
    background-color: #ADA9A0; 
 
    float: right; 
 
    width: 200px; 
 
    min-height: 300px; 
 
    margin-bottom: 3px; 
 
} 
 

 
#container #footer { 
 
    padding-top: 1px; 
 
    border-top: 1px solid black; 
 
} 
 

 
.CR { 
 
    text-align: left; 
 
    position: fixed; 
 
} 
 

 
.Instructor { 
 
    text-align: right; 
 
    position: fixed right; 
 
} 
 

 
.Instructor h4 { 
 
    text-align: right; 
 
} 
 

 

 
/*NAV LINKS - add an "a" to style items under the ID'S*/ 
 

 
#container #navigation a { 
 
    color: white; 
 
    text-decoration: none; 
 
    /*gets rid of the underlining effect*/ 
 
    padding-top: 5px; 
 
    padding-bottom: 6px; 
 
    padding-left: 10px; 
 
    padding-right: 10px; 
 
} 
 

 

 
/*To add a hover put a:hover*/ 
 

 
#container #navigation a:hover { 
 
    color: red; 
 
    background-color: white; 
 
} 
 

 
#container #content #left { 
 
    font-family: Arial; 
 
}
<!DOCTYPE html> 
 

 
<html> 
 
<head> 
 

 
    <link type="text/css" rel="stylesheet" href="stylesheet.css" /> 
 

 
<title> My Portfolio </title> 
 
</head> 
 

 
<body> 
 
\t <div id="container"> 
 
\t \t <div id="header"> 
 
\t \t \t <h1> CIS 2336- Internet Applications </h1> 
 
\t \t \t <h2> DeVoll </h2> 
 
\t \t </div> 
 
\t \t <div id="navigation"> 
 
\t \t \t <a href="http://tdevoll16f.heyuhnem.com/index1.html/CIS 2336/My Portfolio/MyPage1.html">Home</a> 
 
\t \t \t <a href="#">HTML/CSS</a> 
 
\t \t \t <a href="#">PHP</a>  
 
\t \t </div> 
 
\t \t <div id="content"> 
 
\t \t 
 
\t \t \t <div id="sidebar1"> 
 
\t \t \t \t <h4> Instuctor: Natalia Fofanova </h4> 
 
\t \t \t \t <ul> 
 
\t \t \t \t \t <li> Lectures </li> 
 
\t \t \t \t \t <li> Syllabus </li> 
 
\t \t \t \t \t <li> Helpful Videos </li> 
 
\t \t \t \t </ul> 
 
\t \t \t </div> 
 
\t \t \t 
 
\t \t \t <div id="column1"> 
 
\t \t \t \t <h2> HTML and CSS </h2> 
 
\t \t \t \t <p>HTML (Hypertext Markup Language) 
 
\t \t \t \t and CSS (Cascading Style Sheets) are two 
 
\t \t \t \t of the core technologies 
 
\t \t \t \t for bulding a website. <p> 
 
\t \t \t \t 
 
<p>HTML provides a structure for the page by using "Hypertext" which refers to the hyperlinks that an HTML page may contain. Also, "Markup language" refers to the way tags are used to define the page layout and elements within the page. </p> 
 
<p>CSS provides the visual layout of web pages. They can be used to define text styles, table sizes, and other aspects of Web pages that previously could only be defined in a page's HTML. CSS helps Web developers create a uniform look across several pages of a Web site. Instead of defining the style of each table and each block of text within a page's HTML, commonly used styles need to be defined only once in a CSS document. </p> 
 
</p> 
 
\t \t \t </div> 
 
\t \t \t 
 
\t \t \t <div id="sidebar2"> 
 
\t \t \t dddd 
 
\t \t \t </div> 
 
\t 
 
\t \t </div> 
 
\t \t 
 
\t \t <footer> 
 
\t \t \t <div id="footer"> 
 
\t \t \t \t <div class="CR"> 
 
\t \t \t \t \t <h4> Copyright 2016 </h4> 
 
\t \t \t </div> 
 
\t \t \t \t <div class="Instructor"> 
 
\t \t \t \t \t <a href="http://heyuhnem.com/"><h4>Copyright Natalie Fofanova </h4> </a> 
 
\t \t \t </div> 
 
\t \t \t \t 
 
\t \t </footer> 
 

 
</body> 
 
</html>

0

爲了創建一個3列布局,你必須給每個列aw IDþ。在你的情況下,左邊和右邊的列各有200px。中間欄490px。每列將浮動到左側。浮動元素會導致父容器崩潰。 Here is a great tutorial on floats

*{ 
    font-family: Melvetica; 
    margin: 0px; 
    padding: 0px; 
    } 

body{background-color: #6B6A67;}  

#container{ 
      width: 920px; 
      background-color: white; 
      padding: 10px; 
      margin-left: auto; /*will center your page*/ 
      margin-right: auto; /*will center your page*/ 
      } 

h1, h2{ text-align: center;} 

li{ 
    text-align: center; 
    padding: 5px; 
    list-style: none; /*removes bullets from sidebar1*/ 
    } 

h4{ 
    padding: 5px; 
    text-align: center; 
    } 

/*To style an ID within an ID under it use the parent ID--start with header then call the ID you want to select */ 
#header{ 
    height: 80px; 
    background-color: #ADA9A0; 
    padding-top: 20px; 
    padding-left: 10px; 
    padding-right: 20px; 
    margin-bottom: 5px; /*To add empty space to bottom of the element*/ 
    background: green; 
    } 


#navigation{ 
    margin-top: 5px; 
    background-color: pink; 
    color: white; 
    padding-top: 5px; 
    padding-bottom: 5px; 
    border: 2px solid #ADA9A0; 
    }  

#content{ 
    min-height: 300px; 
    margin-top: 5px; 
    margin-bottom: 5px; /*To add empty space to bottom of the element*/ 
    } 

#sidebar1{ 
    background-color: yellow; 
    float: left; 
    width: 200px; 
    min-height: 300px; 
    margin-bottom: 3px; 
    margin-right: 5px; 
    } 

#column1{ 
    background-color: teal; 
    min-height: 300px; 
    margin-bottom: 3px; 
    padding: 0 10px; 
    margin: 0; 
    width: 490px; 
    float: left; 
    } 

#sidebar2{ 
    background-color: green; 
    float: left; 
    width: 200px; 
    min-height: 300px; 
    margin-bottom: 3px; 
    margin-left: 5px; 
    } 

#footer{ 
    padding-top: 1px; 
    border-top: 1px solid black; 
    clear: both; 
    background: pink; 
    } 

.CR{ 
    text-align: left; 
    position: fixed;  
    } 

.Instructor{ 
    text-align: right; 
    position: fixed right; 
    } 

/*NAV LINKS - add an "a" to style items under the ID'S*/ 
#navigation a{ 
       color: white; 
       text-decoration: none; /*gets rid of the underlining effect*/ 
       padding-top: 5px; 
       padding-bottom: 6px; 
       padding-left: 10px; 
       padding-right: 10px; 
       } 



/*To add a hover put a:hover*/ 
#navigation a:hover{ 
         color: red; 
         background-color: white; 
         } 

#left {font-family: Arial;}