css想让块靠右该如何实现

王林
王林原创
2020-12-02 17:35:054550浏览

css想让块靠右的实现方法:可以通过float属性来实现,如【float:right;】,表示元素向右浮动。float属性用于定义元素在哪个方向浮动,left表示元素向左浮动,right表示元素向右浮动。

本文环境:

  • windows10、css3

  • 本文适用于所有品牌的电脑

相关元素:

float 属性定义元素在哪个方向浮动。以往这个属性总应用于图像,使文本围绕在图像周围,不过在 CSS 中,任何元素都可以浮动。浮动元素会生成一个块级框,而不论它本身是何种元素。

(学习视频分享:css视频教程

属性值:

  • left 元素向左浮动。

  • right 元素向右浮动。

  • none 默认值。元素不浮动,并会显示在其在文本中出现的位置。

  • inherit 规定应该从父元素继承 float 属性的值。

代码实现:

<html>
<head>
<style type="text/css">
img 
{
float:right
}
</style>
</head>

<body>
<p>在下面的段落中,我们添加了一个样式为 <b>float:right</b> 的图像。结果是这个图像会浮动到段落的右侧。</p>
<p>
<img src="/i/eg_cute.gif" />
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
</p>
</body>

</html>

实现效果:

43c7e9871412d28526b2c5b45a4941a.png

相关推荐:CSS教程

以上就是css想让块靠右该如何实现的详细内容,更多请关注php中文网其它相关文章!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。