我需要将包装文本居中

时间:2018-05-25 22:48:15

标签: html css formatting

我已经包装了文本以更好地包含它,但它使它不再居中;它在页面的左侧是合理的,但我需要它居中。

我最初根本没有样式部分,但我认为我需要它来包装我的文本,因为我不希望因为内容的性质而跨越整个页面的单词。

简而言之,我只需要让我的内容再次居中,但我需要430px包装文本。

谢谢。

以下是代码:

 c(mapply(rep, 2 ,A)) # OR sort(rep(A, times = 2))
 #[1] "a" "a" "b" "b" "c" "c" "d" "d" "e" "e" "f" "f" "g" "g" "h" "h" "i" "i" "j" "j"
 #[21] "k" "k"

 c(mapply(rep,A, 4))  #OR sort(rep(A, times = 2))
 #[1] "a" "a" "a" "a" "b" "b" "b" "b" "c" "c" "c" "c" "d" "d" "d" "d" "e" "e" "e" "e"
 #[21] "f" "f" "f" "f" "g" "g" "g" "g" "h" "h" "h" "h" "i" "i" "i" "i" "j" "j" "j" "j"
 #[41] "k" "k" "k" "k"

2 个答案:

答案 0 :(得分:0)

应该是text-align:center

div {
width: 430px;
text-align : center;
}

这是一个有效的例子:



div {
    width: 430px;
    text-align : center;
    }
div.a {
    word-wrap: normal;

<title>contact</title>

    <body>
    <div class=“panel”>
    <center>
    <img src=img/about_blackonorange.png height=215 width=215>
    </center>

<center>        
<div class="twelve columns nav-bar--column">
<nav class="nav-collapse">


    <a href=home.html>home</a>
    <a href=news_v2.html>news</a>
    <a href=visual_v2.html>visual</a>
    <a href=audio_v2.html>audio</a>
    <a href=contact_v2.html>contact</a>
    <a href=about.html>about<a>


</nav>
</div> 
</center>



<!—-CONTENT GOES HERE—->

<center>
<p>
<div class="a">
blah blah blah blah blah. 
<br></br>
blah blah blah blah blah. 
</div>
</p>
</center>



    </body>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

将此CSS添加到您的容器中:

.centered {
  position: fixed;
  top: 50%;
  left: 50%;
  /* bring your own prefixes */
  transform: translate(-50%, -50%);
}

将元素置于中间任何包装器的中间位置。如果没有,它只是将其居中到屏幕中间。

只要将文本与元素的中心对齐,就可以添加此CSS:

text-align: center;