What is the smartest CSS technology that allows you to use less HTML?
One of the benefits of using CSS well is that it allows you to simplify your HTML code and produce CSS-style effects completely. At first, it simply replaced the obsolete HTML presentation and spacer-GIF labels with CSS, but better ideas have come up in recent years.
I am looking for something less obvious than the following.
HR
border
IMG
background-image
:before
content
I'm not looking for methods that include adding JavaScript or more HTML, such as additional div elements.
Methods that work only in certain browsers and versions are fine if you say which ones.
Specificity may not be omitted by nesting elements in a div, but instead simply gives the elements unique identifiers themselves.
<div id="mylist"> <ul> <li>ListItem1</li> <li>ListItem2</li> </ul> </div>
Replace
<ul id="mylist"> <li>ListItem1</li> <li>ListItem2</li> </ul>
So your CSS will go from
div#mylist ul li { }
to
ul#mylist li { }
And there will be less HTML.
EDIT : under unnecessary circumstances :)
Using smart CSS selectors instead of extra classes or identifiers.
Example (navigation lists seem to be popular):
<ul class="nav"> <li class="section">Section 1<ul class="subnav"> <li class="subsection">Section 1.1</li> <li class="subsection">Section 1.2</li> ⋮ </ul></li> <li class="section">Section 2<ul class="subnav"> <li class="subsection">Section 2.1</li> <li class="subsection">Section 2.2</li> ⋮ </ul></li> ⋮ </ul>
better:
<ul id="nav"> <li>Section 1<ul> <li>Section 1.1</li> <li>Section 1.2</li> ⋮ </ul></li> <li>Section 2<ul> <li>Section 2.1</li> <li>Section 2.2</li> ⋮ </ul></li> ⋮ </ul> #nav { /* first level list */ } #nav li { /* first level items */ } #nav li ul { /* second level list */ } #nav li ul li { /* second level items */ } ⋮
, , , , - CSS .
, , , , . , CSS .
, OO CSS - .
, , divs :
<table> <tbody> <tr> <td>Column 1</td> <td>Column 2</td> <td>Column 3</td> </tr> </tbody> </table>
:
<div>Column 1</div> <div>Column 2</div> <div>Column 3</div>
CSS
div { float:left; width:33%; }
, HTML.
, 3 . ID, #mainColumn, #leftColumn, #rightColumn - #cointainer. .
, 3 , , : , , . :
.love div, #container, , Love (pink), Hate (Black and Red), Stoned ( !)...
, .love,.hate .stoned , , #rightCol, #leftCol #mainCol.
, , , .
CSS HTML, . , HTML. , -.
HTML , . , . , , <div> <span>.
<div>
<span>
, , - background <img>
background
<img>
Source: https://habr.com/ru/post/1702689/More articles:Where is ODBC File DSN in Windows Vista - windowsCSS background url() не отображается в IE, работает в FF/Safari - cross-browsersearch for constructor calling object in C ++ - c ++Скопируйте файл из одного каталога в другой по дате - sqlКак проинструктировать веб-браузеры НЕ кэшировать страницы? - httpHow to get the application pool name for a specific IIS6 website programmatically? C # - c #Memory Leak in TDictionary - Problems with a Workaround? - memory-leaksWhat is the most efficient way to deserialize an XML file - performanceDifferentiation between "AB" and "Ab" in a character base field - sqlDoes PHP provide the fopen function to implement some kind of cache? - httpAll Articles