简体   繁体   English

CSS不适用于div元素

[英]Css not applying on div element

I have this problem with my css, I'm trying to make my X button appear to the top right corner of my the div frame. 我的CSS遇到了这个问题,我试图使我的X按钮出现在div框的右上角。 The problem is that it is just not appearing anywhere. 问题在于它只是没有出现在任何地方。 the codes seems okay to me. 代码对我来说似乎还可以。 I wonder what is causing this problem?. 我想知道是什么引起了这个问题? Can someone help? 有人可以帮忙吗? Please run the snippet you will see that the button x is not appearing at all!and I apologize for the unnecessary long html codes. 请运行代码段,您将发现按钮x根本没有出现!对于不必要的长html代码,我深表歉意。

 .x { position: absolute; background: red; color: white; top: -10%; right: -10%; } 
 <div class="divider"></div> <div class="frame" onmouseover=""><button class="x">X</button><!--This button--> <div class="section"> <h5>Only take into consideration of the x button</h5> <center> <div class="uploader" onclick="selectFile(this)"></div><input type="file" name="userprofile_picture" accept="image/*" onchange="handleImage(this)" /></center> <div class="grid-container"> <div class="grid-item"> <p style="color:white">A) '+A+'</p> </div> <div class="grid-item"> <p style="color:white">B) '+C+'</p> </div> <div class="grid-item"> <p style="color:white">C) '+B+'</p> </div> <div class="grid-item"> <p style="color:white">D) '+D+'</p> </div> </div> <div class="grid-container3"> <div class="grid-item"><span style="color:green;font-weight:bold">Answer: '+answer+'</span></div> <div class="grid-item"></div> <div class="grid-item"></div> <div class="grid-item"><input class="timer" type="range" min="3" max="20" value="10" oninput="showValue(this)"> <h4> <p>5 Minutes</p> </h4> </div> </div> </div> </div><br> 

Your values are wrong. 您的价值观是错误的。 You're placing it on the top right corner and outside of the frame because of the negative values. 由于值为负,因此将其放置在框架的右上角和外部。 Try this: 尝试这个:

.x {
    position: absolute;
    background: red;
    color: white;
    top: 10%;
    right: 10%;
}

There is a problem with your positioning 您的定位有问题

The absolute position makes it to the top right-hand corner, from right to left. 绝对位置使其从右到左位于右上角。 By making it -10% you are taking it off the screen. 通过将其设为-10%,您可以将其从屏幕上删除。 You could position it with a positive number 您可以将其定位为正数

Without positioning 没有定位 没有定位

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM