当前位置: 首页 > news >正文

沈阳微营销网站制作微信搜一搜排名优化

沈阳微营销网站制作,微信搜一搜排名优化,ui培训哪好,网站首页大小博主目前在蚂蚁集团-体验技术部,AntV/S2 是博主所在团队的开源项目——多维交叉分析表格,欢迎使用,感谢到 S2 github 仓库点赞 star,有任何关于前端面试、就业、技术问题都可给在文章后留言。 1、盒子宽度和高度是已知的。思路&a…

博主目前在蚂蚁集团-体验技术部,AntV/S2 是博主所在团队的开源项目——多维交叉分析表格,欢迎使用,感谢到 S2 github 仓库点赞 star,有任何关于前端面试、就业、技术问题都可给在文章后留言。

1、盒子宽度和高度是已知的。思路:
  • 父元素相对定位;
  • 子元素绝对定位;
  • left: 50%; top: 50%;
  • margin-left: 负的一半宽度; margin-top: 负的一半高度。
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>盒子垂直水平居中demo1</title><style type="text/css">html,body {height: 100%;position: relative;overflow: hidden;}.box {height: 150px;width: 300px;background-color: antiquewhite;border: 2px solid #000;line-height: 146px;text-align: center;position: absolute;top: 50%;left: 50%;margin-top: -75px;margin-left: -150px;}</style>
</head>
<body><div class="box">盒子垂直水平居中</div>
</body>
</html>
2、盒子宽度和高度是未知的(有高、宽,但是不知道)。思路:
  • 父元素相对定位;
  • 子元素绝对定位;
  • top: 0; right: 0; bottom: 0; left: 0;
  • margin: auto;
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>盒子垂直水平居中demo2</title><style type="text/css">html,body {height: 100%;position: relative;overflow: hidden;}.box {height: 150px;width: 300px;background-color: antiquewhite;border: 2px solid #000;line-height: 146px;text-align: center;position: absolute;top: 0;right: 0;bottom: 0;left: 0;margin: auto;}</style>
</head>
<body><div class="box">盒子垂直水平居中</div>
</body>
</html>
3、平移:定位 + transform。思路:
  • 父元素相对定位;
  • 子元素绝对定位;
  • top: 50%; left: 50%;
  • transform: translate(-50%, -50%);
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>盒子垂直水平居中demo3</title><style type="text/css">html,body {height: 100%;position: relative;overflow: hidden;}.box {background-color: antiquewhite;border: 2px solid #000;line-height: 146px;text-align: center;position: absolute;top: 50%;left: 50%;transform: translate(-50%, -50%);}</style>
</head>
<body><div class="box">盒子垂直水平居中</div>
</body>
</html>
4、flex 布局。思路:
  • 在父级元素中采用flex布局:display: flex; justify-content: center; align-items: center;
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>盒子垂直水平居中demo4</title><style type="text/css">html,body {height: 100%;overflow: hidden;display: flex;justify-content: center;align-items: center;}.box {height: 150px;width: 300px;background-color: antiquewhite;border: 2px solid #000;line-height: 146px;text-align: center;}</style>
</head>
<body><div class="box">盒子垂直水平居中</div>
</body>
</html>
5、父元素:display: table-cell 布局。思路:
  • 父元素:display: table-cell; vertical-align: middle; text-align: center;
  • 父元素有固定的宽高;
  • 子元素:display: inline-block;
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>盒子垂直水平居中demo6</title><style type="text/css">.box1 {height: 300px;width: 600px;background-color: blue;display: table-cell;vertical-align: middle;text-align: center;overflow: hidden;}.box2 {display: inline-block;height: 150px;width: 300px;background-color: antiquewhite;border: 2px solid #000;line-height: 146px;text-align: center;}</style>
</head>
<body><div class="box1"><div class="box2">盒子垂直水平居中</div></div>
</body>
</html>
6、通过JavaScript的方式。思路:
  • 父元素相对定位;
  • 子元素绝对定位;
  • 获取父元素的 clientHeight 和 clientWidth;
  • 获取子元素的 offsetHeight 和 offsetWidth;
  • 计算子元素的 top 和 left。
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>盒子垂直水平居中demo6</title><style type="text/css">html,body {height: 100%;overflow: hidden;position: relative;}.box {height: 150px;width: 300px;background-color: antiquewhite;border: 2px solid #000;line-height: 146px;text-align: center;position: absolute;}</style>
</head>
<body><div class="box" id="box">盒子垂直水平居中</div><script type="text/javascript">let HTML = document.documentElement,winH = HTML.clientHeight,winW = HTML.clientWidth,boxH = box.offsetHeight,boxW = box.offsetWidth;box.style.top = (winH - boxH) / 2 + "px";box.style.left = (winW - boxW) / 2 + "px";</script>
</body>
</html>

博主水平有限,若发现文中存在问题,欢迎留言指正!

学习之路永无止境!
http://www.khdw.cn/news/47361.html

相关文章:

  • 滨江网站制作运营推广计划怎么写
  • 网站高中建设工具黑帽seo排名优化
  • 全网型网站建设方案软考培训机构排名
  • 贵阳网站维护培训电子商务营销策略
  • 新乡 网站开发百度快照是干什么的
  • 江苏威达建设有限公司网站电销名单渠道在哪里找
  • 网络设计师培训平台浙江seo推广
  • 深圳沙井做网站爱站网关键词工具
  • 电子商务网站建设大作业b2b网站免费推广平台
  • wordpress手机显示不了图片seo外链发布技巧
  • 实时开奖走势网站建设建站之星官方网站
  • 苹果商店app下载化工seo顾问
  • 石家庄房产信息网查询系统优化大师官网入口
  • 营销型网站三要素正规软件开发培训学校
  • 结合公众号小店做网站推广app平台
  • 青岛做网站青岛做网站百度app最新版本
  • 旅行用品东莞网站建设阿里大数据分析平台
  • 网站建设课程设计百度文库今日国际新闻最新消息大事
  • 微网站开发平台系统软件指数基金定投技巧
  • 构建动态网站设计全球搜索引擎排名
  • 做网站一般图片多大关键词排名查询api
  • 专业做调查的网站网站免费推广平台
  • 东莞整站优化推广公司找火速聊城网站推广的公司
  • 企业网站用wordpress网站管理和维护的主要工作有哪些
  • 专业做物业网站的公司吗上海正规seo公司
  • 建设网站比较好东莞营销网站建设优化
  • 网站制做拉新推广怎么做代理
  • 哪里网站建设千网推软文推广平台
  • 丹阳做公司网站的每日新闻最新消息
  • 简单的购物网站怎么做网络营销概述