gpt4 book ai didi

html - float 或 'display: inline' 带有 css 背景图像的输入标签

转载 作者:太空宇宙 更新时间:2023-11-04 07:41:04 25 4
gpt4 key购买 nike

我有一个包含数量输入和添加到购物车按钮的购物车表单的修复 HTML 结构:

enter image description here

但我想要数量输入字段旁边的添加到购物车按钮,如下所示:

enter image description here

当我尝试将字段的显示设置为内联/内联 block 或 float 它们时,背景图像表现得很奇怪,如您在此图像或代码片段 (or alternatively in this fiddle) 中所见:

enter image description here

table {
border-collapse: collapse;
}

th {
border-bottom: 3px solid #ccc;
padding-right: 1em;
text-align: left;
}

tbody {
border-top: 1px solid #ccc;
}

tr.even,
tr.odd {
background-color: #eee;
border-bottom: 1px solid #ccc;
padding: 0.1em 0.6em;
}

label {
display: block;
}

form.commerce-add-to-cart input {
padding-left: 28px;
}

form.commerce-add-to-cart input.form-submit+label::before {
background-image: url('http://files.softicons.com/download/business-icons/free-e-commerce-icons-by-design-bolts/png/96x96/Shopping-Basket-Icon.png');
position: absolute;
background-size: 18px 18px;
display: inline-block;
width: 18px;
height: 18px;
vertical-align: text-bottom;
content: "";
background-repeat: no-repeat;
padding-right: 0.25em;
margin: -21px 0 0 6px;
}

body.page-all-books .form-item-quantity label {
display: none;
}

input[type="submit"] {
-webkit-appearance: none;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
-moz-background-clip: padding;
-webkit-background-clip: padding;
background-clip: padding-box;
border-radius: 2px;
background-color: #d3cfe8;
border: 1px solid #d3cfe8;
cursor: pointer;
color: #333;
font: normal 12px/1.2 "OpenSans", sans-serif;
outline: 0;
overflow: visible;
padding: 3px 6px 4px;
text-shadow: none;
width: auto;
}

table {
border: 0 solid #CCC;
width: 100%;
}

thead th,
th {
background-color: #eeeeee;
}

tr.even td,
tr.odd td {
background-color: #ffffff;
}

tr:hover td {
background: #f7f7f7;
}

div.form-item-quantity {
display: inline-block;
}
<body class="page-all-books">
<div class="view-content">
<table>
<thead>
<tr>
<th>
Published</th>
<th>
Price</th>
<th>
</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>
2016
</td>
<td>
12,00&nbsp; EUR
</td>
<td>
<form class="commerce-add-to-cart" id="form-1">
<div>
<input name="product_id" value="45" type="hidden">
<label for="input"></label>
<input name="form_build_id" value="form-1" type="hidden">
<label for="input"></label>
<input name="form_id" value="form_1" type="hidden">
<label for="input"></label>
<div id="edit-line-item-fields" class="form-wrapper"></div>
<div class="form-item-quantity">
<label for="edit-quantity">Quantity </label>
<input id="edit-quantity" name="quantity" value="1" size="5" type="text">
<label for="input"></label>
</div>
<input id="edit-submit" name="op" value="Add to cart" class="form-submit" type="submit">
<label for="input"></label>
</div>
</form>
</td>
</tr>

<tr class="even">
<td>
2010
</td>
<td>
19,90&nbsp; EUR
</td>
<td>
<form class="commerce-add-to-cart" id="form-2">
<div>
<input name="product_id" value="45" type="hidden">
<label for="input"></label>
<input name="form_build_id" value="form-2" type="hidden">
<label for="input"></label>
<input name="form_id" value="form_2" type="hidden">
<label for="input"></label>
<div id="edit-line-item-fields" class="form-wrapper"></div>
<div class="form-item-quantity">
<label for="edit-quantity">Quantity </label>
<input id="edit-quantity" name="quantity" value="1" size="5" type="text">
<label for="input"></label>
</div>
<input id="edit-submit" name="op" value="Add to cart" class="form-submit" type="submit">
<label for="input"></label>
</div>
</form>
</td>
</tr>

<tr class="odd">
<td>
2018
</td>
<td>
42,00&nbsp; EUR
</td>
<td>
<form class="commerce-add-to-cart" id="form-3">
<div>
<input name="product_id" value="45" type="hidden">
<label for="input"></label>
<input name="form_build_id" value="form-3" type="hidden">
<label for="input"></label>
<input name="form_id" value="form_3" type="hidden">
<label for="input"></label>
<div id="edit-line-item-fields" class="form-wrapper"></div>
<div class="form-item-quantity">
<label for="edit-quantity">Quantity </label>
<input id="edit-quantity" name="quantity" value="1" size="5" type="text">
<label for="input"></label>
</div>
<input id="edit-submit" name="op" value="Add to cart" class="form-submit" type="submit">
<label for="input"></label>
</div>
</form>
</td>
</tr>

