如何使用 CSS 将段落元素显示为内联?

WBOY
WBOY 转载
2023-09-06 16:41:04 739浏览

如何使用 CSS 将段落元素显示为内联?

CSS具有内部样式和内联样式,可用于以内联方式显示段落元素。 CSS 是一种用于设计 HTML 和 XML 文本样式的语言。更改 HTML 元素的显示属性是一项典型的 CSS 工作。元素的显示属性指示其应如何呈现,例如块、内联或内联块。内联显示段落元素时,必须将显示属性从其默认块值修改为内联。

在这里,我们将学习如何开发将段落元素显示为内联的 CSS 代码。

语法

<p style="display : inline">..write the paragraph...</p>

HTML中的段落由p标签表示。显示属性定义内容的流动方式。

设置为显示“内联”的元素将显示为内联级框,这意味着它将在一行文本内流动。

相比之下,“块”元素将填充其父容器的整个宽度,并在任何现有内容下方添加新的内容行。

标题、段落和 div 元素是块级元素的示例,而链接、span 元素和图像是内联元素的示例。

使用的属性

示例中使用的以下属性是 -

  • 颜色 - 定义文本的颜色。

  • background-color - 将文本定义为细或粗。

  • display - display 属性指定显示行为。

示例

在此示例中,我们将开始使用段落元素来设置几行文本。要将段落元素显示为内联,它将使用 display 属性通过内联 CSS 设置内联值。然后设计一些元素的样式,例如 body、p,以吸引网页上的用户交互。

<!DOCTYPE html>
<html>
<title>Display paragraph elements as inline using CSS</title>
<head>
</head>
<body style="background-color: powderblue;">
   <center>
      <h1>Rich Dad and Poor Dad</h1>
   </center>
   <p style="background-color:#a89032; color: white; font-style: italic; display: inline;">Rich
      Dad Poor Dad, by Robert Kiyosaki, was initially published in 1997 and immediately became a must-read
      for anybody interested in investment, money, or the global economy. The book has been translated into
      dozens of languages and sold all over the world, becoming the best-selling personal finance book of all
      time. Rich Dad Poor Dad's overriding theme is how to use money as a tool for wealth growth. It debunks
      the idea that the wealthy are born wealthy, explains why your personal residence may not be an asset,
      defines the distinction between an asset and a liability, and much more.
   </p>
   <p style="font-weight: bold; text-align: right; display: inline; color: darkgreen;">@tutorialspoint.com</p>
</body>
</html>

结论

在上面的输出中,我们可以看到如何借助 CSS 显示属性中的内联值来控制文本样式的布局。这是测试显示段落元素作为内联元素的变化的好主意。为了保持文本位置的灵活性,有时改变显示的属性是正确的。

以上就是如何使用 CSS 将段落元素显示为内联?的详细内容,更多请关注php中文网其它相关文章!

声明:本文转载于:tutorialspoint,如有侵犯,请联系admin@php.cn删除