我有一个产品div和一个显示它名称的锚标记。它的文字超出了div。如何控制这个文本?
.element {
border: 1px solid #d1d1d1;
margin-top: 5px;
padding: 10px;
overflow: hidden;
min-height: 345px;
min-width: 221.46px !important;
max-width: 230.46px !important;
}
.element img {
margin-top: 20px;
margin-bottom: 20px;
cursor: pointer;
transition: all .3s ease-out;
}
.element:hover {
border: 1px solid #fe9c00;
}
.element button i {
margin-right: 10px;
}
.element button {
display: block;
margin-top: 30px;
margin-bottom: 20px;
background: #fe9c00;
color: #fff;
border: none;
display: block;
padding: 7px 15px;
font-size: 13px;
line-height: 19px;
text-align: center;
text-transform: uppercase;
position: absolute;
width: 88%;
opacity: 0;
margin-left: -11px;
transition: all .3s ease-in-out;
}
.element:hover button {
margin-top: -40px;
opacity: 1;
}
.info-pro {
position: absolute
}
.element:hover img {
margin-top: 0px;
}
.element a {
display: block;
text-decoration: none;
font-size: 13px;
}
.element span {
color: #fe9c00
}

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="col-md-3">
<div class="element">
<img src="../../../../../uploads/store/products/{{ $product->product_image1 }}" width="200" height="200" alt="img1" />
<button><i class="fa fa-shopping-cart"></i>ADD To Card</button>
<div class="info-pro">
<a href="#">Asus DUAL-GTX1070-O8G Graphics Card</a>
<span>Rs 59,849.00</span>
<p>In stock</p>
</div>
</div>
</div>
&#13;
我提供了一个小册子。有谁可以帮我解决这个问题?
答案 0 :(得分:2)
我已删除
.info-pro {
position: absolute
}
.element {
border: 1px solid #d1d1d1;
margin-top: 5px;
padding: 10px;
overflow: hidden;
min-height: 345px;
min-width: 221.46px !important;
max-width: 230.46px !important;
}
.element img {
margin-top: 20px;
margin-bottom: 20px;
cursor: pointer;
transition: all .3s ease-out;
}
.element:hover {
border: 1px solid #fe9c00;
}
.element button i {
margin-right: 10px;
}
.element button {
display: block;
margin-top: 30px;
margin-bottom: 20px;
background: #fe9c00;
color: #fff;
border: none;
display: block;
padding: 7px 15px;
font-size: 13px;
line-height: 19px;
text-align: center;
text-transform: uppercase;
position: absolute;
width: 88%;
opacity: 0;
margin-left: -11px;
transition: all .3s ease-in-out;
}
.element:hover button {
margin-top: -40px;
opacity: 1;
}
.element:hover img {
margin-top: 0px;
}
.element a {
display: block;
text-decoration: none;
font-size: 13px;
}
.element span {
color: #fe9c00
}
&#13;
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="col-md-3">
<div class="element">
<img src="../../../../../uploads/store/products/{{ $product->product_image1 }}" width="200" height="200" alt="img1" />
<button><i class="fa fa-shopping-cart"></i>ADD To Card</button>
<div class="info-pro">
<a href="#">Asus DUAL-GTX1070-O8G Graphics Card</a>
<span>Rs 59,849.00</span>
<p>In stock</p>
</div>
</div>
</div>
&#13;
答案 1 :(得分:2)
由于您使用的是绝对位置,因此您需要将position:relative
添加到父级( .element ),以使其根据它而不是其他父级位置。
.element {
border: 1px solid #d1d1d1;
margin-top: 5px;
padding: 10px;
overflow: hidden;
min-height: 345px;
min-width: 221.46px !important;
max-width: 230.46px !important;
position: relative;
}
.element img {
margin-top: 20px;
margin-bottom: 20px;
cursor: pointer;
transition: all .3s ease-out;
}
.element:hover {
border: 1px solid #fe9c00;
}
.element button i {margin-right: 10px;}
.element button {
display: block;
margin-top: 30px;
margin-bottom: 20px;
background: #fe9c00;
color: #fff;
border: none;
display: block;
padding: 7px 15px;
font-size: 13px;
line-height: 19px;
text-align: center;
text-transform: uppercase;
position: absolute;
width: 88%;
opacity: 0;
margin-left: -11px;
transition: all .3s ease-in-out;
}
.element:hover button {
margin-top: -40px;
opacity: 1;
}
.info-pro {position: absolute}
.element:hover img {margin-top: 0px;}
.element a {display: block;text-decoration: none;font-size: 13px;}
.element span {color: #fe9c00}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="col-md-3">
<div class="element">
<img src="../../../../../uploads/store/products/{{ $product->product_image1 }}" width="200" height="200" alt="img1" />
<button><i class="fa fa-shopping-cart"></i>ADD To Card</button>
<div class="info-pro">
<a href="#">Asus DUAL-GTX1070-O8G Graphics Card</a>
<span>Rs 59,849.00</span>
<p>In stock</p>
</div>
</div>
</div>
答案 2 :(得分:1)
width
更改为inherit
或尝试缩小按钮的宽度。将position:relative;
提交至.element
.element button {
display: block;
margin-top: 30px;
margin-bottom: 20px;
background: #fe9c00;
color: #fff;
border: none;
display: block;
padding: 7px 15px;
font-size: 13px;
line-height: 19px;
text-align: center;
text-transform: uppercase;
position: absolute;
width: inherit;
opacity: 0;
margin-left: -11px;
transition: all .3s ease-in-out;
}
.element {
border: 1px solid #d1d1d1;
margin-top: 5px;
padding: 10px;
overflow: hidden;
min-height: 345px;
min-width: 221.46px !important;
max-width: 230.46px !important;
position: relative;
}
答案 3 :(得分:0)
删除position:absolute
中的.info-pro
。 position:absolute
从文档流中删除元素,这就是为什么它不能“看到”其他元素
.element {
border: 1px solid #d1d1d1;
margin-top: 5px;
padding: 10px;
overflow: hidden;
min-height: 345px;
min-width: 221.46px !important;
max-width: 230.46px !important;
}
.element img {
margin-top: 20px;
margin-bottom: 20px;
cursor: pointer;
transition: all .3s ease-out;
}
.element:hover {
border: 1px solid #fe9c00;
}
.element button i {
margin-right: 10px;
}
.element button {
display: block;
margin-top: 30px;
margin-bottom: 20px;
background: #fe9c00;
color: #fff;
border: none;
display: block;
padding: 7px 15px;
font-size: 13px;
line-height: 19px;
text-align: center;
text-transform: uppercase;
position: absolute;
width: 88%;
opacity: 0;
margin-left: -11px;
transition: all .3s ease-in-out;
}
.element:hover button {
margin-top: -40px;
opacity: 1;
}
.element:hover img {
margin-top: 0px;
}
.element a {
display: block;
text-decoration: none;
font-size: 13px;
}
.element span {
color: #fe9c00
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="col-md-3">
<div class="element">
<img src="../../../../../uploads/store/products/{{ $product->product_image1 }}" width="200" height="200" alt="img1" />
<button><i class="fa fa-shopping-cart"></i>ADD To Card</button>
<div class="info-pro">
<a href="#">Asus DUAL-GTX1070-O8G Graphics Card</a>
<span>Rs 59,849.00</span>
<p>In stock</p>
</div>
</div>
</div>