html - 如何左对齐文本?

标签 html css

我有一个包含两个步骤的脚本,我想对齐文本,例如:

Step1 : I am a boy........
my name is Ram```

但我想将文本对齐为

Step1 : I am a boy........
        my name is Ram```

我尝试了 text-align 和 align 属性来跨越。

p.steps {
  color: #000;
  margin-bottom: 10px;
  font-size: 20px;
  font-weight: normal;
  font-family: 'Montserrat';
  line-height: 1.2;
  margin-top: 20px;
  text-align: left;
}
<p class="steps"> <span style="color:#BB2812">Step1 : </span> I am a boy................. my name is Ram</p>
<p class="steps"> <span style="color:#BB2812">Step2 : </span> There are many countries but I live in Australia </p>

最佳答案

表格布局可以解决问题

p.steps {
  color: #000;
  margin-bottom: 10px;
  font-size: 20px;
  font-weight: normal;
  font-family: 'Montserrat';
  line-height: 1.2;
  margin-top: 20px;
  text-align: left;
  display:table; /* here */
}
p.steps span {
  display:table-cell; /* here */
  white-space:nowrap; /* and here */
  padding-right:5px;
}
<p class="steps"> <span style="color:#BB2812">Step1 : </span> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut pellentesque urna at ex fermentum egestas. Nullam convallis nec dolor finibus rhoncus. Nunc neque nisi,</p>
<p class="steps"> <span style="color:#BB2812">Step2 : </span> There are many countries but I live in Australia </p>

关于html - 如何左对齐文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63776646/

相关文章:

php - .htaccess 重写 URL 显示不正确?

javascript - 将键/值对传递给 Angular 过滤器

javascript - JQuery 无法在 "forwards"css 动画后对 div 进行动画处理

php - 如何检查表单中的任何字段是否在php中为空

html - Adobe Edge Code 和 Brackets 有什么区别?

javascript - 使用 isPointInPath() 引用 Path2D 对象?

javascript - 带开关盒的功能不提供输出

javascript - 动态动画的问题

javascript - 如何使用 YUI3 检测 HTML 元素的样式变化?

CSS 隐藏所有具有匹配 SRC 属性的图像