我在 CSS 方面遇到了一点麻烦,似乎找不到解决方案
<div id="closelink"> <a href="">Close</a> Click to close </div>
现在我只想隐藏文本“ Click to close”,而不隐藏 div 和其中的链接。
这能做到吗?
Try
#closelink { position: relative; left: -9999px; } #closelink a { position: relative; left: 9999px; }
The visibility attribute can be overriden on children elements, so you are able to do this:
visibility
#closelink { visibility: collapse; } #closelink a { visibility: visible; }
It works but you can use visibility:hidden instead of visibility:collapse
visibility:hidden
visibility:collapse
To avoid the child element breaking to a new line (as happens with just using visibility: hidden/collapse and visibility: visible), and to avoid drawing a 9999px block in the browser (generally frowned upon as it is unnecessary overhead), try this:
visibility: hidden/collapse
visibility: visible
#closelink { position: relative; visibility: hidden; } #closelink a { position: absolute; left: 0; top: 0; visibility: visible; }
You can adjust your left: 0 value to provide some padding.
left: 0
There are three methods I could think of:
One
#parent { opacity: 1; } .child { opacity: 0; }
<div id="parent"> dkjfdkf <span class="child">Annoying text</span> </div>
Two
.child { visibility: hidden; }
Three
.child { display: none; }
Opacity is best if you want the image to always be on the page to keep the structure but, you don't want it to be visible. Hope this was helpful.
.closelink { font-size: 0px; } .close-link a { font-size: 12px; }