温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

css如何使用clear属性

发布时间:2020-09-24 13:41:32 来源:亿速云 阅读:133 作者:小新 栏目:web开发

这篇文章主要介绍了css如何使用clear属性,具有一定借鉴价值,需要的朋友可以参考下。希望大家阅读完这篇文章后大有收获。下面让小编带着大家一起了解一下。

css clear属性指定元素的左侧或右侧上不允许出现浮动元素。可用于实现浮动的清除,解决浮动布局带来的一些问题。

css clear属性怎么用?

clear 属性规定元素的哪一侧不允许其他浮动元素。

语法:

clear:left|right|both|none|inherit;

属性值:

● left:在左侧不允许浮动元素。

● right:在右侧不允许浮动元素。

● both:在左右两侧均不允许浮动元素。

● none:默认值。允许浮动元素出现在两侧。

● inherit:规定应该从父元素继承 clear 属性的值。

说明:

clear 属性定义了元素的哪边上不允许出现浮动元素。在 CSS1 和 CSS2 中,这是通过自动为清除元素(即设置了 clear 属性的元素)增加上外边距实现的。在 CSS2.1 中,会在元素上外边距之上增加清除空间,而外边距本身并不改变。

不论哪一种改变,最终结果都一样,如果声明为左边或右边清除,会使元素的上外边框边界刚好在该边上浮动元素的下外边距边界之下。

注释:所有主流浏览器都支持 clear 属性。任何版本的 Internet Explorer (包括 IE8)都不支持属性值 "inherit"。

css clear属性 示例

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<style>
img
{
float:left;
}
p.clear
{
clear:both;
}
</style>
</head>
<body>
<img src="logocss.gif" width="95" height="84" />
<p>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>
<p>This is also some text. This is also some text. This is also some text. This is also some text. This is also some text.</p>
<br>
<p>使用clear:both清除浮动:</p>
<img src="logocss.gif" width="95" height="84" />
<p>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>
<p class="clear">This is also some text. This is also some text. This is also some text. This is also some text. This is also some text. </p>
</body>
</html>

效果图:

css如何使用clear属性

感谢你能够认真阅读完这篇文章,希望小编分享css如何使用clear属性内容对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,遇到问题就找亿速云,详细的解决方法等着你来学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI