【问题标题】:text-align center not working for me文本对齐中心不适合我
【发布时间】:2018-04-16 18:37:09
【问题描述】:

我正在尝试更改我正在处理的页面上某一特定文本行的文本对齐方式,但并没有真正成功。我试过使用 div class 和 div id 以及 p class 和 p id 并在 CSS 文件中进行修改,但它似乎对我不起作用。我试图将“专用于内存......”这一行居中。这是我的 HTML 和 CSS 文件:

body {
  background-color: #008000;
}

h1 {
  border-style: double;
  font-family: times-new-roman;
  color: white;
}

p {
  color: white;
  font-family: times-new-roman;
}

h2 {
  color: #ffffff;
}

a:link {
  color: blue;
}

a:visited {
  color: purple;
}
<link rel="stylesheet" href="style.css">

<p style="text-align:center;">Dedicated to the memory of Rhodesia's special forces operators</p>
<br>
<br>
<p><img src="https://upload.wikimedia.org/wikipedia/commons/7/77/Melander_and_Hupli_RLI_1979_simulation_4_%28cropped%29.jpg" width=300 height=200></p>
<span style=f ont-family="times-new-roman" font-weight="200"><h2>Rhodesian Light Infantry</h2></span>
<p class="regular">The Rhodesian Light Infantry was formed on February 1st, 1961. It was part of the army of the Central African Federation. This unit was Rhodesia's equivalent to the United States' 75th Ranger Regiment When the war against black nationalist guerrillas
  broke out in the 1960s, they played a crucial role in counterterrorism operations. In the latter stages of the conflict, the unit became trained in airborne operations. Throughout the RLI's history, it was an exclusively white unit. Volunteers from
  all throughout the world fought and died in the Rhodesian Light Infantry. In October 1980, the RLI was officially disbanded following the formation of Zimbabwe.</p>
<br>
<br>
<p><img src="https://upload.wikimedia.org/wikipedia/commons/b/b6/Selous_Scouts_II.jpg" width=200 height=200></p>
<h2>Selous Scouts</h2>
<p class="regular2">The Selous Scouts were created in 1973 during the Rhodesian Bush War. Their name came from famed hunter Frederick Courtney Selous. Ronald Reid-Daly commanded this notable unit. The Shona phrase <i>Pamwe chete</i> or <q>all together</q> was the Selous
  Scouts' motto. The Selous Scouts have 68% of all enemy deaths during the Rhodesian Bush War to their credit. Like other famed Rhodesian units, the Selous Scouts were disbanded upon the forming of the new government of Zimbabwe.</p>
<br>
<br>
<p><img src="https://upload.wikimedia.org/wikipedia/commons/2/2e/C_Squadron_%28Rhodesian%29_SAS%2C_1953.jpg" width=400 height=200></p>
<h2>Rhodesian Special Air Service</h2>
<p class="regular3">The history of the Rhodesian Special Air Service goes back to the Malayan Emergency. <q>C</q> Squadron of the SAS was made up of volunteers from Southern Rhodesia. Once this unit had completed their tour of duty in Malaya, they were disbanded. The Rhodesian
  Special Air Service was reactivated in the 1960s and fought during the insurgency against African nationalist forces. Upon Robert Mugabe's ascension to the Zimbabwean presidency in 1980, the Rhodesian SAS was disbanded permanently.</p>

