我可以停止100%宽度的文本框超出其容器?(Can I stop 100% Width Text Boxes from extending beyond their containers?)
让我说我有一个文本框,我想填充一行。 我会给它一个这样的风格:
input.wide {display:block; width: 100%}
这会导致问题,因为宽度是基于文本框的内容。 默认情况下,文本框具有边距,边框和填充,这使得宽度为100%的文本框大于其容器。
例如,在右边:
有没有办法使文本框填充其容器的宽度,而不扩展它?
下面是一些示例HTML,以显示我的意思:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Untitled Page</title> <style type="text/css"> #outer{border: 1px solid #000; width: 320px; margin: 0px;padding:0px} #inner{margin: 20px; padding: 20px; background: #999;border: 1px solid #000;} input.wide {display:block; margin: 0px} input.normal {display:block; float: right} </style> </head> <body> <div id="outer"> <div id="inner"> <input type="text" class="wide" /> <input type="text" class="normal" /> <div style="clear:both;"></div> </div> </div> </body> </html>
如果这是运行,您可以通过查看“正常”文本框看到“宽”文本框伸出容器之外。 “正常”文本框浮动到容器的实际边缘。 我试图使“宽”文本框填充其容器,而不会像“正常”文本框那样扩展到边缘之外。
Lets say I have a text box that I want to fill a whole line. I would give it a style like this:
input.wide {display:block; width: 100%}
This causes problems because the width is based on the content of the text box. Text boxes have margin, borders, & padding by default, which makes a 100% width text box larger than its container.
For example, here on the right:
Is there any way to make a text box fill the width of its container without expanding beyond it?
Here is some example HTML to show what I mean:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Untitled Page</title> <style type="text/css"> #outer{border: 1px solid #000; width: 320px; margin: 0px;padding:0px} #inner{margin: 20px; padding: 20px; background: #999;border: 1px solid #000;} input.wide {display:block; margin: 0px} input.normal {display:block; float: right} </style> </head> <body> <div id="outer"> <div id="inner"> <input type="text" class="wide" /> <input type="text" class="normal" /> <div style="clear:both;"></div> </div> </div> </body> </html>
If this is run, you can see by looking at the "normal" text box that the "wide" text box is sticking out beyond the container. The "normal" text box floats to the actual edge of the container. I'm trying to make the "wide" text box fill its container, without expanding beyond edge like the "normal" text box is.
原文:https://stackoverflow.com/questions/628500
最满意答案
虽然我倾向于同意@AlekDavis的评论 ,但是在NT shell中仍然有几种方法来做到这一点。
我将利用SHIFT命令和IF条件分支的方法,这样的事情...
@ECHO OFF SET man1=%1 SET man2=%2 SHIFT & SHIFT :loop IF NOT "%1"=="" ( IF "%1"=="-username" ( SET user=%2 SHIFT ) IF "%1"=="-otheroption" ( SET other=%2 SHIFT ) SHIFT GOTO :loop ) ECHO Man1 = %man1% ECHO Man2 = %man2% ECHO Username = %user% ECHO Other option = %other% REM ...do stuff here... :theend
Though I tend to agree with @AlekDavis' comment, there are nonetheless several ways to do this in the NT shell.
The approach I would take advantage of the SHIFT command and IF conditional branching, something like this...
@ECHO OFF SET man1=%1 SET man2=%2 SHIFT & SHIFT :loop IF NOT "%1"=="" ( IF "%1"=="-username" ( SET user=%2 SHIFT ) IF "%1"=="-otheroption" ( SET other=%2 SHIFT ) SHIFT GOTO :loop ) ECHO Man1 = %man1% ECHO Man2 = %man2% ECHO Username = %user% ECHO Other option = %other% REM ...do stuff here... :theend
相关问答
更多-
看到你'真的很想看到子字符串的工作',这里是你的脚本结构化和编码,如你所愿。 @Set "CMD_LINE_ARGS=%*" @Rem Remove all chars and port arg @Set "PORT_ARG_REMOVED=%CMD_LINE_ARGS:*-port =%" @Rem Remove trailing chars @Set "PORT_NUM=%PORT_ARG_REMOVED: ="&:"%" @Echo %PORT_NUM% @Pause Seeing as you ' ...
-
虽然我倾向于同意@AlekDavis的评论 ,但是在NT shell中仍然有几种方法来做到这一点。 我将利用SHIFT命令和IF条件分支的方法,这样的事情... @ECHO OFF SET man1=%1 SET man2=%2 SHIFT & SHIFT :loop IF NOT "%1"=="" ( IF "%1"=="-username" ( SET user=%2 SHIFT ) IF "%1"=="-otheroption" ( ...
-
从Windows批处理文件中读取文件并调用另一个.bat(Reading a file and calling another .bat from within a Windows batch file)[2022-01-28]
1)为了防止,你必须拆卸它。 所以你的方法走向了正确的方向。 只需将其扩展一点以使其更灵活: setlocal enabledelayedexpansion set /p build=version.txt .\deploy.bat -versio ... -
您可以使用%0 , %1 , %2格式的cmd行参数。 使用当前代码中的%~d0 ,您将从参数%0中提取letter drive 。 这个MS页面可能对您有所帮助 。 奇怪的是,如果我点击它,链接就可以工作,但对某些用户来说并不适用。 如果您想将其粘贴到首选浏览器中,则可以使用以下路径。 正如您在链接中看到的,这是从WindowsXP文档中提取的,这可以解释为什么链接充其量只是片状。 https://www.microsoft.com/resources/documentation/windows/xp/a ...
-
Srvany: http : //support.microsoft.com/kb/137890 RunAsService: http: //runasservice.sourceforge.net/ Nssm: http ://nssm.cc/ Srvany: http://support.microsoft.com/kb/137890 RunAsService: http://runasservice.sourceforge.net/ Nssm: http://nssm.cc/
-
这里有两种方法(其他方法也是可能的),假设参数与问题中的相同: @echo off :: mind that '=' will be taken as blank space when parsing arguments. :: and `--user=admin` are two arguments. :: 1) with for /l setlocal enableDelayedExpansion rem max count of the expected arguments set max_coun ...
-
.BAT切换解析(.BAT Switches Parsing)[2023-01-14]
哇......终于自己解决了〜我用scirpt的完整路径而不是%0替换了DEL %0 %0 ,然后一切都恢复了工作。 Aww... finally solved it myself~ I replaced the DEL %0 with scirpt's fullpath instead of %0, then everything get back working. -
Windows无法从Processing中找到“run.bat”文件(Windows can not find “run.bat” file, from Processing)[2021-11-28]
由于您是从cmd而不是直接从Java运行start命令,因此必须指定完整路径。 您可以使用System.getProperty("user.dir")获取Java项目文件夹的路径。 如果批处理文件位于项目文件夹的根目录中,则代码如下所示: p1 = r.exec("cmd /c start " + System.getProperty("user.dir") + "run.bat"); Since you are running the start command from cmd instead of ... -
似乎当前版本的摊铺机有一个与Windows系统上的virtualenv支持相关的错误,请参阅此问题 。 Seems like the current release of paver has a bug related to the virtualenv support on windows systems see this issue.
-
问题是当以管理员身份运行时,当前工作目录将更改为C:\ Windows \ System32。 我的解决方案是显式更改caller.bat中的当前工作目录,使其与运行文件的目录相同。 这是通过从%0参数中提取驱动器和路径来完成的,如下所示: cd /D %~dp0 call callee.bat pause cd的/ D参数会导致目录和路径发生变化,并且需要处理调用者.bat文件不在C:驱动器上的情况。 更多信息: Windows批处理文件的隐藏功能 The problem is that when ru ...