position:fixed 居中

 时间:2024-10-12 17:21:48

1、新建一个html文件。如图:

position:fixed 居中

3、创建div并设置基本属性。html文件找到<title>标签,在这个标签后新秃赈沙嚣建一个<style>标签,然后在<style媪青怍牙>标签里设置class类为fixed的属性为:宽为300像素,高为150像素,背景为红色,相对于浏览器窗口定位,距离浏览器顶部位置为20%样式代码: <style> .fixed{ width: 300px; height: 150px; background-color: red; position: fixed; top: 20%; } </style>

position:fixed 居中

5、设置position:fixed 居中。为了给div自动居中显示,只需要在fixed类中再添加:left: 0; right: 0; margin:0 auto;如图:

position:fixed 居中

7、如有不明白可以把所有代码复制到新建的html文件保存后使用浏览器打开即可看到效果。所有代码:<!DOCTYPE html><html><head><meta charset="UTF-8"><title>position: fixedn居中</title><style>.fixed{width: 300px;height: 150px;background-color: red;position: fixed;top: 20%;left: 0;right: 0;margin:0 auto;}</style></head><body><div class="fixed">fixed浮动居中</div></body></html>

position:fixed 居中
  • 前端编程-用浏览器自带的取色功能快速拾取颜色
  • tomcat怎么修改端口号
  • IDEA中怎么设置选项卡关闭按钮位置
  • css如何去掉textarea的边框
  • jquery如何获取标签的class属性值
  • 热门搜索
    盐城旅游团 大连旅游线路 锡林郭勒盟旅游 湖南旅游网 圣托里尼岛旅游多少钱 石林旅游攻略 西安旅游景点门票 马尼拉旅游攻略 凭祥旅游 上海旅游节花车巡游