【问题讨论】:

    标签: html css text alignment


    【解决方案1】:

    它确实有效,请参阅 sn-p。

    <h1>Special Forces of Rhodesia</h1>
    <p style="text-align:center;">Dedicated to the memory of Rhodesia's special forces operators</p>
    <br>
    <br>
    <p><img src="https://upload.wikimedia.org/wikipedia/commons/7/77/Melander_and_Hupli_RLI_1979_simulation_4_%28cropped%29.jpg" 
    width=300 height=200></p>
    <span style= font-family="times-new-roman" font-weight="200"><h2>Rhodesian Light Infantry</h2></span>
    <p class="regular">The Rhodesian Light Infantry was formed on February 1st, 1961. It was part of the army of the Central African
    Federation. This unit was Rhodesia's equivalent to the United States' 75th Ranger Regiment When the war against black 
    nationalist guerrillas broke out in the 1960s, they played a crucial role in counterterrorism operations. 
    In the latter stages of the conflict, the unit became trained in airborne operations. Throughout the RLI's history, it
    was an exclusively white unit. Volunteers from all throughout the world fought and died in the Rhodesian Light Infantry.
    In October 1980, the RLI was officially disbanded following the formation of Zimbabwe.</p>
    <br>
    <br>
    <p><img src="https://upload.wikimedia.org/wikipedia/commons/b/b6/Selous_Scouts_II.jpg" width=200 height=200></p>
    <h2>Selous Scouts</h2>
    <p class="regular2">The Selous Scouts were created in 1973 during the Rhodesian Bush War. Their name came from famed hunter
    Frederick Courtney Selous. Ronald Reid-Daly commanded this notable unit. The Shona phrase <i>Pamwe chete</i> or <q>all together</q>
    was the Selous Scouts' motto. The Selous Scouts have 68% of all enemy deaths during the Rhodesian Bush War to their credit.
    Like other famed Rhodesian units, the Selous Scouts were disbanded upon the forming of the new government of Zimbabwe.</p>
    <br>
    <br>
    <p><img src="https://upload.wikimedia.org/wikipedia/commons/2/2e/C_Squadron_%28Rhodesian%29_SAS%2C_1953.jpg" width=400
    height=200></p>
    <h2>Rhodesian Special Air Service</h2>
        <p class="regular3">The history of the Rhodesian Special Air Service goes back to the Malayan Emergency. <q>C</q> Squadron of the SAS was
    made up of volunteers from Southern Rhodesia. Once this unit had completed their tour of duty in Malaya, they were disbanded.
    The Rhodesian Special Air Service was reactivated in the 1960s and fought during the insurgency against African nationalist
        forces. Upon Robert Mugabe's ascension to the Zimbabwean presidency in 1980, the Rhodesian SAS was disbanded permanently.</p>
        

    【讨论】:

    • 在这里很好用,但是在 Microsoft Edge 中打开时却不显示。
    【解决方案2】:

    有一些无效的语法。头部有一个开放式标签。 移除或关闭样式标签。

    p之后还有一个内联样式问题。

    <span style= font-family="times-new-roman" font-weight="200">
    

    应该是

    <span style="font-family: times-new-roman" font-weight="200">
    

    适用于 Chrome 和 Edge

    【讨论】:

      【解决方案3】:

      它适用于 CSS 中的 ID,但它应该已经运行。有一个开放式的标签,关闭或移除它。您的内联 CSS 无效。

      <span style= font-family="times-new-roman" font-weight="200">
      
      <span style="font-family: times-new-roman" font-weight="200">
      

      <!DOCTYPE html>
      <html>
      <head>
      
      <style>
      body
      {
      background-color:#008000;
      }
      h1{
      border-style:double;
      font-family:times-new-roman;
      color:white;
      }
      p{
      color: white;
      font-family:times-new-roman;
      }
      h2{
      color:#ffffff;
      }
      a:link{
      color:blue;
      }
      a:visited{
      color:purple;
      }
      #centerTitle{
      	text-align: center;
      }
      </style>
      <title>My first web page</title>
      <link rel="stylesheet" href="style.css">
      </head>
      <body>
      <h1>Special Forces of Rhodesia</h1>
      <p id="centerTitle">Dedicated to the memory of Rhodesia's special forces operators</p>
      <br>
      <br>
      <p><img src="https://upload.wikimedia.org/wikipedia/commons/7/77/Melander_and_Hupli_RLI_1979_simulation_4_%28cropped%29.jpg" 
      width=300 height=200></p>
      <span style="font-family: times-new-roman" font-weight="200"><h2>Rhodesian Light Infantry</h2></span>
      <p class="regular">The Rhodesian Light Infantry was formed on February 1st, 1961. It was part of the army of the Central African
      Federation. This unit was Rhodesia's equivalent to the United States' 75th Ranger Regiment When the war against black 
      nationalist guerrillas broke out in the 1960s, they played a crucial role in counterterrorism operations. 
      In the latter stages of the conflict, the unit became trained in airborne operations. Throughout the RLI's history, it
      was an exclusively white unit. Volunteers from all throughout the world fought and died in the Rhodesian Light Infantry.
      In October 1980, the RLI was officially disbanded following the formation of Zimbabwe.</p>
      <br>
      <br>
      <p><img src="https://upload.wikimedia.org/wikipedia/commons/b/b6/Selous_Scouts_II.jpg" width=200 height=200></p>
      <h2>Selous Scouts</h2>
      <p class="regular2">The Selous Scouts were created in 1973 during the Rhodesian Bush War. Their name came from famed hunter
      Frederick Courtney Selous. Ronald Reid-Daly commanded this notable unit. The Shona phrase <i>Pamwe chete</i> or <q>all together</q>
      was the Selous Scouts' motto. The Selous Scouts have 68% of all enemy deaths during the Rhodesian Bush War to their credit.
      Like other famed Rhodesian units, the Selous Scouts were disbanded upon the forming of the new government of Zimbabwe.</p>
      <br>
      <br>
      <p><img src="https://upload.wikimedia.org/wikipedia/commons/2/2e/C_Squadron_%28Rhodesian%29_SAS%2C_1953.jpg" width=400
      height=200></p>
      <h2>Rhodesian Special Air Service</h2>
          <p class="regular3">The history of the Rhodesian Special Air Service goes back to the Malayan Emergency. <q>C</q> Squadron of the SAS was
      made up of volunteers from Southern Rhodesia. Once this unit had completed their tour of duty in Malaya, they were disbanded.
      The Rhodesian Special Air Service was reactivated in the 1960s and fought during the insurgency against African nationalist
          forces. Upon Robert Mugabe's ascension to the Zimbabwean presidency in 1980, the Rhodesian SAS was disbanded permanently.</p>
      	</body></html>

      【讨论】:

        猜你喜欢
        • 2019-02-09
        • 2018-09-15
        • 2013-06-15
        • 2018-03-29
        • 1970-01-01
        • 2016-01-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多