Ответ 1
В вашем CSS .button
попробуйте display:inline-block
. Смотрите JSFiddle
Я пытаюсь стилизовать кнопку, используя <input type="button">
вместо <button>
. С кодом, который у меня есть, кнопка проходит полностью по экрану. Я просто хочу уметь подгонять его к тексту, который он находится в кнопке. Любые идеи?
Смотрите пример jsFiddle или перейдите к HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>WTF</title>
</head>
<style type="text/css">
.button {
color:#08233e;
font:2.4em Futura, ‘Century Gothic’, AppleGothic, sans-serif;
font-size:70%;
padding:14px;
background:url(overlay.png) repeat-x center #ffcc00;
background-color:rgba(255,204,0,1);
border:1px solid #ffcc00;
-moz-border-radius:10px;
-webkit-border-radius:10px;
border-radius:10px;
border-bottom:1px solid #9f9f9f;
-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);
-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);
box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);
cursor:pointer;
}
.button:hover {
background-color:rgba(255,204,0,0.8);
}
</style>
<body>
<div class="button">
<input type="button" value="TELL ME MORE" onClick="document.location.reload(true)">
</div>
</body>
В вашем CSS .button
попробуйте display:inline-block
. Смотрите JSFiddle
Вы действительно хотите стилизовать <div>
? Или вы хотите стиль <input type="button">
? Вы должны использовать правильный селектор, если хотите его:
input[type=button] {
color:#08233e;
font:2.4em Futura, ‘Century Gothic’, AppleGothic, sans-serif;
font-size:70%;
/* ... other rules ... */
cursor:pointer;
}
input[type=button]:hover {
background-color:rgba(255,204,0,0.8);
}
См. также:
Вы хотите что-то вроде данной скрипка!
HTML
<div class="button">
<input type="button" value="TELL ME MORE" onClick="document.location.reload(true)">
</div>
CSS
.button input[type="button"] {
color:#08233e;
font:2.4em Futura, ‘Century Gothic’, AppleGothic, sans-serif;
font-size:70%;
padding:14px;
background:url(overlay.png) repeat-x center #ffcc00;
background-color:rgba(255,204,0,1);
border:1px solid #ffcc00;
-moz-border-radius:10px;
-webkit-border-radius:10px;
border-radius:10px;
border-bottom:1px solid #9f9f9f;
-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);
-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);
box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);
cursor:pointer;
display:block;
width:100%;
}
.button input[type="button"]:hover {
background-color:rgba(255,204,0,0.8);
}
Float:left
... Хотя я предполагаю, что вы хотите, чтобы входные данные были не в стиле div?
.button input{
color:#08233e;float:left;
font:2.4em Futura, ‘Century Gothic’, AppleGothic, sans-serif;
font-size:70%;
padding:14px;
background:url(overlay.png) repeat-x center #ffcc00;
background-color:rgba(255,204,0,1);
border:1px solid #ffcc00;
-moz-border-radius:10px;
-webkit-border-radius:10px;
border-radius:10px;
border-bottom:1px solid #9f9f9f;
-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);
-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);
box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);
cursor:pointer;
}
.button input:hover{
background-color:rgba(255,204,0,0.8);
}
Проблема не с кнопкой, проблема связана с div
. Поскольку div
являются блочными элементами, они по умолчанию занимают всю ширину своего родительского элемента (как правило, я уверен, что есть некоторые исключения, если вы возитесь с различными схемами позиционирования в одном документе, которые он должен занимать всю ширину более высокого элемента в иерархии).
В любом случае попробуйте добавить float: left;
в правила для селектора .button
. Это приведет к тому, что div
с классом button
будет располагаться вокруг кнопки и позволит вам иметь несколько плавающих div
в одной строке, если вам нужно больше div.button
s.
Попробуйте поставить
Display:inline;
В CSS.