如果您对什么是最好的CSS技巧,以减少您需要多少HTML?感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解什么是最好的CSS技巧,以减少您需要多少HTML?的各种细节,此外还有关于22个必须知道
如果您对什么是最好的CSS技巧,以减少您需要多少HTML?感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解什么是最好的CSS技巧,以减少您需要多少HTML?的各种细节,此外还有关于22个必须知道的css技巧_html/css_WEB-ITnose、ASP.NET自定义控件 – 什么是最好的方式来包括嵌入式CSS引用一次?、css – 什么是最好的方法来编码标题/标题为或,像我们有?、css – 什么是最好的方法来设置复选框列表的实用技巧。
本文目录一览:- 什么是最好的CSS技巧,以减少您需要多少HTML?
- 22个必须知道的css技巧_html/css_WEB-ITnose
- ASP.NET自定义控件 – 什么是最好的方式来包括嵌入式CSS引用一次?
- css – 什么是最好的方法来编码标题/标题为或,像我们有?
- css – 什么是最好的方法来设置复选框列表
什么是最好的CSS技巧,以减少您需要多少HTML?
>将HTML IMG替换为CSS背景图像,用于非“内容”的图形.
>用CSS代替HTML文本:before和content,用于不是’content’的文本. @H_301_5@我不是在寻找涉及添加JavaScript或更多HTML的技术,例如其他DIV元素. @H_301_5@只有在说出哪些技术时,才能在特定浏览器和版本中使用的技术是可以的.
解决方法
<div id="mylist"> <ul> <li>ListItem1</li> <li>ListItem2</li> </ul> </div>@H_301_5@用…来代替 @H_301_5@
<ul id="mylist"> <li>ListItem1</li> <li>ListItem2</li> </ul>@H_301_5@那样你的CSS就可以了 @H_301_5@
div#mylist ul li { }@H_301_5@至 @H_301_5@
ul#mylist li { }@H_301_5@并且HTML会少一些. @H_301_5@编辑:在不必要的情况下:)
22个必须知道的css技巧_html/css_WEB-ITnose
1、改变选中文字的背景和颜色
::selection{ /* Safari and Opera */ background:#c3effd; color:#000;}::-moz-selection{ /* Firefox */ background:#c3effd; color:#000;}
2、防止火狐滚动条跳动
html{ overflow-y:scroll; }
3、分页打印
.page-break{ page-break-before:always; }
4、使用!important
.page { background-color:blue !important; background-color:red;}
5、图像替换文字
.header{ text-indent:-9999px; background:url(''someimage.jpg'') no-repeat; height: 100px; /*dimensions equal to image size*/ width:500px;}
标注:text-indent:-9999px; 是将首行左缩进到人看不到的地方
6、兼容浏览器的最小高度
#container{ height:auto !important;/*all browsers except ie6 will respect the !important flag*/ min-height:500px; height:500px;/*Should have the same value as the min height above*/}
7、对新窗口打开得链接高亮显示
a[target="_blank"]:before,a[target="new"]:before { margin:0 5px 0 0; padding:1px; outline:1px solid #333; color:#333; background:#ff9; font:12px "Zapf Dingbats"; content: "\279C";}
8、美化li序列号
如图:
ol { font: italic 1em Georgia, Times, serif; color: #999999;}ol p { font: normal .8em Arial, Helvetica, sans-serif; color: #000000;}
9、首字下沉
如图:
p:first-letter{display:block;margin:5px 0 0 5px;float:left;color:#FF3366;font-size:3.0em;font-family:Georgia;}
10、兼容浏览器的opacity
.transparent_class { filter:alpha(opacity=50); -moz-opacity:0.5; -khtml-opacity: 0.5; opacity: 0.5; }
11、使用line-height实现垂直居中
line-height:30px;
12、居中布局
body{ width:1000px; margin:0 auto;}
13、移除ie文本域的垂直滚动条
textarea{ overflow:auto;}
14、移动超链接的虚线框
a:active, a:focus{ outline:none; }
15、ie下元素消失,给该元素添加
position:relative;
16、根据链接不一样,添加不一样的icons
a[href$=''.doc''] { padding:0 20px 0 0; background:transparent url(/graphics/icons/doc.gif) no-repeat center right;}
17、css手型点击样式
input[type=submit],label,select,.pointer { cursor:pointer; }
18、字母大写
text-transform: capitalize;
19、所有英文大写,且首字母比其他的大
font-variant:small-caps;
20、高亮文本框,不支持ie
input[type=text]:focus, input[type=password]:focus{ border:2px solid #000;}
21、移除img边框
a img{ border:none; }
22、用label实现无表格表单
HTML Code
<form method="post" action="#" ><p><label for="username" >Username</label><input type="text" id="username" name="username" /></p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/cb6835dc7db1"rel="nofollow" target="_blank">前端免费学习笔记(深入)</a>”;</p><p><span>点击下载</span>“<a href="https://teacher.php.cn/jump/126"rel="nofollow" target="_blank">修复打印机驱动工具</a>”;</p><p><label for="password" >Username</label><input type="password" id="password" name="pass" /></p><p><input type="submit" value="Submit" /></p></form>
CSS Code
p label{ width:100px; float:left; margin-right:10px; text-align:right;}
参考:http://www.cnblogs.com/guoguo-15/archive/2011/08/24/2151859.html
ASP.NET自定义控件 – 什么是最好的方式来包括嵌入式CSS引用一次?
这是我想出来的(到目前为止):
Public Sub IncludeStyles(ByVal Page As System.Web.UI.Page) 'Don't include the reference if it already exists... If Page.Header.FindControl("MyID") Is nothing Then Dim cssUrl As String = Page.ClientScript.GetWebResourceUrl(GetType(Common),StylePath) Dim css As New System.Web.UI.HtmlControls.HtmlGenericControl("link") With css .Attributes.Add("rel","stylesheet") .Attributes.Add("type","text/css") .Attributes.Add("href",cssUrl) .ID = "MyID" End With Page.Header.Controls.Add(css) End If End Sub
好的,它的工作原理…但这里的明显缺陷是使用FindControl()来查看控件是否存在于表单上.虽然我使用命名容器,但仍然似乎正在运行,我相信有一些方法可以打破这个.在表单上添加相同ID的另一个控件肯定是一个…
问题:什么是更好的方法来确保标题控件只添加到HTML标题一次?
注意:ClientScript.RegisterClientScriptResource()方法具有接受.NET类型的参数,并且可以使用此类型来确保每页只输出一次代码.不幸的是,此方法仅适用于JavaScript文件引用.如果CSS引用有内置的等效项,那就是我的偏好.
更新:
我发现通过使用Page.ClientScript.RegisterClientScriptBlock并且告诉它包含你自己的脚本标签来做这个here的稍微优雅的方式,但是如Rick指出的那样,这不会将脚本添加到html头标记中不符合xhtml标准.
更新2:
我在this thread看到另一个有趣的想法,但是循环访问控件集合并不是一个很好的解决方案,如果页面上有几个引用和几个控件,会增加很多开销.
Chris Lively想出了一个更好的解决方案,需要更少的代码.这是我的功能改变与新的解决方案:
Public Sub IncludeStyles(ByVal Page As System.Web.UI.Page) If Not Page.ClientScript.IsClientScriptBlockRegistered(StyleName) Then Dim cssUrl As String = Page.ClientScript.GetWebResourceUrl(GetType(Common),StylePath) Dim css As New System.Web.UI.HtmlControls.HtmlGenericControl("link") With css .Attributes.Add("href",cssUrl) .Attributes.Add("rel","text/css") End With Page.Header.Controls.Add(css) Page.ClientScript.RegisterClientScriptBlock(GetType(Page),StyleName,"") End If End Sub
关于这个解决方案需要注意的几件事情.在他的原始帖子中,Chris使用了IsClientscriptincludeRegistered()方法,而不是RegisterClientScriptBlock()方法的相应方法.要使此功能正确,测试必须使用IsClientScriptBlockRegistered()完成.
另外,请注意传递给RegisterClientScriptBlock()的类型.我将自定义数据类型传递给此方法(在所有控件中都是相同的),但没有以IsClientScriptBlockRegistered()测试的方式进行注册.为了使其工作,当前的Page对象必须作为Type参数传入.
尽管诚然,这种解决方案感觉有点像黑客,但它不需要很多代码或开销,b)在页面上产生所需的输出,c)是符合xhtml的代码.
解决方法
if (!Page.ClientScript.IsClientScriptBlockRegistered("SoPro." + id)) { HtmlLink cssLink = new HtmlLink(); cssLink.Href = cssLink.Href = Page.ClientScript.GetWebResourceUrl(this.GetType(),styleSheet); cssLink.Attributes.Add("rel","stylesheet"); cssLink.Attributes.Add("type","text/css"); this.Page.Header.Controls.Add(cssLink); this.Page.ClientScript.RegisterClientScriptBlock(typeof(System.Web.UI.Page),"SoPro." + id,String.Empty); }
首先,我们测试以查看命名脚本是否以前注册.如果没有,我们添加它.
css – 什么是最好的方法来编码标题/标题为或,像我们有?
这是好吗?
<p>heading</p> <ul> <li>list item</li> <li>list item</li> <li>list item</li> </ul>
还是应该标题总是使用?
<h3|4|5|6>heading</h3|4|5|6> <ul> <li>list item</li> <li>list item</li> <li>list item</li> </ul>
解决方法
如果你不想让它们变粗,用CSS改变他们的风格。例如:
HTML:
<h3https://www.jb51.cc/tag/heading/" target="_blank">heading">heading</h3> <ul> <li>list item </li> <li>list item </li> <li>list item </li> </ul>
CSS
.list-heading { font-weight: normal; }
在HTML5中,您可以使用< section>标签更清晰地关联标题和列表。元件。 (< section>不能正常工作在IE 8和更早没有一些JavaScript虽然。)
<section> <h1>heading</h1> <ul> <li>list item </li> <li>list item </li> <li>list item </li> </ul> </section>
你可以在HTML 4中做类似的事情:
<divhttps://www.jb51.cc/tag/heading/" target="_blank">heading"> <h3>heading</h3> <ul> <li>list item </li> <li>list item </li> <li>list item </li> </ul> </div>
然后风格如此:
.list-with-heading h3 { font-weight: normal; }
css – 什么是最好的方法来设置复选框列表
some label [ ] checkBox 1 [ ] checkBox 2 [ ] checkBox 3 [ ] checkBox 4
[]代表一个复选框
什么标记和CSS最适合使用?
我知道这对桌子来说很容易
我想知道这是否可以使用div
解决方法
<div id="checkBoxes"> <label>some label</label> <ul> <li><input type="checkBox"> checkBox 1</li> <li><input type="checkBox"> checkBox 2</li> <li><input type="checkBox"> checkBox 3</li> <li><input type="checkBox"> checkBox 4</li> </ul> </div>
和这些风格:
#checkBoxes label { float: left; } #checkBoxes ul { margin: 0; list-style: none; float: left; }
桌子不是邪恶的,但是它们常常用于错误的原因。它们使更大的html文件(对于性能和带宽不利),通常具有更加混乱的html结构(对可维护性不利)。然而,对于表格数据,它们是非常好的。
今天关于什么是最好的CSS技巧,以减少您需要多少HTML?的分享就到这里,希望大家有所收获,若想了解更多关于22个必须知道的css技巧_html/css_WEB-ITnose、ASP.NET自定义控件 – 什么是最好的方式来包括嵌入式CSS引用一次?、css – 什么是最好的方法来编码标题/标题为或,像我们有?、css – 什么是最好的方法来设置复选框列表等相关知识,可以在本站进行查询。
本文标签: