I need to create a CSS naming convention in an MVC project with layouts.
Using layouts creates a need very carefully when it comes to choosing a class name, because it can be overridden by one declared in the CSS layout file.
One rule I use is to have only element classes for the style and element id for using jQuery.
Say I have a layout like this:
<div class="lyb-ctn">
<div class="lyb-wrp">
@RenderBody()
<div class="lyb-ctn-rgt">
<div class="lyb-ctn-subscribe">
<p class="lyb-ctn-subscribe-title">Subscribe</p>
<input placeholder="Email" /><input type="button" />
</div>
<div class="lyb-ctn-categories">
<p class="lyb-ctn-categories-title">Categories</p>
<div class="lyb-ctn-categories-ctn-list">
<div class="category">
<p>Cars</p>
<p>Boats</p>
</div>
</div>
</div>
</div>
</div>
</div>
One of the options:
.lyb-ctn {
position:fixed;
padding:0px;
margin:0px;
width:100%;
height:100%;
background-color: #f2f2f2;
padding-top: 50px;
}
.lyb-wrp {
max-width: 960px;
width: 95%;
margin: auto;
background-color: #ffd800;
}
.lyb-ctn-rgt {
float: right;
width: 235px;
border: solid 1px #ff6a00;
}
.lyb-ctn-subscribe {
width: 100%;
}
.lyb-ctn-subscribe-title {
color: #80bd01;
}
.lyb-ctn-categories {
width: 100%;
}
.lyb-ctn-categories-title {
color: #80bd01;
}
I am also creating another option, but this one, I think, is dangerous, because if ".rgt-ctn" exists in the parent layout, it can override this:
.lyb-ctn {
position:fixed;
padding:0px;
margin:0px;
width:100%;
height:100%;
background-color: #f2f2f2;
padding-top: 50px;
}
.lyb-ctn .wrp {
max-width: 960px;
width: 95%;
margin: auto;
background-color: #ffd800;
}
.lyb-ctn .wrp .rgt-ctn {
float: right;
width: 235px;
border: solid 1px #ff6a00;
}
.lyb-ctn .wrp .rgt-ctn .subscribe-ctn {
width: 100%;
}
.lyb-ctn .wrp .rgt-ctn .subscribe-ctn .title {
color: #80bd01;
}
Here is another one that seems clean, but we cannot see the hierarquy from the DOM when we look at it, and I think it might be harder to find an element to edit:
.lyb-ctn {
position:fixed;
padding:0px;
margin:0px;
width:100%;
height:100%;
background-color: #f2f2f2;
padding-top: 50px;
}
.lyb-wrp {
max-width: 960px;
width: 95%;
margin: auto;
background-color: #ffd800;
}
.ctn-side-options {
float: right;
width: 235px;
}
.ctn-subscribe,
.ctn-categories,
.ctn-tags {
width: 100%;
}
.ctn-subscribe .title,
.ctn-categories .title,
.ctn-tags .title {
color: #80bd01;
padding: 25px 0 10px 5px;
}
.ctn-categories .ctn-list,
.ctn-tags .ctn-list {
width: 100%;
background-color: #fff;
border: solid 1px #e6e6e6;
border-radius: 3px;
margin: 0;
padding: 0;
}
?