Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
381 views
in Technique[技术] by (71.8m points)

html - 如何创建一个不创建换行符或水平空格的隐藏div?(How do you create a hidden div that doesn't create a line break or horizontal space?)

I want to have a hidden checkbox that doesn't take up any space on the screen.

(我希望有一个隐藏的复选框,不占用屏幕上的任何空间。)

If I have this:

(如果我有这个:)

<div id="divCheckbox" style="visibility: hidden">

I don't see the checkbox, but it still creates a new line.

(我没有看到复选框,但仍然会创建一个新行。)

If I have this:

(如果我有这个:)

<div id="divCheckbox" style="visibility: hidden; display:inline;">

it no longer creates a new line, but it takes up horizontal space on the screen.

(它不再创建新行,但占用屏幕上的水平空间。)

Is there a way to have a hidden div that takes up no room (vertical or horizontal?

(有没有办法让隐藏的div不占用任何空间(垂直或水平?)

  ask by leora translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use display:none;

(使用display:none;)

<div id="divCheckbox" style="display: none;">
  • visibility: hidden hides the element, but it still takes up space in the layout.

    (visibility: hidden隐藏了元素,但它仍然占用了布局中的空间。)

  • display: none removes the element completely from the document, it doesn't take up any space.

    (display: none从文档中完全删除元素,它不占用任何空间。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...