【问题标题】:Do not want the text to be centered不希望文本居中
【发布时间】:2018-12-10 03:39:03
【问题描述】:

我以前从未编程过,但我有一个大学项目,我必须在其中编辑布局。 其中有一部分文本在中心,当它到达页面的中心时,它会跳到下一行..我希望它能够正常继续.. https://jsfiddle.net/nqpa6jh0/#&togetherjs=vORwosTiHV

.image.feature2 {
  display: block;
  margin: 0 0 0em 0;
}

.image.feature2 img {
  display: block;
  width: 100%;
  border-radius: 50%;
  width: 200px;
  height: 200px;
  float: left
}

.image.feature3 img {
  display: block;
  width: 100%;
  border-radius: 50%;
  width: 200px;
  height: 200px;
  float: right;
<div class="wrapper style2">
  <section class="container">
    <header class="major">
      <h2>Depoimentos</h2>
      <span class="byline">Os viajantes recomendam.</span>
    </header>
    <div class="row no-collapse-1">
      <section class="">
        <a class="image feature2"><img src="images/pic02.jpg" alt=""></a>
        <p>Nam in massa. Sed vel tellus. Curabitur sem urna, consequat vel, suscipit in, mattis placerat.</p>
      </section>
    </div>
  </section>
</div>

这是它的外观

这就是我想要的样子(第一个照片):

【问题讨论】:

  • 请创建jsfiddlecodepen 或类似名称,供人们试验。在您的问题中包含指向它的链接。包括工作示例所需的一切,即使它不能完全工作,包括 html、css、js 和 图像,根据需要。
  • 抱歉不知道。这是 jsfiddle:jsfiddle.net/nqpa6jh0/#&togetherjs=vORwosTiHV
  • 你使用的是框架还是什么?
  • 我不确定.. 崇高的文字

标签: html css text center undo


【解决方案1】:

让我给你解释清楚。

从经过 photoshop 处理的图像中,我可以看到您想要实现的目标以及代码中的错误。有很多。

这里:(冗余代码)

.image.feature2 img {
  display: block;
  width: 100%;
  border-radius: 50%;
  width: 200px;
  height: 200px;
  float: left
}

.image.feature3 img {
  display: block;
  width: 100%;
  border-radius: 50%;
  width: 200px;
  height: 200px;
  float: right;
}

您没有正确使用类。类旨在删除 css 中的冗余代码。让我们考虑您在包含这些部分的 div 中添加了一个类 myParentClass,并删除了 a 元素上的类 image feature2。然后html看起来像:

<div class="myParentClass row no-collapse-1">
  <section class="">
    <a ><img src="images/pic02.jpg" alt=""></a>
    <p>Nam in massa. Sed vel tellus. Curabitur sem urna, consequat vel, suscipit in, mattis placerat.</p>
  </section>
  <section class="">
    <a><img src="images/pic02.jpg" alt=""></a>
    <p>Nam in massa. Sed vel tellus. Curabitur sem urna, consequat vel, suscipit in, mattis placerat.</p>
  </section>
</div>

上面的css可以换成:

.myClass section a img {
  display: block;
  width: 100%;
  border-radius: 50%;
  width: 200px;
  height: 200px;
  float: left
}

.myParentClass section:nth-child(odd) a img {
  float: right;
}

为了使p 元素内的文本不被环绕,您需要添加white-space": nowrap。所以:

.myParentClass section p {
  white-space: nowrap;
}

为了使odd 部分元素的左侧有一些空格,您必须使用padding,即

.myParentClass section:nth-child(odd){
  padding-left: 50px;
}

【讨论】:

  • 对不起,我不明白第 n 个孩子(奇数).. 我也可能做错了什么,因为我添加了空格“:nowrap,它没有做任何事情.. 我必须做我不知道有什么问题
  • 而这个人stackoverflow.com/a/51129526/10018813 似乎已经修复了它.. 但是当我复制他的代码并粘贴到这里时,文本保持不变。也许那是我的电脑出了问题..
  • 没有。你的电脑没有问题。也许有些东西正在覆盖规则。只需将其放在 css 文件的末尾,这样如果定义错误,它就会覆盖其他规则。
  • 没有工作..我想我要切换模板,页脚背景也不见了..谢谢
猜你喜欢
  • 2017-06-13
  • 2020-05-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多