Мне нужно создать входной слот/кнопку рядом друг с другом.
Они должны реагировать на размер браузера (35 пикселей с обеих сторон). Это для мобильного сайта.
Как это сделать?
Здесь вы идете: вам нужно стилировать ваши кнопки так: не стесняйтесь стилить их больше внутри. рабочий код по адресу: http://jsfiddle.net/73DD2/2/
Поля:
<input type="text"value="email address"><input type="submit" value="submit">
Стиль:
input[type="text"] {
position: absolute;
top: 20px;
width: 70%;
left: 30px;
z-index: 2;
height: 30px;
-webkit-border-top-left-radius: 10px;
-webkit-border-bottom-left-radius: 10px;
-moz-border-radius-topleft: 10px;
-moz-border-radius-bottomleft: 10px;
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
border: 1px solid #CCC;
}
input[type="submit"] {
text-align: right;
position: absolute;
top: 20px;
width: 30%;
right: 30px;
z-index: 1;
-webkit-border-top-right-radius: 10px;
-webkit-border-bottom-right-radius: 10px;
-moz-border-radius-topright: 10px;
-moz-border-radius-bottomright: 10px;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
border: 1px solid #CCC;
height: 34px;
}
Попробуйте этот простой код с помощью JQuery.
var s=$(window).width()-70; // 35+35=70 for margin
document.getElementById("parent").style.width = s+"px";
// for maintaining margin while resizing
$( window ).resize(function() {
var s=$(window).width()-70;
document.getElementById("parent").style.width = s+"px";
});
Когда вы добавляете margin: 36px
он добавляется в Интернет, а также в мобильные сайты!
Вы можете попробовать следующее:
Сначала создайте родительский элемент как:
<div class="parent">
<input type="text" name="field" />
<input type="submit" value="Send" />
</div>
Теперь используйте это:
.parent {
margin: 0 35px;
// you donot need to write the width and height properties for this
}
input[type="text"] {
max-width: 60%; // 60% of the parent element
}
input[type="submit"] {
max-width: 40%; // 40% of the parent element..
}
Маржа будет применяться к родительскому элементу (.parent
), и ввод будет отображаться в .parent
с использованием
input[type="text"], input[type="submit"] {
display: inline;
}
Это простой, но понятный для вас пример! Поскольку вы новичок, вам может потребоваться прочитать некоторые документы с https://developer.mozilla.org/, http://msdn.microsoft.com и многие другие...
вот сценарий для этого: http://jsfiddle.net/afzaal_ahmad_zeeshan/t88Wm/. Извините за стили низкого качества, я забыл добавить border-radius
.
Стили CSS:
parent {
margin: 0 35px;
background-color: #cecece;
text-align: center;
padding: 10px;
}
input[type="text"] {
max-width: 60%; /* 60% of the parent element */
padding: 5px;
background-color: #999;
margin: 0;
border: 1px solid #000;
}
input[type="submit"] {
max-width: 40%; /* 40% of the parent element..*/
background-color: green;
padding: 5px;
margin: 0;
}