fixed实现div居中
前端开发中,有时候既要实现一个div fixed固定定位,又要实现该div居中且div里的内容居中,实现方法如下:
在div的css为:
.fixed-c {height: 80px;width: 90%;position: fixed;margin: auto;bottom: 0; /*底部固定*/left: 0; /*实现div的居中*/right: 0; /*实现div的居中*/text-align: center; /*div的内容居中*/background: red;line-height: 80px; /*垂直居中*/}
效果图如下:
原代码:
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>fixed居中</title><style>body{padding: 0;margin: 0;font-size: 22px;}.content-left{width: 256px;min-width: 256px;max-width: 256px;flex: 0 0 256px;overflow: hidden;height:100vh;background: orange;}.content-right{height: 900px;}.fixed-c {height: 80px;width: 90%;position: fixed;margin: auto;bottom: 0; /*底部固定*/left: 0; /*实现div的居中*/right: 0; /*实现div的居中*/text-align: center; /*div的内容居中*/background: red;line-height: 80px; /*垂直居中*/}</style>
</head>
<body><div style="display:flex"><div class="content-left">左侧任意内容</div><div style="flex: auto"><div class="content-right">右侧任意内容</div></div><div class="fixed-c">fixed底部固定,且要居中</div></div>
</body>
</html>
fixed实现div居中相关推荐
- css position fixed 居中,css中position:fixed实现div居中上下左右居中
上下左右 居中 代码如下 div{ position:fixed; margin:auto; left:0; right:0; top:0; bottom:0; width:200px; height ...
- div css将文字居中显示图片,css文字居中、图片居中、div居中解决方案
一.文字居中 若文字只有一行 文本只有一行 .box { width: 200px; height: 200px; background-color: red; } .text { line-heig ...
- php 上下位置居中,CSS_css中position:fixed实现div在窗口上下左右居中,上下左右 居中 代码如下 复制 - phpStudy...
css中position:fixed实现div在窗口上下左右居中 上下左右 居中 代码如下 复制代码代码如下: div{ position:fixed; margin:auto; left:0; ri ...
- div居中 边框设置 文字行高设置
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- html怎么div剧中,css怎么使div居中?
在开发过程中,很多需求需要我们居中一个div,比如html文档流当中的一块div,比如弹出层内容部分这种脱离了文档流等.不同的情况有不同的居中方式,接下来就分享下一下几种常用的居中方式. css设置d ...
- html让整个div居中,分享一个可以让DIV实现居中齐的方法
无意中在网站看到一属性可以让一个DIV实现居中,个人觉得很好,想起以前自己学习CSS时候也曾经接触过实现DIV居中的方法,看过css彻底研究一本书,中讲到用三个DIV的方式,实现代码长,代码不易理解, ...
- 纯css使div垂直居中,div垂直,div居中的方法
首先编写一个简单的html代码,设置一个父div类名为boxFather,再设置一个子div类名为box1.html代码如下: <div class="boxFather"& ...
- div居中方法(共9种)
div居中方法(共9种) 水平居中 行级元素:为该行级元素的父元素设置text-align:center配合line-height样式 <div style="width: 500px ...
- css 绝对定位fixed,按钮居中
fixed实现按钮居中 fixed含义: 1.position:fixed绝对定位,脱离文档流,元素位置通过left,right,top,bottom进行定位: 2.一般用在页面底部做 tab按钮; ...
最新文章
- 看源码,我为什么推荐IDEA?
- 河北师范大学C语言试题,2017年河北师范大学信息技术学院838C语言程序设计考研题库...
- python网络爬虫教程-教你从零开始学会写 Python 爬虫
- May 18:PHP 用到的学习工具
- 如何上传应用到百度应用(图解攻略)
- codeigniter 禁止ip登录_「开源资讯」baigo SSO v4.0 beta-3 发布,单点登录系统
- 电容充放电原理图_干货 | 入门开关电源,这些原理图一定要读懂
- 加入收藏 lsk的BLOG
- IntelliJ IDEA 添加项目后编译显示包不存在的解决方案
- zookeeper集群自动启动-关闭-查询的shell脚本
- 2-2:C++快速入门之输入和输出
- python 基础 集合
- Linux下 SVN 常用命令
- 使用Gpu恢复7z密码
- Kotlin中三元运算符
- mysql数据库外连_数据库外连接及MySQL实现
- bat 切换网络适配器_Windows批处理自动切换IP地址设置无线网络和以太网的IP地址...
- 5G时代App和小程序是否会逐渐消失?
- 王者荣耀测试自己本命英雄软件,王者荣耀中谁是你的本命英雄测试地址 趣推测试王者荣耀中谁是你的本命英雄...
- 发现一个好用的视频下载器(浏览器插件)Cococut