我有很多div元素,在最后一个div元素中,我使用position: fixed;
来在滚动时不改变元素的位置。
所以问题是一些顶级div元素被底部div元素重叠,因为它有这样的css。
#div1 {
position: fixed;
background: blue;
font-size: 50px;
bottom: 0;
}
Fiddle附加链接
答案 0 :(得分:1)
在父元素上添加一些padding
,在本例中为<body>
:
body {
padding-bottom: 65px;
}
#div1 {
position: fixed;
background: blue;
font-size: 50px;
bottom: 0;
}
<div>a</div>
<div>a</div>
<div>a</div>
<div>a</div>
<div>a</div>
<div>a</div>
<div>a</div>
<div>a</div>
<div>a</div>
<div>a</div>
<div>a</div>
<div>a</div>
<div>a</div>
<div>a</div>
<div>a</div>
<div>a</div>
<div>a</div>
<div>a</div>
<div>a</div>
<div>a</div>
<div>a</div>
<div>a</div>
<div>a</div>
<div>a</div>
<div>a</div>
<div>a</div>
<div>a</div>
<div>a19</div>
<div>a20</div>
<div>a21</div>
<div>a22</div>
<div>a23</div>
<div>lastdiv</div>
<div id="div1">
Example
</div>
答案 1 :(得分:0)
您可以尝试向其中添加from decimal import Decimal
from django.conf import settings
from shop.models import Product
class Cart(object):
def __init__(self, request):
"""
Initialize the cart.
"""
self.session = request.session
cart = self.session.get(settings.CART_SESSION_ID)
if not cart:
# save an empty cart in the session
cart = self.session[settings.CART_SESSION_ID] = {}
self.cart = cart
def add(self, product, quantity=1, update_quantity=False):
"""
Add a product to the cart or update its quantity
"""
product_id = str(product.id)
if product_id not in self.cart:
self.cart[product_id] = {'quantity': 0,
'price': str(product.price)}
if update_quantity:
self.cart[product_id]['quantity'] = quantity
else:
self.cart[product_id]['quantity'] += quantity
self.save()
def save(self):
# update the session cart
self.session[settings.CART_SESSION_ID] = self.cart
# mark the session as "modified" to make sure it is saved
self.session.modified = True
def remove(self, product):
"""
Remove a product from the cart.
"""
product_id = str(product.id)
if product_id in self.cart:
del self.cart[prodcut_id]
self.save()
def __iter__(self):
"""
Iterate over the items in the cart and get the products
from the database
"""
product_ids = self.cart.keys()
# get the product objects and add them to the cart
products = Product.objects.filter(id__in=product_ids)
for product in products:
self.cart[str(product.id)]['product'] = product
for item in self.cart.values():
item['price'] = Decimal(item['price'])
item['total_price'] = item['price'] * item['quantity']
yield item
def __len__(self):
"""
Count all items in the cart.
"""
return sum(item['quantity'] for item in self.cart.values())
def get_total_price(self):
return sum(Decimal(item['price']) * item['quantity'] for item in self.cart.values())
def clear(self):
# remove cart from session
del self.session[settings.CART_SESSION_ID]
self.session.modified = True
。试试这段代码。
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
答案 2 :(得分:0)
首先:访问到最后一个div,不需要ID
替换此代码:
div:last-child {
position: fixed;
background: blue;
font-size: 50px;
bottom: 0;
}
div:nth-last-child(2) {
height:75px;
}