» » » Воскресные сниппеты №4

Воскресные сниппеты №4

12.08
2
13 249
Воскресные сниппеты №4

Сегодня подборка CSS-снипеетов.
Ничего особенного, но многое полезно и одновременно забывается, так что сделал эту подборку больше для себя.

Подборка полезных css сиппетов


  1. Установка font-size для body (поможет легко использовать em вместо px):
    body {
     	font-size: 62.5%; /* font-size 1em = 10px */
    	}
    	p {
    		font-size: 1.2em; /* 1.2em = 12px */
    		}



  2. Вертикальное выравнивание картинки в блоке (полезно когда картинки разного размера):
    div {
    	width: 100px;
    	height: 100px;
    	line-height: 100px;
    	overflow: hidden;
    	}
    	div img {
    		max-width: 100px;
    		vertical-align: middle;
    		display: block;
    		}
    


  3. Изменение цвета выделения:
    ::-moz-selection { background: #b3d4fc; text-shadow: none; }
    ::selection { background: #b3d4fc; text-shadow: none; }


  4. Предотвращение схлопывания родительского элемента если внутри есть плавающие блоки (clearfix):
    .clearfix:before, 
    .clearfix:after { content: ""; display: table; }
    .clearfix:after { clear: both; }
    .clearfix { *zoom: 1; }


  5. Можно использовать и вот такую конструкцию:
    .clr {clear: both; height: 0; overflow: hidden;}  
    а перед закрывающим тегом родительского блока вставить: 
    <div class="clr"></div>


  6. Запрет выделения текста:
    div {
    	-webkit-user-select: none;
    	-moz-user-select: none;
    	-ms-user-select: none;
    	user-select: none;
    	}



  7. "Подсветка" целевого элемента на странице:
    например имеем код:
    <h3 id="123">текст</h3>

    при переходе по ссылке site.ru/index.html#123 внешний вид нашего заголовка поменяется.
    На основе этого псевдокласса можно сделать даже галерею:

    h3 {
    	font: normal 1.3em/1.8em Arial, Helvetica, sans-serif;
    	color: #ccc;
    }
    
    h3:target {
    	font-size: 1.6em;
    	text-decoration: underline;
    	color: #68c;
    }
    


  8. "Подсветка внешних ссылок"
    a {
    	color: #c06;
    	}
    	a[target*="blank"] {
    		color: #f50;
    		}
    	a[target*="blank"]:after {
    		content: url(icon.png); /*маленькая иконка для большей наглядности*/
    		}


  9. Размытый текст:
    h1 { /*ie9 и старше, как всегда отсасывает... юзаем костыли*/
    	color:transparent;
    	text-shadow:   0 0 10px #ccc;  
    	}&#8203;


  10. Треугольник на css:
    .someclass {
    	width: 0; 
    	height: 0; 
    	border-left:solid 5px transparent;
    	border-right:solid 5px transparent;	
    	border-bottom:solid 5px black;
    	}


    - Тоже самое применимо к спискам:
    ul {
        margin: 0.75em 0;
        padding: 0 1em;
        list-style: none;
    }
    li:before { 
        content: "";
        border-color: transparent #111;
        border-style: solid;
        border-width: 0.35em 0 0.35em 0.45em;
        display: block;
        height: 0;
        width: 0;
        left: -1em;
        top: 0.9em;
        position: relative;
    }



  11. Кроссбраузерный inline-block для блочных элементов:
    li {
    	width: 200px;
    	min-height: 250px;
    	display: -moz-inline-stack;
    	display: inline-block;
    	vertical-align: top;
    	margin: 5px;
    	zoom: 1;
    	*display: inline;
    	}


  12. Замена текста картинкой (новый вариант без text-indent):
    .ir { 
    	border: 0; 
    	font: 0/0 a; 
    	text-shadow: none; 
    	color: transparent; 
    	background-color: transparent; 
    	}


  13. Видимый контур у всех элементов (полезно для отладки):
    * { outline: 2px dotted red }
    * * { outline: 2px dotted green }
    * * * { outline: 2px dotted orange }
    * * * * { outline: 2px dotted blue }
    * * * * * { outline: 1px solid red }
    * * * * * * { outline: 1px solid green }
    * * * * * * * { outline: 1px solid orange }
    * * * * * * * * { outline: 1px solid blue }



  14. Стили для печати страницы (от htbp.com):

    @media print {
      * { background: transparent !important; color: black !important; box-shadow:none !important; text-shadow: none !important; } /* Black prints faster: h5bp.com/s */
      a, a:visited { text-decoration: underline; }
      a[href]:after { content: " (" attr(href) ")"; }
      abbr[title]:after { content: " (" attr(title) ")"; }
      .ir a:after, a[href^="javascript:"]:after, a[href^="#"]:after { content: ""; } /* Don't show links for images, or javascript/internal links */
      pre, blockquote { border: 1px solid #999; page-break-inside: avoid; }
      thead { display: table-header-group; } /* h5bp.com/t */
      tr, img { page-break-inside: avoid; }
      img { max-width: 100% !important; }
      @page { margin: 0.5cm; }
      p, h2, h3 { orphans: 3; widows: 3; }
      h2, h3 { page-break-after: avoid; }
    }
    


  15. Стили для таблиц (от bootstrap):
    /*TABLES*/
    
    table.bordered {
    	max-width: 100%;
    	background-color: transparent;
    	border-collapse: collapse;
    	border-spacing: 0;
    	width: 100%;
    	margin-bottom: 18px;
    }
    
    table.bordered {
    	border: 1px solid #dddddd;
    	border-collapse: separate;
    	*border-collapse: collapsed;
    	border-left: 0;
    	-webkit-border-radius: 4px;
    	-moz-border-radius: 4px;
    	border-radius: 4px;
    }
    
    table.bordered caption + thead tr:first-child th,
    table.bordered caption + tbody tr:first-child th,
    table.bordered caption + tbody tr:first-child td,
    table.bordered colgroup + thead tr:first-child th,
    table.bordered colgroup + tbody tr:first-child th,
    table.bordered colgroup + tbody tr:first-child td,
    table.bordered thead:first-child tr:first-child th,
    table.bordered tbody:first-child tr:first-child th,
    table.bordered tbody:first-child tr:first-child td { border-top: 0; }
    
    table.bordered caption + thead tr:first-child th,
    table.bordered caption + thead tr:first-child td,
    table.bordered colgroup + thead tr:first-child th,
    table.bordered colgroup + thead tr:first-child td,
    table.bordered thead:first-child tr:first-child th,
    table.bordered thead:first-child tr:first-child td { border-top: 0; }
    
    table.bordered tbody + tbody { border-top: 2px solid #dddddd; }
    
    table.bordered tbody tr:hover td,
    table.bordered tbody tr:hover th { background-color: #f5f5f5; }
    
    table.bordered tbody tr:nth-child(odd) td,
    table.bordered tbody tr:nth-child(odd) th { background-color: #f9f9f9; }
    
    table.bordered th { font-weight: bold; }
    
    table.bordered th,
    table.bordered td {
    	padding: 8px;
    	line-height: 18px;
    	text-align: left;
    	vertical-align: top;
    	border-top: 1px solid #dddddd;
    }
    
    table.bordered th,
    table.bordered td { border-left: 1px solid #dddddd; }
    
    table.bordered thead th { vertical-align: bottom; }
    
    table.bordered thead:first-child tr:first-child th:first-child,
    table.bordered tbody:first-child tr:first-child td:first-child {
    	-webkit-border-top-left-radius: 4px;
    	border-top-left-radius: 4px;
    	-moz-border-radius-topleft: 4px;
    }
    
    table.bordered thead:first-child tr:first-child th:last-child,
    table.bordered tbody:first-child tr:first-child td:last-child {
    	-webkit-border-top-right-radius: 4px;
    	border-top-right-radius: 4px;
    	-moz-border-radius-topright: 4px;
    }
    
    table.bordered thead:last-child tr:last-child th:first-child,
    table.bordered tbody:last-child tr:last-child td:first-child {
    	-webkit-border-radius: 0 0 0 4px;
    	-moz-border-radius: 0 0 0 4px;
    	border-radius: 0 0 0 4px;
    	-webkit-border-bottom-left-radius: 4px;
    	border-bottom-left-radius: 4px;
    	-moz-border-radius-bottomleft: 4px;
    }
    
    table.bordered thead:last-child tr:last-child th:last-child,
    table.bordered tbody:last-child tr:last-child td:last-child {
    	-webkit-border-bottom-right-radius: 4px;
    	border-bottom-right-radius: 4px;
    	-moz-border-radius-bottomright: 4px;
    }
    
    table.bordered th,
    table.bordered td { padding: 4px 5px; }
    
    
    table.bordered.character {
    	border: none !important;
    	padding: 0 !important;
    	background: #fff !important;
    	}



На сегодня всё.
P.S. На неделе будет плагин, о котором говорил ранее, пока расписывать всё по полкам вермени не хватает.

Похожие материалы

Комментарии

TCSE
TCSE 13 августа 2012 09:21
прикольно, но явно не хватает картинок с примерами того, как будет выглядеть каждый CSS на сайте. Тот же стиль для таблиц (крайне любопытно). Для себя кстати, использую другой вариант к таблицам
вот картинка http://owely.com/61fX7Ug

сам код такой:

.fancy {    width: 100%;
    margin: 0;
    border: 0;
    border-collapse: collapse;
}

.fancy thead th {
    height: 24px;
    vertical-align: middle;
    border-bottom: 5px solid #ca0000;
    border-top: 6px solid #3c3c3c;
    background: #3c3c3c;
    color: #fff;
    padding:0 2px;
}

.fancy tbody td {
    border: 1px dotted #8c8c8c;
    text-align: left;
    padding: 4px;
    vertical-align: middle;
    line-height: 17px;
}

.fancy tbody td:first-child {
    text-align: left;
}

.fancy tr td:first-child a{text-decoration:none;}

.fancy tr td:first-child a:first-child{font-weight:bold;}

.fancy tbody td:last-child {
    /*line-height: 35px;*/
}
ПафНутиЙ
ПафНутиЙ 13 августа 2012 09:31
http://twitter.github.com/bootstrap/base-css.html#tables - таблицы.
остальные примеры наверное нуждаются не в картинках, а демонстрации. Но к сожалению времени не хватило делать демки. Не могу оторваться от создания нового шаблона для dle-faq.ru

Добавить комментарий

Комментировать могут только зарегистрированные пользователи

Информация

Посетители, находящиеся в группе Гости, не могут оставлять комментарии к данной публикации.