- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为一个类(class)元素制作网页,我已经设置好框架,但是我遇到了一个问题。我无法让这张图片在我的生活中居中对齐。它目前位于屏幕右侧,我就是无法移动它。您很可能需要将其粘贴到浏览器中才能准确了解正在发生的事情。
initComparisons();
function initComparisons() {
var x, i;
/*find all elements with an "overlay" class:*/
x = document.getElementsByClassName("img-comp-overlay center");
for (i = 0; i < x.length; i++) {
/*once for each "overlay" element:
pass the "overlay" element as a parameter when executing the compareImages function:*/
compareImages(x[i]);
}
function compareImages(img) {
var slider, img, clicked = 0, w, h;
/*get the width and height of the img element*/
w = img.offsetWidth;
h = img.offsetHeight;
/*set the width of the img element to 50%:*/
img.style.width = (w / 2) + "px";
/*create slider:*/
slider = document.createElement("DIV");
slider.setAttribute("class", "img-comp-slider");
/*insert slider*/
img.parentElement.insertBefore(slider, img);
/*position the slider in the middle:*/
slider.style.top = (h / 2) - (slider.offsetHeight / 2) + "px";
slider.style.left = (w / 2) - (slider.offsetWidth / 2) + "px";
/*execute a function when the mouse button is pressed:*/
slider.addEventListener("mousedown", slideReady);
/*and another function when the mouse button is released:*/
window.addEventListener("mouseup", slideFinish);
/*or touched (for touch screens:*/
slider.addEventListener("touchstart", slideReady);
/*and released (for touch screens:*/
window.addEventListener("touchstop", slideFinish);
function slideReady(e) {
/*prevent any other actions that may occur when moving over the image:*/
e.preventDefault();
/*the slider is now clicked and ready to move:*/
clicked = 1;
/*execute a function when the slider is moved:*/
window.addEventListener("mousemove", slideMove);
window.addEventListener("touchmove", slideMove);
}
function slideFinish() {
/*the slider is no longer clicked:*/
clicked = 0;
}
function slideMove(e) {
var pos;
/*if the slider is no longer clicked, exit this function:*/
if (clicked == 0) return false;
/*get the cursor's x position:*/
pos = getCursorPos(e)
/*prevent the slider from being positioned outside the image:*/
if (pos < 0) pos = 0;
if (pos > w) pos = w;
/*execute a function that will resize the overlay image according to the cursor:*/
slide(pos);
}
function getCursorPos(e) {
var a, x = 0;
e = e || window.event;
/*get the x positions of the image:*/
a = img.getBoundingClientRect();
/*calculate the cursor's x coordinate, relative to the image:*/
x = e.pageX - a.left;
/*consider any page scrolling:*/
x = x - window.pageXOffset;
return x;
}
function slide(x) {
/*resize the image:*/
img.style.width = x + "px";
/*position the slider:*/
slider.style.left = img.offsetWidth - (slider.offsetWidth / 2) + "px";
}
}
}
body {
margin: 0;}
#bg {
position: fixed;
top: 0;
left: 0;
/* Preserve aspet ratio */
min-width: 100%;
min-height: 100%;
}
ul.topnav {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
background-color: rgba(0,255,255, 0.3);
backdrop-filter: blur(5px);
-webkit-backdrop-filter: blur(5px);
max-width: 100%;
max-height: 100%;
overflow: auto;
}
.center {
display: flex;
justify-content: center;
flex-direction: column;
}
ul.topnav li {float: left;}
ul.topnav li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
ul.topnav li a:hover:not(.active) { background-color: rgba(47,79,79, 0.6);
backdrop-filter: blur(5px);
-webkit-backdrop-filter: blur(5px);}
ul.topnav li a.active {background-color: rgba(112,128,144, 0.6);
backdrop-filter: blur(5px);
-webkit-backdrop-filter: blur(5px);}
ul.topnav li.right {float: right;}
@media screen and (max-width: 600px){
ul.topnav li.right,
ul.topnav li {float: none;}
}
.tanddblur {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
align-content: center;
align-self:center;
background-color: #333;
background-color: rgba(47,79,79, 0.5);
backdrop-filter: blur(5px);
-webkit-backdrop-filter: blur(5px);
overflow: auto;
padding-left:10px;
padding-right:10px;
border-style: solid;
border-color: darkslategray;
border-radius:15px;
padding-top:10px;
padding-bottom:10px;
}
.parent {
position: relative;
}
.child {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
* {box-sizing: border-box;}
.img-comp-container {
position: absolute;
height: 200px; /*should be the same height as the images*/
top: 50%;
left: 50%;
right:50%;
transform: translate(-50%, -50%);
}
.img-comp-img {
position: absolute;
width: auto;
height: auto;
overflow: hidden;
}
.img-comp-img img {
display: block;
vertical-align: middle;
}
.img-comp-slider {
position:absolute;
https://www.w3schools.com/howto/img_fjords.jpg z-index: 9;
cursor: ew-resize;
/*set the appearance of the slider:*/
width: 40px;
height: 40px;
background-color: #2196F3;
opacity: 0.7;
border-radius: 50%;
}
#display_image
{
align-self:center;
}
<img src="webpagepic.jpg" id="bg" alt="">
<ul class="topnav">
<li><a class= "active" href="#news">Reenacted Photos</a></li>
<li><a href="navpage.html">Terms & Definitions</a></li>
<li><a href="#contact">Video</a></li>
<li><a href="#about">Review Links</a></li>
<li class="right"><a href="index.html">Return Home</a></li>
</ul>
<div align= 'center' class="img-comp-container center">
<div align= 'center' class="img-comp-img">
<img src="https://www.w3schools.com/howto/img_forest.jpg" width="600" height="300">
</div>
<div align= 'center' class="img-comp-img img-comp-overlay center">
<img src="https://www.w3schools.com/howto/img_fjords.jpg" width="600" height="300">
</div>
</div>
<div>
最佳答案
对您的 CSS 进行以下更改。基本上,为 left
分配一个百分比,相对于容器的宽度移动图像,为 top
分配一个百分比,使图像相对于父容器的高度移动。我使用 calc 来完美地居中图像。例如,容器的宽度为 600 像素,因此水平中心为 50% - 300 像素(图像宽度的一半)。
最后,我为 html 和 body 分配了宽度和高度,以便 body 的长度和宽度与浏览器窗口相同。
.img-comp-container {
position: absolute;
left: calc(50% - 300px);
top: calc(50% - 23px);
height: 200px; /*should be the same height as the images*/
width: 600px;
}
html,body{
width:100%;
height:100%;
margin:0;
}
关于javascript - 居中对齐位于 javascript 中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50179404/
我正在尝试将 Bootstrap 输入字段置于列 div 的中心,但我尝试过的所有方法似乎都不起作用。 到目前为止我尝试了什么: Enter the inf
这是它的样子: http://i.imgur.com/H0Oqz4Q.png 这是 CSS: #header{ background:url('header.png'); border-radius:
似乎有一个 align 属性工作得非常好,但是可以对齐元素,因此面板上的所有元素都将对齐,以在彼此底部居中,如果它们都小于容器尺寸?类似顶部中心中心的东西。 类似这样的事情: 或者至少水平方向和垂直方
我用 GUI 创建了一个简单的猜谜游戏。问题是,每当我最大化窗口时,整个 GUI 都会卡在顶部中间。我想知道如何将其居中以及如何使其变大。代码如下: import javax.swing.*;
目前我在另一个 View 中有一个 View (它是一个广告),但是因为我使用的是 MATCH_PARENT,所以宽度是整个屏幕的长度,而我只希望它是广告尺寸。现在 WRAP_CONTENT 解决了这
我有一个 UIViewController 子类,它实例化了一个 UIView 子类(我们称之为 viewA)。然后,viewA 有时会实例化另一个 UIView,我们称之为 viewB。 我希望 v
我是 Cocca 和 IOS 开发的新手,发现自己处于以下情况。 我有一张 1024x1024 的背景图片,我想在所有 View 中显示它。我已将以下代码放在应用程序委托(delegate)中的应用程
我正在尝试使用 MathML 作为 HTML5 的一部分来制作居中的盒装数学方程式。问题是盒子。如果我在我的 div 元素上放置一个边框,边框足够高,但它一直延伸到屏幕的左侧和右侧。如果我在我的数学元
我知道这听起来很简单,但它不适合我。我做错了什么? .popuphdr { background-color:#00477f; height:30px; width
我正在为我的网店创建一个新网站 - 我遇到了这个 css 问题...... 系统是在prestashop平台上制作的,但是这是基本的CSS,所以没关系。 在 CMS 页面上,我在将页面居中时遇到问题,
我有一个横跨整个屏幕宽度的按钮: accusantium quia sunt 44% 我希望第一个段落标签中的文本居中,其背景图像紧挨着文本。问题是第一个 居中
http://makememodern.com/portfolio/ 您会看到我在页面上嵌入了一个网站,并且它与页面右侧对齐。我希望它居中。 最佳答案 您将 iframe 的宽度设置为 1100
我的 header 中有一个元素正在从 js 文件中获取数据。 我试图将该元素置于我的页面的中心,但我所做的一切似乎都有效。 我尝试了 margin-left: auto 和 margin-right
这个问题在这里已经有了答案: What does auto do in margin: 0 auto? (8 个答案) 关闭 7 年前。
我试图让这两个按钮并排对齐,在页面的中心垂直和水平。 几个小时以来,我一直在摆弄它,尝试了所有方法,但我无法让它既与页面居中对齐又并排对齐 我希望有人能给我指出正确的方向。谢谢..
我需要将一个 img 居中(带有 class=“key”的那个,但是 float 元素阻止了它。我应该使用什么技术将其居中? 谢谢! GitHub 存储库:https://github.com/Cal
每次我嵌入来自 Google map 的 iframe 时,它都会将标记保留在中间。 即使有工具提示并且只是剪切工具提示数据,它也会这样做: http://jsfiddle.net/V2SVa/
我无法将这些按钮置于页面中央。我只知道我错过了一些愚蠢的东西,但我不知道是什么。这是页面: All Time Last 2 Weeks La
我如何将 div 内的表格 div 对齐到 align=center 最佳答案 asd 关于html - div对齐=居中,我们在Stack Overflow上找到一个类似的问题: htt
有人知道如何在调整浏览器窗口大小时也实现垂直居中吗? 水平效果很好,图像大小调整也很好。我希望图片和链接始终在浏览器中间居中。 另外,为什么 ul 没有像图像那样居中而是向右移动了一点? Here i
我是一名优秀的程序员,十分优秀!