为什么在我给其中的<span>添加类时,<Div>消失了?

huangapple go评论65阅读模式
英文:

Why is my <Div> disappearing when I add Class to my <span> within it?

问题

我试图将一个变量通过CSS显示在我的HTML页面上,用于OBS流媒体软件中的图形显示。每次我将类.wrappers添加到span id p1Name(以及p2Name),文本就会在OBS中的HTML输出中消失。是什么导致文本消失?否则,在我不包含类.wrappers时,它完美地显示出来。

我尝试过修改整个页面设置,类规格和移动对象本身,但文本似乎只是消失了。

编辑 在wrappers中更改不透明度不会影响对象的可见性。

英文:

I'm trying to take a variable and display it on my html page via CSS for a Graphical display in OBS streaming software.
Every time I add the class .wrappers to the span id p1Name (as well as p2Name) the text disappears from the html output in OBS.
What is causing the text to disappear? As otherwise it perfectly is displayed when I don't include the class .wrappers

I've tried modifying overall page settings, the class specifications and moving the object itself but the text just seems to have disappeared.

Edit Changing the opacity within wrappers does not affect the visibility of the object

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

//Time stuff
let time = document.getElementById(&quot;current-time&quot;);

setInterval(() =&gt; {
  let d = new Date();
  time.innerHTML = d.toLocaleTimeString(navigator.language, {
    hourCycle: &#39;h23&#39;,
    hour: &#39;2-digit&#39;,
    minute: &#39;2-digit&#39;
  });
}, 1000);

<!-- language: lang-css -->

@font-face {
  font-family: &quot;Futura&quot;;
  src: url(&#39;Resources/Fonts/Brandon_bld.otf&#39;);
}

* {
  margin: 0;
  padding: 0;
  font-family: &quot;Futura&quot;;
  box-sizing: border-box;
  overflow: hidden;
  white-space: nowrap;
}

.graphicBox {
  position: absolute;
  width: 1800px;
  height: 105px;
  background: rgb(51, 116, 182);
  background: linear-gradient(90deg, rgba(51, 116, 182, 0.75) 0%, rgba(110, 83, 180, 0.75) 70%);
  border-radius: 15px;
  bottom: 40px;
  left: 50px;
  filter: drop-shadow(-2px 2px 4px black);
}

.statusBox {
  position: absolute;
  font-family: &quot;Futura&quot;;
  font-weight: bold;
  padding-top: 8px;
  font-size: 40px;
  width: 130px;
  height: 70px;
  background: rgb(231, 231, 231);
  border-radius: 15px;
  text-align: center;
  bottom: 125px;
  left: 100px;
  filter: drop-shadow(-2px 2px 4px black);
}

.timeDisplay {
  width: 140px;
  height: 30px;
  display: flex;
  align-items: left;
  justify-content: center;
  position: absolute;
  font-size: 14px;
  color: white;
  bottom: 58px;
  left: 771px;
}

.timeZone {
  width: 60px;
  height: 20px;
  display: flex;
  align-items: left;
  justify-content: space-between;
  position: absolute;
  font-size: 15px;
  color: white;
  bottom: 40px;
  left: 812px;
}

.scoreboardP1 {
  position: absolute;
  left: 150px;
  bottom: 60px;
  width: 300px;
}

.scoreboardP2 {
  position: absolute;
  left: 450px;
  bottom: 60px;
  width: 300px;
}

.wrappers {
  position: absolute;
  width: 340px;
  height: 100px;
  line-height: 54px;
  top: 356px;
  opacity: 0;
  color: black;
}

#p1Wrapper {
  bottom: 540x;
  left: 300px;
  color: white;
}

#p2Wrapper {
  width: 300px;
  bottom: 20px;
  left: 100px;
  color: white;
}

.scoreDisplay {
  position: absolute;
  color: white;
  width: 60px;
  height: 60px;
  align: center;
  font-family: &quot;Avant&quot;;
}

#p1Format {
  top: 30px;
  left: 1160px;
}

#p2Format {
  top: 30px;
  left: 1450px;
}

.scoreBox {
  position: absolute;
  width: 45px;
  height: 45px;
  background: white;
  border-radius: 10px;
  align: center;
}

#p1Box {
  top: 28px;
  left: 1150px;
}

#p2Box {
  top: 28px;
  left: 1440px;
}

<!-- language: lang-html -->

&lt;div class=&quot;graphicBox&quot;&gt;
&lt;/div&gt;

&lt;div class=&quot;statusBox&quot;&gt;
  &lt;p&gt;NEXT&lt;/p&gt;
&lt;/div&gt;


&lt;div class=&quot;timeDisplay&quot;&gt;
  &lt;h1 id=&quot;current-time&quot;&gt;&lt;/h1&gt;
&lt;/div&gt;



&lt;div class=&quot;timeZone&quot;&gt;
  &lt;p&gt;EST&lt;/p&gt;
&lt;/div&gt;


&lt;div id=&quot;overlayP1&quot; class=&quot;scoreboardP1&quot;&gt;
  &lt;span id=&quot;p1Wrapper&quot; class=&quot;wrappers&quot;&gt;
            &lt;span id=&quot;p1Name&quot; class=&quot;names&quot;&gt;&lt;/span&gt;
  &lt;/span&gt;
&lt;/div&gt;

&lt;div class=&quot;scoreboardP2&quot;&gt;
  &lt;span id=&quot;p2Wrapper&quot;&gt;
            &lt;span id=&quot;p2Name&quot; class=&quot;names&quot;&gt;&lt;/span&gt;
  &lt;/span&gt;
&lt;/div&gt;

<!-- end snippet -->

答案1

得分: 0

CSS类.wrappers中的问题似乎有两个。

因为.wrappers具有position: absolute属性,元素会从屏幕中消失。
另外,通过设置opacity: 0属性,该项目将变为不可见。

因此,通过在CSS中注释掉这些元素:

.wrappers {
  /* position: absolute; */
  width: 340px;
  height: 100px;
  line-height: 54px;
  top: 356px;
  /* opacity: 0; */
  color: black;
}

现在,当将wrappers类添加到父级span p1Wrapperp2Wrapper中时,我可以看到p1Namep2Name两者,就像这样:

<span id="p1Wrapper" class="wrappers">

另外,一些快速注意事项:

  • align: center 不是有效的CSS属性。
  • 在测试中,我在p1Name span中添加了一些词语"testp2",以便在格式化后看到更改:<span id="p2Name" class="names">testp2</span>
英文:

The problem seem to be two things in the CSS class .wrappers.

Because .wrappers has the property position: absolute, the element was disappearing out of the screen.
Also, with the propriety opacity: 0 the item is invisible.

So, by commenting out these elements in the CSS:

  .wrappers {
    /* position: absolute; */
    width: 340px;
    height: 100px;
    line-height: 54px;
    top: 356px;
    /* opacity: 0; */
    color: black;
  }

I can now see both p1Name and p2Name when the parent span p1Wrapper and p2Wrapper have the wrappers class added to them, like this:

&lt;span id=&quot;p1Wrapper&quot; class=&quot;wrappers&quot;&gt;

Also, just some quick notes:

  • align: center is not a valid CSS property.
  • While testing I added inside the p1Name span some words "testp2" so I could see the changes after formatting: &lt;span id=&quot;p2Name&quot; class=&quot;names&quot;&gt;testp2&lt;/span&gt;

huangapple
  • 本文由 发表于 2023年2月16日 06:20:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/75465970.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定