决定如何为H1,H2,H3等创建CSS的难题 [英] Dilemma in deciding how to create CSS for H1, H2, H3 etc

查看:41
本文介绍了决定如何为H1,H2,H3等创建CSS的难题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在我的网站上有一些通用的H1,H2,H3样式,这些样式非常适合大多数我需要一个简单的传统"标题的通用"标题.

I currently have some general purpose H1, H2, H3 styles for my site which work great for most 'general' headings where I need a simple 'traditional' header.

 h1 { /* lots of style attributes */ }
 h2 { /* lots of style attributes */ }
 h3 { /* lots of style attributes */ }

我还创建了一些类似这样的组件,也就是说,我需要特定于该特定控件类型的标头.

I am also creating some components where I have something like this, thats to say I need a header specific to that particular type of control.

 <div class="titledimage"><h1>Section header</h1><img .../></div>

 .titledimage h1 { color:red; bottom-border: 1px solid blue; }

我遇到的问题是 titledimage 下的 h1 也是前面定义的 h1 ,因此它继承了所有已定义的样式通过 h1 .这通常是不希望的-我只想 red 1px纯蓝色作为 .titledImage div中的标题.

The problem I'm encountering is that the h1 under titledimage is also an h1 as defined earlier so it inherits all the styles defined by h1. This is generally undesired - I just want red and 1px solid blue for the header in the .titledImage div.

我正在阅读并尝试回答

I was reading and trying to answer this question about H1 styles. My conclusion is that if you are doing specific header styles (.titledimage h1) you cant really do generic header styles (h1) unless :

 a) you reset every style attribute in the '.titledimage h1' style
 b) you just use a class name instead of h1
 c) your `h1` style is defined with very few attributes that you'd 
    be overriding anyway

我注意到,为设置 YUI菜单控件的样式,他们实际上使用了 H6 ,我想知道他们是否正在这样做以避免这种冲突.

I've noticed that for styling the YUI menu control they actually use H6 and I'm wondering if they are doing that to avoid such conflicts.

我应该

a) be using <h6> like yahoo does?
b) reset every attribute defined by `h1` when I define `.titledimage h1` ?
c) just use a class name for `.titledimage header`, and leave 
   `h1`, `h2`, `h3` for 'traditional more logical headers' 
d) something else

理想情况下,我想这样说,但据我所知,没有这样的东西

ideally i want to say this, but theres no such thing (to my knowledge)

 .titledimage h1 { inherit: none; color:red; bottom-border: 1px solid blue; }

推荐答案

对我来说,重置似乎很浪费.必须有一种干净的方法将/*很多样式属性*/应用于要应用于的 h1 标记,而不将其应用于 .titledimage </code>中的h1 </code>.<em class="showen"></em></p> <p class="en">To me resetting seems wasteful. There must be a clean way to apply the <code>/* lots of style attributes */</code> to the <code>h1</code> tags you want it applied to while not having it apply to the <code>h1</code> within a <code>.titledimage</code>.</p> <p class="cn">说你有</p> <pre><code><code><div class="top"><h1>PageName</h1></div> <div class="leftNavigation"><h1>Cat1</h1><h1>Cat2</h1><h1>Cat3</h1></div> <div class="rightMarginNote"><h1>Username</h1></div> <div class="content"> <h1>CONTENT</h1> <div class="titledimage"> <h1>title</h1> </div> </div> </code></code></pre> <p class="cn">然后,您希望CSS有点像:<em class="showen"></em></p> <p class="en">Then you'd want your CSS a little like:</p> <pre><code><code>.top h1, .leftNavigation h1, .rightMarginNote h1, .content > h1 { /* lots of style attributes */ } .similarly h2 { /* lots of style attributes */ } .similarly h3 { /* lots of style attributes */ } .titledimage h1 { color:red; bottom-border: 1px solid blue; } </code></code></pre> <p class="cn">代替替代方案</p> <pre><code><code>h1 { /* lots of style attributes */ } h2 { /* lots of style attributes */ } h3 { /* lots of style attributes */ } .titledimage h1, .otherCase h1, .anotherCase h1, yetAnotherCase h1 { /* lots of style backtracking */ } .titledimage h1 { color:red; bottom-border: 1px solid blue; } .otherCase h1 { color:blue; bottom-border: 1px solid blue; } .anotherCase h1 { color:green; bottom-border: 1px solid blue; } .yetAnotherCase h1 { color:mauve; bottom-border: 1px solid blue; } </code></code></pre> <p class="cn">还要尽可能多地将H1-H5的东西归为一类,如果必须同时使用,请定义一个专门用于重置的类,该类不应用于h1,而是应用于任何类的包含div.<em class="showen"></em></p> <p class="en">Also group as much of that H1-H5 stuff together as possible, and if you must go with the alernative define a class specifically for the resetting that is applied not to the h1 but to the containing div of any class.</p> <pre><code><code><div class="titledimage hReset"><h1>title</h1></div> </code></code></pre> <p>这篇关于决定如何为H1,H2,H3等创建CSS的难题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!</p> </div> <div class="arc-body-main-more"> <span onclick="unlockarc('2224383');">查看全文</span> </div> </div> <div> </div> <div class="wwads-cn wwads-horizontal" data-id="166" style="max-width:100%;border: 4px solid #666;"></div> </div> </article> <div id="arc-ad-2" class="mb-1"> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5038752844014834" crossorigin="anonymous"></script> <ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5038752844014834" data-ad-slot="3921941283"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <div class="widget bgwhite radius-1 mb-1 shadow widget-rel"> <h5>相关文章</h5> <ul> <li> <a target="_blank" title="标题(h1,h2,h3等)规格" href="/1052714.html"> 标题(h1,h2,h3等)规格; </a> </li> <li> <a target="_blank" title="Firefox标题大小h1 h2 h3" href="/575179.html"> Firefox标题大小h1 h2 h3; </a> </li> <li> <a target="_blank" title="添加标头h1,h2,h3(当代)" href="/1972374.html"> 添加标头h1,h2,h3(当代); </a> </li> <li> <a target="_blank" title="如何在JavaScript中获得所有h1,h2,h3等元素?" href="/872463.html"> 如何在JavaScript中获得所有h1,h2,h3等元素?; </a> </li> <li> <a target="_blank" title="标题大小h1 h2 h3在Firefox中" href="/872286.html"> 标题大小h1 h2 h3在Firefox中; </a> </li> <li> <a target="_blank" title="h1,h2,h3 ..元素占用div边距" href="/1596344.html"> h1,h2,h3 ..元素占用div边距; </a> </li> <li> <a target="_blank" title="标题宽度(H1、H2 等)" href="/2801915.html"> 标题宽度(H1、H2 等); </a> </li> <li> <a target="_blank" title="标题宽度(H1,H2等)" href="/570272.html"> 标题宽度(H1,H2等); </a> </li> <li> <a target="_blank" title="如何使用单个 xpath 表达式获得 H1,H2,H3,..." href="/2504340.html"> 如何使用单个 xpath 表达式获得 H1,H2,H3,...; </a> </li> <li> <a target="_blank" title="标题标签的默认CSS样式是什么? (H1,h2,h3,h4,h5)" href="/2022364.html"> 标题标签的默认CSS样式是什么? (H1,h2,h3,h4,h5); </a> </li> <li> <a target="_blank" title="更简单的方法做h1,h2,h3,h4,h5,h6" href="/1045123.html"> 更简单的方法做h1,h2,h3,h4,h5,h6; </a> </li> <li> <a target="_blank" title="HTML如何使H1,H2等作为链接?" href="/2121966.html"> HTML如何使H1,H2等作为链接?; </a> </li> <li> <a target="_blank" title="H1、H2、H3、H4、H5、H6 表内的 TH 标签?- HTML" href="/2729837.html"> H1、H2、H3、H4、H5、H6 表内的 TH 标签?- HTML; </a> </li> <li> <a target="_blank" title="H1,H2,H3,H4标签是块元素还是嵌入式元素?" href="/2121246.html"> H1,H2,H3,H4标签是块元素还是嵌入式元素?; </a> </li> <li> <a target="_blank" title="桌子TH标签内的H1,H2,H3,H4,H5,H6吗? -HTML" href="/1803021.html"> 桌子TH标签内的H1,H2,H3,H4,H5,H6吗? -HTML; </a> </li> <li> <a target="_blank" title="可以&lt; small&gt;标签位于HTML5标题内(即h1,h2,h3等)?" href="/2271021.html"> 可以&lt; small&gt;标签位于HTML5标题内(即h1,h2,h3等)?; </a> </li> <li> <a target="_blank" title="在Sphinx中的新页面中显示每个部分(h1、h2、h3)" href="/2891684.html"> 在Sphinx中的新页面中显示每个部分(h1、h2、h3); </a> </li> <li> <a target="_blank" title="HTML 5标题中是否可以包含另一个标签(即h1,h2,h3等)?" href="/2122160.html"> HTML 5标题中是否可以包含另一个标签(即h1,h2,h3等)?; </a> </li> <li> <a target="_blank" title="为什么H2比H1大?" href="/867990.html"> 为什么H2比H1大?; </a> </li> <li> <a target="_blank" title="删除h1和h2之间的空间" href="/1803023.html"> 删除h1和h2之间的空间; </a> </li> <li> <a target="_blank" title="我可以在编辑器中自定义标题标签(h1,h2,h3 ...)吗?" href="/582508.html"> 我可以在编辑器中自定义标题标签(h1,h2,h3 ...)吗?; </a> </li> <li> <a target="_blank" title="校验和运算(FF = h1 xor h2 ...)" href="/1417761.html"> 校验和运算(FF = h1 xor h2 ...); </a> </li> <li> <a target="_blank" title="解析HTML和获取所有h3之后h2之前的h2使用PHP" href="/652653.html"> 解析HTML和获取所有h3之后h2之前的h2使用PHP; </a> </li> <li> <a target="_blank" title="在CSS中如何更改h1和h2的字体大小" href="/2021644.html"> 在CSS中如何更改h1和h2的字体大小; </a> </li> <li> <a target="_blank" title="在h1之后是否需要使用H2" href="/870755.html"> 在h1之后是否需要使用H2; </a> </li> </ul> </div> <div class="mb-1"> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5038752844014834" crossorigin="anonymous"></script> <ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5038752844014834" data-ad-slot="3921941283"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> <div class="side"> <div class="widget widget-side bgwhite mb-1 shadow"> <h5>前端开发最新文章</h5> <ul> <li> <a target="_blank" title="为什么Chrome(在Electron内部)突然重定向到chrome-error:// chromewebdata?" href="/1996151.html"> 为什么Chrome(在Electron内部)突然重定向到chrome-error:// chromewebdata?; </a> </li> <li> <a target="_blank" title="错误102(net :: ERR_CONNECTION_REFUSED):服务器拒绝连接" href="/749568.html"> 错误102(net :: ERR_CONNECTION_REFUSED):服务器拒绝连接; </a> </li> <li> <a target="_blank" title="如何解决'重定向已被CORS策略阻止:没有'Access-Control-Allow-Origin'标题'?" href="/1009885.html"> 如何解决'重定向已被CORS策略阻止:没有'Access-Control-Allow-Origin'标题'?; </a> </li> <li> <a target="_blank" title="如何处理“Uncaught(in promise)DOMException:play()失败,因为用户没有首先与文档交互。”在桌面上使用Chrome 66?" href="/884909.html"> 如何处理“Uncaught(in promise)DOMException:play()失败,因为用户没有首先与文档交互。”在桌面上使用Chrome 66?; </a> </li> <li> <a target="_blank" title="警告:添加非被动事件侦听器到滚动阻塞'touchstart'事件" href="/818517.html"> 警告:添加非被动事件侦听器到滚动阻塞'touchstart'事件; </a> </li> <li> <a target="_blank" title="如何在浏览器中播放.TS文件(视频/ MP2T媒体类型)?" href="/343346.html"> 如何在浏览器中播放.TS文件(视频/ MP2T媒体类型)?; </a> </li> <li> <a target="_blank" title="此请求已被阻止;内容必须通过HTTPS提供" href="/886417.html"> 此请求已被阻止;内容必须通过HTTPS提供; </a> </li> <li> <a target="_blank" title="资源解释为样式表,但转换为MIME类型text / html(似乎与web服务器无关)" href="/562873.html"> 资源解释为样式表,但转换为MIME类型text / html(似乎与web服务器无关); </a> </li> <li> <a target="_blank" title="通过HTTPS加载页面但请求不安全的XMLHttpRequest端点" href="/885901.html"> 通过HTTPS加载页面但请求不安全的XMLHttpRequest端点; </a> </li> <li> <a target="_blank" title="拒绝从执行脚本'*',因为它的MIME类型(“应用/ JSON')不是可执行文件,并严格MIME类型检查被启用。" href="/47347.html"> 拒绝从执行脚本'*',因为它的MIME类型(“应用/ JSON')不是可执行文件,并严格MIME类型检查被启用。; </a> </li> </ul> </div> <div class="widget widget-side bgwhite mb-1 shadow"> <h5> 热门教程 </h5> <ul> <li> <a target="_blank" title="Java教程" href="/OnLineTutorial/java/index.html"> Java教程 </a> </li> <li> <a target="_blank" title="Apache ANT 教程" href="/OnLineTutorial/ant/index.html"> Apache ANT 教程 </a> </li> <li> <a target="_blank" title="Kali Linux教程" href="/OnLineTutorial/kali_linux/index.html"> Kali Linux教程 </a> </li> <li> <a target="_blank" title="JavaScript教程" href="/OnLineTutorial/javascript/index.html"> JavaScript教程 </a> </li> <li> <a target="_blank" title="JavaFx教程" href="/OnLineTutorial/javafx/index.html"> JavaFx教程 </a> </li> <li> <a target="_blank" title="MFC 教程" href="/OnLineTutorial/mfc/index.html"> MFC 教程 </a> </li> <li> <a target="_blank" title="Apache HTTP客户端教程" href="/OnLineTutorial/apache_httpclient/index.html"> Apache HTTP客户端教程 </a> </li> <li> <a target="_blank" title="Microsoft Visio 教程" href="/OnLineTutorial/microsoft_visio/index.html"> Microsoft Visio 教程 </a> </li> </ul> </div> <div class="widget widget-side bgwhite mb-1 shadow"> <h5> 热门工具 </h5> <ul> <li> <a target="_blank" title="Java 在线工具" href="/Onlinetools/details/4"> Java 在线工具 </a> </li> <li> <a target="_blank" title="C(GCC) 在线工具" href="/Onlinetools/details/6"> C(GCC) 在线工具 </a> </li> <li> <a target="_blank" title="PHP 在线工具" href="/Onlinetools/details/8"> PHP 在线工具 </a> </li> <li> <a target="_blank" title="C# 在线工具" href="/Onlinetools/details/1"> C# 在线工具 </a> </li> <li> <a target="_blank" title="Python 在线工具" href="/Onlinetools/details/5"> Python 在线工具 </a> </li> <li> <a target="_blank" title="MySQL 在线工具" href="/Onlinetools/Dbdetails/33"> MySQL 在线工具 </a> </li> <li> <a target="_blank" title="VB.NET 在线工具" href="/Onlinetools/details/2"> VB.NET 在线工具 </a> </li> <li> <a target="_blank" title="Lua 在线工具" href="/Onlinetools/details/14"> Lua 在线工具 </a> </li> <li> <a target="_blank" title="Oracle 在线工具" href="/Onlinetools/Dbdetails/35"> Oracle 在线工具 </a> </li> <li> <a target="_blank" title="C++(GCC) 在线工具" href="/Onlinetools/details/7"> C++(GCC) 在线工具 </a> </li> <li> <a target="_blank" title="Go 在线工具" href="/Onlinetools/details/20"> Go 在线工具 </a> </li> <li> <a target="_blank" title="Fortran 在线工具" href="/Onlinetools/details/45"> Fortran 在线工具 </a> </li> </ul> </div> </div> </div> <script type="text/javascript">var eskeys = '决定,如,何为,h1,h2,h3,等,创建,css,的,难题'; var cat = 'cc';';//qianduan</script> </div> <div id="pop" onclick="pophide();"> <div id="pop_body" onclick="event.stopPropagation();"> <h6 class="flex flex101"> 登录 <span onclick="pophide();">关闭</span> </h6> <div class="pd-1"> <div class="wxtip center"> <span>扫码关注<em>1秒</em>登录</span> </div> <div class="center"> <img id="qr" src="https://huajiakeji.com/Content/Images/qrydx.jpg" alt="" style="width:150px;height:150px;" /> </div> <div style="margin-top:10px;display:flex;justify-content: center;"> <input type="text" placeholder="输入验证码" id="txtcode" autocomplete="off" /> <input id="btngo" type="button" onclick="chk()" value="GO" /> </div> <div class="center" style="margin: 4px; font-size: .8rem; color: #f60;"> 发送“验证码”获取 <em style="padding: 0 .5rem;">|</em> <span style="color: #01a05c;">15天全站免登陆</span> </div> <div id="chkinfo" class="tip"></div> </div> </div> </div> <script type="text/javascript" src="https://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script> <script type="text/javascript" src="https://cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.min.js"></script> <script type="text/javascript" src="https://img01.yuandaxia.cn/Scripts/highlight.min.js"></script> <script type="text/javascript" src="https://img01.yuandaxia.cn/Scripts/base.js?v=0.22"></script> <script type="text/javascript" src="https://img01.yuandaxia.cn/Scripts/tui.js?v=0.11"></script> <footer class="footer"> <div class="container"> <div class="flink mb-1"> 友情链接: <a href="https://www.it1352.com/" target="_blank">IT屋</a> <a href="https://huajiakeji.com/" target="_blank">Chrome插件</a> <a href="https://www.cnplugins.com/" target="_blank">谷歌浏览器插件</a> </div> <section class="copyright-section"> <a href="https://www.it1352.com" title="IT屋-程序员软件开发技术分享社区">IT屋</a> ©2016-2022 <a href="http://www.beian.miit.gov.cn/" target="_blank">琼ICP备2021000895号-1</a> <a href="/sitemap.html" target="_blank" title="站点地图">站点地图</a> <a href="/Home/Tags" target="_blank" title="站点标签">站点标签</a> <a target="_blank" alt="sitemap" href="/sitemap.xml">SiteMap</a> <a href="/1155981.html" title="IT屋-免责申明"><免责申明></a> 本站内容来源互联网,如果侵犯您的权益请联系我们删除. </section> <!--统计代码--> <script type="text/javascript"> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?0c3a090f7b3c4ad458ac1296cb5cc779"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> <script type="text/javascript"> (function () { var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </div> </footer> </body> </html>