html - 如何使图像居中

标签 html css

我有一个网站,其中有一个圆形图片。

我希望该图像始终位于中心。(小/中/大屏幕)

清除它visit .

代码在这里:-

<html>
<head>
<title>
Maintenance in Progress
</title>
<style>
.timer {
  text-align: center;
  font-size: 60px;
  color: white;
   position: absolute;
    right: 500px;
    bottom: 0;
}
body {
    background-repeat: no-repeat;
    background-size: 100% 100%;
}
.utxt{
    position: absolute;
}

.circle{
    position: absolute;
    top: 50%;
    left: 50%;
}
.dtxt{
    position: absolute;
    bottom: 0;
}
</style>
</head>
<body background="maintenance/bg.png">
<img class="utxt" src="maintenance/utxt.png"></img>
<img class="circle" src="maintenance/circle.png"></img>
<img class="dtxt" src="maintenance/dtxt.png"></img>
<div class="timer" id="demo"></div>
</body>
</html>

请帮帮我!

最佳答案

transform: translate(-50%, -50%); 添加到您现有的 .circle 样式中。

.circle{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}

这里有完整的代码和更新。

<html>
<head>
<title>
Maintenance in Progress
</title>
<style>
.timer {
  text-align: center;
  font-size: 60px;
  color: white;
   position: absolute;
    right: 500px;
    bottom: 0;
}
body {
    background-repeat: no-repeat;
    background-size: 100% 100%;
}
.utxt{
    position: absolute;
}

.circle{
    position: absolute;
    top: 50%;
    left: 50%;
transform: translate(-50%, -50%);
}
.dtxt{
    position: absolute;
    bottom: 0;
}
</style>
</head>
<body background="maintenance/bg.png">
<img class="utxt" src="maintenance/utxt.png"></img>
<img class="circle" src="maintenance/circle.png"></img>
<img class="dtxt" src="maintenance/dtxt.png"></img>
<div class="timer" id="demo"></div>
</body>
</html>

很高兴为您提供帮助。

关于html - 如何使图像居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43899126/

相关文章:

css3 需要帮助来理解 box-sizing

php - 将可变文本嵌入到 php/html 网页中

jquery - 让 Jquery lavalamp 成为 fieldset 的传奇

html - 如何对齐容器边框的文本

javascript - 如何将 HTML 文本插入 jQuery

javascript - 如何让我的 Div2 直接位于我的 Div1 下方

css - 无限滑动CSS3渐变

html - 图片自动间距?

css - VS2010 Crystal 报表页面出现滚动条

javascript - 新建iframe并同步加载内容