Refactoring: CSS is also object-oriented_html/css_WEB-ITnose
I first came into contact with object-oriented CSS because the CSS in the project has exceeded 8,000 lines and lacks constraints and management. In the near future or in the near future, there are urgent requirements for reconstruction. In the front-end refactoring, we have already discussed the object-oriented refactoring of JavaScript. At this time, let's take a look at CSS object-oriented and modularity, which provides a very good idea for my work.
First of all, what I want to say is that in this era of turbulent concepts, stubborn pursuit of certain concepts and meanings will not lead to better design and higher productivity. Object-oriented is a This idea, or a methodology, brings some inspiration to CSS reconstruction. This is enough. There is no need to worry about the definition and rigor of OO CSS.
What problem did our CSS code encounter?
The reusability is poor. Looking at the name of a CSS, it is difficult to tell which modules may reference it and which parts of the web page this CSS is used for;
As a result, no one dares to modify and Delete, the following styles can only be piled on top;
Afraid of duplicate CSS names, names like s1, s2, t1, and t2 began to appear. This is tantamount to drinking poison to quench thirst. No one knows what these styles do. ;
As a result, CSS is getting bigger and bigger;
The ideas of high-fidelity artists and business developers are completely different. We see various styles of CSS definitions and naming;
Sometimes, you will also encounter the problem of CSS conflict. It all boils down to that sentence: Complexity is the root of all software problems.
Principles of CSS reconstruction:
Vertical modularization: Create CSS module files from large to small, such as: Public-> Portal-> Channel-> Column-> Content ;
Horizontal modularization: suitable for some highly independent components, such as player modules and pop-up layer modules;
Provide guiding CSS: for example, prepare several sets of styles for list type display , all the list displays in the entire system are gathered into this place. The replacement, comparison and modification of future skins will greatly facilitate the artist;
CSS thumb principle: If two of the same functional areas The styles are very similar, only one is kept!
The frame (column) uses the grid to control the width, and the content controls the height. When the page is composed of several columns, the width of each column can be fixed or fixed proportionally by the channel, but the height needs to depend on content.
After the rules of CSS are set, they need to be controlled and managed from the perspectives of open source and cost reduction. On the one hand, newly added CSS must act in accordance with the rules. This needs to be given to high-fidelity designers and business developers. Make requirements; on the other hand, the original CSS needs to be gradually reconstructed.
CSS itself supports inheritance and modularization. In addition, on HTML pages, it is easier to use styles and extended styles, such as: "div class="player wmpPlayer"".
If one day, the front-end of the project becomes so complex that UML modeling is required for HTML, then put CSS in it too. DOM and its affiliated and associated models are very suitable for modeling.
Finally ends with the example from http://oocss.org/:
Css code
- /* **************** TEMPLATE ***************** */
- /* ====== Page Head, Body, and Foot ====== */
- body{/*_text-align:center;*/}/* IE5.5 */
- .body{overflow:hidden; _overflow:visible; _zoom:1;}
- .page{margin: 0 auto; width: 950px;/*_text-align:left;*/} /* wraps other template elems to set width */ /* text-align IE5.5 */
- /* "old school" and "liquid" extend page to allow for different page widths */
- .oldSchool{width:750px;}
- .gs960{width:960px;}
- .liquid{extends:.page; width: auto;margin:0;}
- /* ====== Columns ====== */
- .main{overflow: hidden;_overflow:visible;_zoom:1;}
- .leftCol{float:left; width:250px;_margin-right:-3px;}
- .rightCol{float:right; width: 300px;_margin-left:-3px;}
- /* extend columns to allow for common column widths */
- .gMail{width:160px;}
- .gCal{width:180px;}
- .yahoo{width:240px;}
- .myYahoo{width:300px;}
- /* **************** CONTENT OBJECTS ***************** */
- /* ====== Default spacing ====== */
- h1, h2, h3, h4, h5, h6, ul, ol,dl, p,blockquote {padding:10px;}
- h1, h2, h3, h4, h5, h6,img{padding-bottom:0px;}
- pre{margin: 10px;}
- table h1,table h2,table h3, table h4, table h5, table h6, table p, table ul, table ol, table dl{padding:0;}
- /* ====== Elements ====== */
- img{display:block;}
- em{font-style: italic;}
- strong{font-weight:bold;}
- hr{border: 5px solid #e2e2e2; border-width: 0 0 5px 0; margin: 20px 10px 10px 10px;}
- code{color:#0B8C8F;}
- /* ====== Headings ====== */
- /* .h1-.h6 classes should be used to maintain the semantically appropriate heading levels - NOT for use on non-headings */
- h1, .h1{font-size:196%; font-weight:normal; font-style: normal; color:#AE0345;}
- h2, .h2{font-size:167%; font-weight:normal; font-style: normal; color:#AE0345;}
- h3, .h3{font-size:146.5%; font-weight:normal; font-style: normal; color:#DF2B72;}
- h4, .h4{font-size:123.1%; font-weight:normal; font-style: normal; color: #333;}
- h5, .h5{font-size:108%; font-weight:bold; font-style: normal; color:#AE0345;}
- h6, .h6{font-size:108%; font-weight:normal; font-style: italic; color:#333;}
- /* if additional headings are needed they should be created via additional classes, never via location dependant styling */
- .category{font-size:108%; font-weight:normal; font-style: normal; text-transform:uppercase; color: #333;}
- .category a{color: #333;}
- .important a{font-weight:bold;}
- /* links */
- a { color: #036; font-weight:bold;text-decoration: none }
- a:focus, a:hover { text-decoration: underline }
- a:visited { color:#005a9c; }
- /* ====== Lists ======*/
- /* numbered list */
- ol.simpleList li{list-style-type: decimal; margin-left:40px;}
- /* standard list */
- ul.simpleList li{list-style-type:disc; margin-left:40px;}
- /* ====== Tables ====== */
- .data{padding: 20px; position:relative; zoom:1;vertical-align: top;border-right:solid 1px transparent;/* border fixes a FF2 bug which causes the data table to overlay its borders*/}
- .data table {width:100%;border:1px solid #AE0345;}
- th, td{vertical-align:top;border:1px solid #AE0345;}
- .txtC, .data .txtC td, .data .txtC th{text-align:center;}
- .txtL, .data .txtL td, .data .txtL th{text-align:left;}
- .txtR, .data .txtR td, .data .txtR th{text-align:right;}
- .txtT, .data .txtT td, .data .txtT th{vertical-align:top;}
- .txtB, .data .txtB td, .data .txtB th{vertical-align:bottom;}
- .txtM, .data .txtM td, .data .txtM th{vertical-align:middle;}
- .data th,.data td{padding:3px 20px}
- .data thead tr{#fff0f8;}
- .data th{color: #000; font-weight:bold}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text
