简体   繁体   English

HTML/CSS 表单样式

[英]HTML/CSS form styles

I'm trying to make a file sharing website but having trouble styling the upload forms I have as my design is quite advanced instead of setting the indivdual styles i'm trying to get set the design as a background image.我正在尝试创建一个文件共享网站,但是在为我的上传表单设置样式时遇到了麻烦,因为我的设计非常先进,而不是设置个人样式,我正在尝试将设计设置为背景图像。

This is my design - http://icap.me/i/s5YIbheY3g.png这是我的设计 - http://icap.me/i/s5YIbheY3g.png

This is it currently effort - http://icap.me/i/ODuzJOQMhS.png这是目前的努力 - http://icap.me/i/ODuzJOQMhS.png

So far I set the style of the upload button by using the following code -到目前为止,我使用以下代码设置了上传按钮的样式 -

form input[type=submit] {
background : url("../img/upload.png") no-repeat center center;
width : 115px;
height :52px;
border : none;
color : transparent;
font-size : 0

} }

do you know how I could use an image to style my other form buttons here is the html -你知道我如何使用图像来设计我的其他表单按钮的样式吗?

            <form action="upload_file.php" method="post"enctype="multipart/form-data">
        <input type="file" name="file" id="file" />
        <br />
        <input type="submit" name="submit" value="Submit" />
        <input type="checkbox" name="vehicle" value="Bike">I agree to the terms and conditions<br>
        </form>

Styling some form elements suck, and unfortunately, the file element is one of those elements.样式化一些表单元素很糟糕,不幸的是,文件元素就是这些元素之一。 This is because the browser actually derives the control itself from the operating system (which means you have absolutely no control over how it looks).这是因为浏览器实际上是从操作系统派生控件本身(这意味着您完全无法控制它的外观)。 What this means for you is that in order to style it, you will need JavaScript and some CSS hackary.这对您来说意味着,为了设置样式,您将需要 JavaScript 和一些 CSS hackary。

Quirksmode has a great step by step for doing it, at least to get you started. Quirksmode 有一个很好的一步一步来做,至少让你开始。

The basics of which, though, are:但是,其中的基础知识是:

  1. Style your normal file input with position: relative .使用position: relative普通文件输入的样式。
  2. Add a new plain old text input and position it on top of the file input.添加一个新的纯旧文本输入并将其放置在文件输入的顶部。
  3. Style the text input to look like the file input将文本输入设置为看起来像文件输入
  4. Drop the file input's opacity to 0, so that it's invisible, but still clickable (this is key, because you're still actually using the file input)将文件输入的opacity设为 0,使其不可见,但仍可点击(这是关键,因为您实际上仍在使用文件输入)
  5. Use JavaScript to put the filename into the text input使用 JavaScript 将文件名放入文本输入

This one's kind of primitive and not very standards-compliant (extra elements and all that).这是一种原始的,不是很符合标准(额外的元素等等)。 If you're already using a JavaScript library (jQuery, MooTools, etc), you may be able to find a plugin that will handle the control itself, and you just add styling to that.如果您已经在使用 JavaScript 库(jQuery、MooTools 等),您可能会找到一个可以处理控件本身的插件,您只需为其添加样式即可。 The advantage to this method is that you won't necessarily need to add extra elements yourself (so you don't have a stray input field lying around), and the JavaScript (ideally) picks up the presence of your file input(s) and "fixes" them accordingly.这种方法的优点是您不一定需要自己添加额外的元素(因此您不会有一个杂散的input字段),并且 JavaScript(理想情况下)会获取您的文件输入的存在并相应地“修复”它们。

For styling browse button you need to take help of css-javascript duo or something like twitter bootstrap which just works out of the box 1 .. Also, check this post and this article对于样式浏览按钮,您需要借助 css-javascript duo 或类似twitter bootstrap 之类的东西,它可以开箱即用1 .. 另外, 请查看这篇文章这篇文章

As a personal view, i feel that form elements like browse button and drop-down menus shouldn't be tweaked much..giving out two benefits..one, faster developments..and two, cross-browser symmetry..作为个人观点,我觉得像浏览按钮和下拉菜单这样的表单元素不应该做太多调整..给出两个好处..一个,更快的开发..第二个,跨浏览器对称..

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

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