30 марта 2008 ~ 2297 Комментариев

Делаем красивые кнопки

fdgfd

Эта инструкция научит Вас, как создавать очень красивые и удобные текстовые кнопки (с эффектом нажатия), используя CSS.

Техника раздвижных дверей

Что бы сделать наши кнопки практичными, мы должны учесть возможность растяжки кнопок. Для этого вы воспользуемся техникой «раздвижных дверей»(slidingdoors).

Наша кнопка будет состоять из основного тега <a> с вложенным в него тегом <span>, каждый из которых содержит одну из частей фонового рисунка.

Вот то, что HTML выглядит следующим образом:

<a class="button" href="#"><span>Bring world peace</span></a>

Очень просто, не так ли?

Теперь, нам надо разобраться с оформлением нашей кнопки в нормальном состоянии и в состоянии нажатия.

Вот что я думаю:

button-design

Мы будем использовать для обоих состояний одно изображение, просто изменяя его background-position.

Вот так выглядит наша заготовка с учетом всех факторов:

bg_button_span bg_button_a

Оформляем кнопку

Оформляем с помощью следующего css кода:

.clear { /* generic container (i.e. div) for floating buttons */
    overflow: hidden;
    width: 100%;
}

a.button {
    background: transparent url('bg_button_a.gif') no-repeat scroll top right;
    color: #444;
    display: block;
    float: left;
    font: normal 12px arial, sans-serif;
    height: 24px;
    margin-right: 6px;
    padding-right: 18px; /* sliding doors padding */
    text-decoration: none;
}

a.button span {
    background: transparent url('bg_button_span.gif') no-repeat;
    display: block;
    line-height: 14px;
    padding: 5px 0 5px 18px;
}

a.button:active {
    background-position: bottom right;
    color: #000;
    outline: none; /* hide dotted outline in Firefox */
}

a.button:active span {
    background-position: bottom left;
    padding: 6px 0 4px 18px; /* push text down 1px */
}

Специально для IE

В Internet Explorer нажатие кнопки не будет работать, так что сделаем маленькую хитрость на javascript:

<a class="button" href="#" onclick="this.blur();"><span> … </span></a>

Готово ^_^

Посмотреть пример

Скачать пример

По мотивам: http://www.oscaralexander.com/tutorials/how-to-make-sexy-buttons-with-css.html

2297 Комментариев для “Делаем красивые кнопки”

  1. the numerology of names 17 мая 2012 at 22:55 Permalink

    I wish to express my thanks to you for rescuing me from this type of dilemma. Just after researching throughout the search engines and finding basics which were not helpful, I assumed my entire life was over. Existing minus the approaches to the problems you’ve resolved all through the short article is a crucial case, and the ones that would have badly affected my career if I had not come across the website. Your own personal knowledge and kindness in taking care of all the stuff was vital. I’m not sure what I would have done if I had not discovered such a stuff like this. I’m able to at this point relish my future. Thanks for your time so much for your skilled and results-oriented help. I will not think twice to refer your blog to any person who ought to have direction about this topic.


Оставить комментарий