Home  >  Article  >  Web Front-end  >  css怎么实现浏览器窗口改变大小后样式还是居中_html/css_WEB-ITnose

css怎么实现浏览器窗口改变大小后样式还是居中_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-21 08:56:00949browse

css怎么实现浏览器窗口改变大小后样式始终居中。
浏览器最小化后样式右边看不见了,要的效果是最小化后还是居中显示,应该怎么实现,求高手。


回复讨论(解决方案)

不是太明白你的问题,随浏览器大小变化让一个元素始终居中不难

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Swapping Songs</title><style>body{margin:0;padding:0;width:100%;background:#ddd}#a{margin:0 auto;width:10%;}        p{background-color:#f00;display:inline-block}</style></head><body><div id="a">        <p>这是一段文字描述</p></div></body></html>


第一个这个图片是最大化样式居中

第二个图片浏览器最小化样式还是居中,实现这样的效果

body{margin:0;padding:0;position:relative;}
warp{position:absolute ;left:50%;top;50%;transform:translate(-50%,-50%)}


上下左右剧中

因为人家写的都是 百分比的尺寸

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn