English 中文(简体)
CSS 某些要素的超负荷选择
原标题:Override CSS selector for some elements
  • 时间:2012-04-23 10:27:52
  •  标签:
  • html
  • css

我有一页,我想作风格(使用IE9)。

The following Code:

<style type="text/css">
    #komponenter select,
    #komponenter input
    {
         width: 180px;
         box-sizing:content-box; 
    }

    .special_box { width: 50px; height: 150px; }
</style>

... snipp ...

<div id="col2" class="kolumn">

    @Html.LabelFor(model => Model.Verksamhetskod)
    <br />
    @Html.TextBoxFor(model => Model.Verksamhetskod)
    <br />

    @Html.Label("Lat/Long")
    @Html.TextBoxFor(m => m.LatitudTecken)
    @Html.TextBoxFor(m => m.Latitud)
    @Html.TextBoxFor(m => m.LongitudTecken)
    @Html.TextBoxFor(m => m.Longitud)
    <br />

    @Html.Label("3 Överväganden:")
    <br />
    @Html.TextBoxFor(m => m.Overvagande)
    <br />

    @Html.Label("1 Ingångsvärden:")
    <br />
    @Html.TextBoxFor(m => m.Ingangsvarde, new { @class = "special_box" })
    <br />
</div>

html做了罚款,问题在于,上面的剪辑(高点工作罚款)使“特殊”箱宽大。 我先尝试将这门课程放在风格上,但确实会有所改变。

最佳回答

it s a matter of specificity: try this instead (assuming .special_box is an input element)

#komponenter select,
#komponenter input
{
     width: 180px;
     box-sizing:content-box; 
}

#komponenter input.special_box {
     width: 50px; height: 150px; 
}

a rule like #komponenter input has a specificity of 101 (1 id, 0 classes, 1 element)
while .special_box has a specificity of 10 (1 class, 0 elements)

http://coding.smapingmagazine.com/2007/07/27/css-specificity-things-you-should-know/” rel=“nofollow” http://coding.smapingmagazine.com/2007/07/27/css-specificity-things-you-should-know/ 更多信息

问题回答

the css above have a higher specificity (1-0-1) than your .specialbox (0-1-0). to raise it, you have to "be more specific":

/*here we add a few more selectors to .special_box to be more specific*/
#komponenter input.special_box (1-1-1)
//   1-0-0 for #komponenter
//   0-0-1 for input
// + 0-1-0 for .special_box
// = 1-1-1

或仅仅凌驾于你希望以<条码>生效的风格!

#komponenter input.special_box{
    width: 50px !important;   /*override width*/
    height: 150px;
}




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签