</tbody>
</table>
</div>
</body>

最佳答案

position: relative添加到标签中,并使用top和负left(而不是负 margin )。由于 labelblock 级元素,将其设置为 inline 以使其在输入后对齐。

fiddle

table {
border-collapse: collapse;
}

th {
border-bottom: 3px solid #ccc;
padding-right: 1em;
text-align: left;
}

tbody {
border-top: 1px solid #ccc;
}

tr.even,
tr.odd {
background-color: #eee;
border-bottom: 1px solid #ccc;
padding: 0.1em 0.6em;
}

label {
display: inline;
}

form.commerce-add-to-cart input {
padding-left: 28px;
}

label {
position: relative;
}

form.commerce-add-to-cart input.form-submit+label::before {
background-image: url('http://files.softicons.com/download/business-icons/free-e-commerce-icons-by-design-bolts/png/96x96/Shopping-Basket-Icon.png');
position: absolute;
background-size: 18px 18px;
display: inline-block;
width: 18px;
height: 18px;
vertical-align: text-bottom;
content: "";
background-repeat: no-repeat;
padding-right: 0.25em;
top: 0;
left: -90px;
}

body.page-all-books .form-item-quantity label {
display: none;
}

input[type="submit"] {
-webkit-appearance: none;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
-moz-background-clip: padding;
-webkit-background-clip: padding;
background-clip: padding-box;
border-radius: 2px;
background-color: #d3cfe8;
border: 1px solid #d3cfe8;
cursor: pointer;
color: #333;
font: normal 12px/1.2 "OpenSans", sans-serif;
outline: 0;
overflow: visible;
padding: 3px 6px 4px;
text-shadow: none;
width: auto;
}

table {
border: 0 solid #CCC;
width: 100%;
}

thead th,
th {
background-color: #eeeeee;
}

tr.even td,
tr.odd td {
background-color: #ffffff;
}

tr:hover td {
background: #f7f7f7;
}

div.form-item-quantity {
display: inline-block;
}
<body class="page-all-books">
<div class="view-content">
<table>
<thead>
<tr>
<th>
Published</th>
<th>
Price</th>
<th>
</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>
2016
</td>
<td>
12,00&nbsp; EUR
</td>
<td>
<form class="commerce-add-to-cart" id="form-1">
<div>
<input name="product_id" value="45" type="hidden">
<label for="input"></label>
<input name="form_build_id" value="form-1" type="hidden">
<label for="input"></label>
<input name="form_id" value="form_1" type="hidden">
<label for="input"></label>
<div id="edit-line-item-fields" class="form-wrapper"></div>
<div class="form-item-quantity">
<label for="edit-quantity">Quantity </label>
<input id="edit-quantity" name="quantity" value="1" size="5" type="text">
<label for="input"></label>
</div>
<input id="edit-submit" name="op" value="Add to cart" class="form-submit" type="submit">
<label for="input"></label>
</div>
</form>
</td>
</tr>

<tr class="even">
<td>
2010
</td>
<td>
19,90&nbsp; EUR
</td>
<td>
<form class="commerce-add-to-cart" id="form-2">
<div>
<input name="product_id" value="45" type="hidden">
<label for="input"></label>
<input name="form_build_id" value="form-2" type="hidden">
<label for="input"></label>
<input name="form_id" value="form_2" type="hidden">
<label for="input"></label>
<div id="edit-line-item-fields" class="form-wrapper"></div>
<div class="form-item-quantity">
<label for="edit-quantity">Quantity </label>
<input id="edit-quantity" name="quantity" value="1" size="5" type="text">
<label for="input"></label>
</div>
<input id="edit-submit" name="op" value="Add to cart" class="form-submit" type="submit">
<label for="input"></label>
</div>
</form>
</td>
</tr>

<tr class="odd">
<td>
2018
</td>
<td>
42,00&nbsp; EUR
</td>
<td>
<form class="commerce-add-to-cart" id="form-3">
<div>
<input name="product_id" value="45" type="hidden">
<label for="input"></label>
<input name="form_build_id" value="form-3" type="hidden">
<label for="input"></label>
<input name="form_id" value="form_3" type="hidden">
<label for="input"></label>
<div id="edit-line-item-fields" class="form-wrapper"></div>
<div class="form-item-quantity">
<label for="edit-quantity">Quantity </label>
<input id="edit-quantity" name="quantity" value="1" size="5" type="text">
<label for="input"></label>
</div>
<input id="edit-submit" name="op" value="Add to cart" class="form-submit" type="submit">
<label for="input"></label>
</div>
</form>
</td>
</tr>

</tbody>
</table>
</div>
</body>

关于html - float 或 'display: inline' 带有 css 背景图像的输入标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48510419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com