2015-12-11 62 views
0

我正在製作一個網頁。我正在嘗試將我的div正確對齊(動畫公司徽標)。對齊和中心divs

我需要他們坐在彼此旁邊,而不是彼此頂部,間距適合頁面。

這可能使事情變得更加清晰:

這裏是我的代碼:

<html> 
    <head> 

     <link href="bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css"/> 
     <link rel="stylesheet" type="text/CSS" href="Style.css" /> 
     <meta charset="UTF-8"> 
     <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    </head> 
    <body> 
     <header id="container"> 
      <h1> 
<a href="a">My Interactive Webpage </a> 
</h1> 
        <h1> 
<a href="a">Career Page </a> 
</h1> 

<style> 
ul { 
    list-style-type: none; 
    margin: 0; 
    padding: 0; 
    overflow: hidden; 
    background-color: #333; 
} 

li { 
    float: left; 
} 

li a { 
    display: block; 
    color: white; 
    text-align: center; 
    padding: 14px 16px; 
    text-decoration: none; 
} 

li a:hover:not(.active) { 
    background-color: #111; 
} 

.active { 
    background-color: #4CAF50; 
} 
</style> 

<ul> 
    <li><a class="active" href="index.html">Home</a></li> 
    <li><a href="Information Page.html">Information</a></li> 
    <li><a href="Game Page.html">Games</a></li> 
    <li><a href="Career Page.html">Career</a></li> 
</ul>  
     </header>  
     <div id="container">  
     <head> 
<center> 

<p><font face="verdana" color="green">Welcome to my Career Page! 
I am passionate about all aspects of computer games development especially programming and games design. Since an early age I have played and experienced a wide range of platforms and games and retain my love for this form of entertainment. One of my favourite games of all time is Oblivion, on the PC and developed by Bethesda, it played brilliantly, was graphically superb and had a perfect soundtrack. I would love to be involved in developing a game of that quality for the current generation of platforms as well as PC. A computer games programme that gives me a strong foundation in computer science is ideal. It gives me the fundamental skills and knowledge for adapting to this rapidly changing and evolving games industry. 
Below are some of the companies I would dream of working for. Please click the text to be taken to the respective homepage of each company. 
</font></p> 
</center>     
      </div>     
     <div class="tilt pic"> 
<style> 

#rcorners3 { 
    border-radius: 25px; 
    background: url(http://i.imgur.com/AkIPWeF.png); 
    background-position: left top; 
    background-repeat: repeat; 
    padding: 20px; 
    width: 200px; 
    height: 150px; 
} 
</style> 

<a href="http://eu.blizzard.com/en-gb/"> 
    <font color="white"><p id="rcorners3">BLIZZARD ENTERTAINMENT</p></font> 
</a> 
    </div> 

    <div class="tilt pic">  
     <style> 
#rcorners2 { 
    border-radius: 25px; 
    background: url(http://i.imgur.com/Mouf1lw.png); 
    background-position: left top; 
    background-repeat: repeat; 
    padding: 20px; 
    width: 200px; 
    height: 150px;  
} 
</style> 

<a href="http://www.naughtydog.com/"> <font color="white"><p id="rcorners2">NAUGHTY DOG</p></font> 
</a> 
    </div> 
<!DOCTYPE html> 
<html> 
<head> 

<div class="tilt pic">  
     <style> 
#rcorners4 { 
    border-radius: 25px; 
    background: url(http://i.imgur.com/pFeIHdd.png); 
    background-position: left top; 
    background-repeat: repeat; 
    padding: 20px; 
    width: 200px; 
    height: 150px; 
} 
</style> 

<a href="https://www.ubisoft.com/en-GB/"> 
    <font color="white"><p id="rcorners4">UBISOFT</p></font> 
</a> 
</div> 
</body> 
</html> 

</body> 

</html> 

</div>  
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>  
    <script src="bootstrap/js/bootstrap.js" type="text/javascript"></script> 
    </body> 
    </html> 
+0

您的HTML有很多錯誤。首先,一個HTML文檔只應該有一個''元素,其他所有元素都在那裏。如果你確定你的HTML語法是正確的,那麼你的文檔在不同瀏覽器中看起來相同的機率會更大。 –

+0

謝謝。我目前正在通過我的代碼嘗試刪除我的新手錯誤。 –

+0

[如何在另一個div中對齊3個div(左/中/右)?](http://stackoverflow.com/questions/2603700/how-to-align-3-divs-left-center-right -inside-another-div) – hotzst

回答

-1

你可以試試這個:

<html> 
    <head> 

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

       <meta charset="UTF-8"> 
     <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    </head> 
    <body> 
     <header id="container"> 
      <h1> 
<a href="a">My Interactive Webpage </a> 
</h1> 
        <h1> 
<a href="a">Career Page </a> 
</h1> 

<style> 
ul { 
    list-style-type: none; 
    margin: 0; 
    padding: 0; 
    overflow: hidden; 
    background-color: #333; 
} 

li { 
    float: left; 
} 

li a { 
    display: block; 
    color: white; 
    text-align: center; 
    padding: 14px 16px; 
    text-decoration: none; 
} 

li a:hover:not(.active) { 
    background-color: #111; 
} 

.active { 
    background-color: #4CAF50; 
} 
</style> 

<ul> 
    <li><a class="active" href="index.html">Home</a></li> 
    <li><a href="Information Page.html">Information</a></li> 
    <li><a href="Game Page.html">Games</a></li> 
    <li><a href="Career Page.html">Career</a></li> 
</ul> 

     </header> 

     <div id="container"> 


     <head> 

<center> 

<p><font face="verdana" color="green">Welcome to my Career Page! 
I am passionate about all aspects of computer games development especially programming and games design. Since an early age I have played and experienced a wide range of platforms and games and retain my love for this form of entertainment. One of my favourite games of all time is Oblivion, on the PC and developed by Bethesda, it played brilliantly, was graphically superb and had a perfect soundtrack. I would love to be involved in developing a game of that quality for the current generation of platforms as well as PC. A computer games programme that gives me a strong foundation in computer science is ideal. It gives me the fundamental skills and knowledge for adapting to this rapidly changing and evolving games industry. 
Below are some of the companies I would dream of working for. Please click the text to be taken to the respective homepage of each company. 
</font></p> 

</center>    

      </div> 


     <div class="tilt pic" style="float:left; padding:10px;"> 

<style> 

#rcorners3 { 

    border-radius: 25px; 
    background: url(http://i.imgur.com/AkIPWeF.png); 
    background-position: left top; 
    background-repeat: repeat; 
    padding: 20px; 
    width: 200px; 
    height: 150px; 

} 
</style> 



<a href="http://eu.blizzard.com/en-gb/"> 
    <font color="white"><p id="rcorners3">BLIZZARD ENTERTAINMENT</p></font> 
</a> 
    </div> 




    <div class="tilt pic" style="float:left; padding:10px;">  
     <style> 
#rcorners2 { 

    border-radius: 25px; 
    background: url(http://i.imgur.com/Mouf1lw.png); 
    background-position: left top; 
    background-repeat: repeat; 
    padding: 20px; 
    width: 200px; 
    height: 150px; 

} 
</style> 

<a href="http://www.naughtydog.com/"> <font color="white"><p id="rcorners2">NAUGHTY DOG</p></font> 
</a> 
    </div> 
<!DOCTYPE html> 
<html> 
<head> 

<div class="tilt pic" style="float:left; padding:10px;">  
     <style> 
#rcorners4 { 

    border-radius: 25px; 
    background: url(http://i.imgur.com/pFeIHdd.png); 
    background-position: left top; 
    background-repeat: repeat; 
    padding: 20px; 
    width: 200px; 
    height: 150px; 

} 
</style> 



<a href="https://www.ubisoft.com/en-GB/"> 
    <font color="white"><p id="rcorners4">UBISOFT</p></font> 
</a> 
</div> 
</body> 
</html> 





</body> 


</html> 

</div> 


    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>  
    <script src="bootstrap/js/bootstrap.js" type="text/javascript"></script> 
    </body> 

    </html> 
+0

你可以做的最少的事是OP代碼中的一些錯誤。 –

+0

你好,謝謝。但我不確定這是否奏效。我會繼續嘗試。 –

+0

你好,先生謝謝@ SaraW –

0

如前所述已經有很多錯誤,我真的試過,但它實際上是我ULD需要一段時間...

下面是消除一些錯誤的第一次嘗試:https://jsfiddle.net/6qfq1c7g/

然而,因爲還是有很多錯誤,你不應該使用這個代碼。

請考慮讀一些關於類和HTML基本結構應該是這樣的http://www.w3schools.com/html/html_intro.asp

不要使用<html><head><body>兩次。

你當然可以在你的html中使用<style>標籤,但你至少應該把它們放在一起,這樣你就不會一直在html和css之間切換。最好的做法是爲你的css創建一個單獨的文件,就像你已經在你的頭部實現了一樣(style.css)。

使用相同元素的類。您的「公司」的結構基本上都是一樣的,所以你應該這樣做

.company { 
    border: 1px solid #333; 
    border-radius: 5px; 
    // and so on .... 
} 

爲背景,那麼你可以再次使用特定的ID,甚至類

.blizzard { 
    background-color: url('blizzard.jpg'); 
} 

.ubisoft { 
    background-color: url('ubisoft.jpg'); 
} 

這將清除代碼很多。

實際響應:

結合你的3個元素的每一個元素所需要的CSS樣式

display: inline-block; 

我也推薦給

vertical-align: top; 

,使一切都在同一高度對齊。爲了然後再居中你應該添加

margin: 0 auto; 

而且外包裝元素應該有

text-align: center; 
0

正如其他人所說的有很多在你的代碼不必要的重複的,可以被清理,但到回答你的問題,我建議使用一個表,特別是與它的width設置爲100%錶行你如何希望他們像這樣格式化您的圖片:

<table style="width: 100%;"> 
<tr> 
<td> 
    <div class="tilt pic"> 
    <a href="http://eu.blizzard.com/en-gb/"> 
     <font color="white"><p id="rcorners3">BLIZZARD ENTERTAINMENT</p></font> 
    </a> 
    </div> 
</td> 
<td> 
    <div class="tilt pic"> 
    <a href="http://www.naughtydog.com/"> <font color="white"><p id="rcorners2">NAUGHTY DOG</p></font> 
    </a> 
    </div> 
</td> 
<td> 
    <div class="tilt pic"> 
    <a href="https://www.ubisoft.com/en-GB/"> 
     <font color="white"><p id="rcorners4">UBISOFT</p></font> 
    </a> 
    </div> 
</td> 

並且最後以各自的細胞內居中你的圖片,你需要以下內容添加到他們的每一個的ID:

#rcorners3 { 
margin-left:auto; 
margin-right:auto; 
... 
} 

#rcorners2 { 
    margin-left:auto; 
    margin-right:auto; 
    ... 
} 

#rcorners4 { 
    margin-left:auto; 
    margin-right:auto; 
    ... 
} 

這使得確保了的兩側的間距無論實際有多少空間,元素都是相等的。

請參閱工作示例 - http://jsfiddle.net/ddwqkm5t/1/