如何在绝对位置上将一个元素调整到另一个元素?
How to adjust one element to another in absolute position?
我想做的事情:
块元素相对于绝对位置的元素调整其高度。
有问题:
如果价格太长,价格离开区块。
条件:
- 块元素必须可点击才能转到 link。
- 价格不得在link内,供参考。
我一直在努力做的事情:
使javascript中的价格元素可点击以转到link并删除绝对位置,未选择此解决方案,因为您不能"CTRL + CLICK"在新的打开选项卡
效果好的案例:
* {
box-sizing: border-box;
}
.block {
background: #3CAEA3;
display: inline-block;
position: relative;
}
.link {
display: inline-block;
padding: 20px 20px 40px 20px;
text-align: center;
text-decoration: none;
}
.title {
font-size: 20px;
}
.subtitle {
font-size: 16px;
}
.price {
height: 20px;
position: absolute;
bottom: 0;
left: 0;
right: 0;
text-align: center;
pointer-events: none;
}
<div class="block">
<a class="link" href="https://google.com">
<div class="title">Coffee table</div>
<div class="subtitle">Made of wood</div>
</a>
<div class="price">
The price is: 100€
</div>
</div>
不行的情况:
* {
box-sizing: border-box;
}
.block {
background: #3CAEA3;
display: inline-block;
position: relative;
}
.link {
display: inline-block;
padding: 20px 20px 40px 20px;
text-align: center;
text-decoration: none;
}
.title {
font-size: 20px;
}
.subtitle {
font-size: 16px;
}
.price {
height: 20px;
position: absolute;
bottom: 0;
left: 0;
right: 0;
text-align: center;
pointer-events: none;
}
<div class="block">
<a class="link" href="https://google.com">
<div class="title">Coffee table</div>
<div class="subtitle">Made of wood</div>
</a>
<div class="price">
The price is tooooo long: 100€
</div>
</div>
你有什么办法解决我的问题吗?
谢谢。
* {
box-sizing: border-box;
}
.block {
background: #3CAEA3;
display: inline-block;
position: relative;
}
.link {
margin-bottom: 50px;
display: inline-block;
padding: 20px 20px 40px 20px;
text-align: center;
text-decoration: none;
}
.title {
font-size: 20px;
}
.subtitle {
font-size: 16px;
}
.price {
height: auto;
position: absolute;
bottom: 0;
left: 0;
right: 0;
text-align: center;
pointer-events: none;
}
<div class="block">
<a class="link" href="https://google.com">
<div class="title">Coffee table</div>
<div class="subtitle">Made of wood</div>
</a>
<div class="price">
The price is toooooooo toooooo tooooo tooooo long: 100€
</div>
</div>
我认为使用 flex 可以解决您的问题。
* {
box-sizing: border-box;
}
.block {
background: #3CAEA3;
display: inline-flex;
justify-content: space-between;
flex-direction: column;
}
.link {
display: inline-block;
padding: 20px;
text-align: center;
text-decoration: none;
}
.title {
font-size: 20px;
}
.subtitle {
font-size: 16px;
}
.price {
padding: 20px;
text-align: center;
/*pointer-events: none;*/
}
<div class="block">
<a class="link" href="https://google.com">
<div class="title">Coffee table</div>
<div class="subtitle">Made of wood</div>
</a>
<a href="https://www.apple.com/" class="link price">
The price is tooooo long: 100€
</a>
</div>
我找到了解决办法!
.block {
background: #3CAEA3;
position: relative;
text-align: center;
max-width: 200px;
margin: 10px;
}
.link,
.fakeLink {
padding: 20px;
}
.link {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
cursor: pointer;
text-decoration: none;
}
.fakeLink{
opacity: 0;
}
.price {
padding: 0 10px 10px 10px;
text-align: center;
pointer-events: none;
}
.title {
font-size: 20px;
}
.subtitle {
font-size: 16px;
}
<div class="block">
<div class="fakeLink">
<div class="title">Coffee table</div>
<div class="subtitle">Made of wood</div>
</div>
<div class="price">
The price is tooooo tooo tooo tooo too long: 100€
</div>
<a class="link" href="https://www.google.com">
<div class="title">Coffee table</div>
<div class="subtitle">Made of wood</div>
</a>
</div>
<div class="block">
<div class="fakeLink">
<div class="title">Coffee table</div>
<div class="subtitle">Made of wood</div>
</div>
<div class="price">
The price is 100€
</div>
<a class="link" href="https://www.google.com">
<div class="title">Coffee table</div>
<div class="subtitle">Made of wood</div>
</a>
</div>
感谢您的帮助。
我想做的事情:
块元素相对于绝对位置的元素调整其高度。
有问题:
如果价格太长,价格离开区块。
条件:
- 块元素必须可点击才能转到 link。
- 价格不得在link内,供参考。
我一直在努力做的事情:
使javascript中的价格元素可点击以转到link并删除绝对位置,未选择此解决方案,因为您不能"CTRL + CLICK"在新的打开选项卡
效果好的案例:
* {
box-sizing: border-box;
}
.block {
background: #3CAEA3;
display: inline-block;
position: relative;
}
.link {
display: inline-block;
padding: 20px 20px 40px 20px;
text-align: center;
text-decoration: none;
}
.title {
font-size: 20px;
}
.subtitle {
font-size: 16px;
}
.price {
height: 20px;
position: absolute;
bottom: 0;
left: 0;
right: 0;
text-align: center;
pointer-events: none;
}
<div class="block">
<a class="link" href="https://google.com">
<div class="title">Coffee table</div>
<div class="subtitle">Made of wood</div>
</a>
<div class="price">
The price is: 100€
</div>
</div>
不行的情况:
* {
box-sizing: border-box;
}
.block {
background: #3CAEA3;
display: inline-block;
position: relative;
}
.link {
display: inline-block;
padding: 20px 20px 40px 20px;
text-align: center;
text-decoration: none;
}
.title {
font-size: 20px;
}
.subtitle {
font-size: 16px;
}
.price {
height: 20px;
position: absolute;
bottom: 0;
left: 0;
right: 0;
text-align: center;
pointer-events: none;
}
<div class="block">
<a class="link" href="https://google.com">
<div class="title">Coffee table</div>
<div class="subtitle">Made of wood</div>
</a>
<div class="price">
The price is tooooo long: 100€
</div>
</div>
你有什么办法解决我的问题吗?
谢谢。
* {
box-sizing: border-box;
}
.block {
background: #3CAEA3;
display: inline-block;
position: relative;
}
.link {
margin-bottom: 50px;
display: inline-block;
padding: 20px 20px 40px 20px;
text-align: center;
text-decoration: none;
}
.title {
font-size: 20px;
}
.subtitle {
font-size: 16px;
}
.price {
height: auto;
position: absolute;
bottom: 0;
left: 0;
right: 0;
text-align: center;
pointer-events: none;
}
<div class="block">
<a class="link" href="https://google.com">
<div class="title">Coffee table</div>
<div class="subtitle">Made of wood</div>
</a>
<div class="price">
The price is toooooooo toooooo tooooo tooooo long: 100€
</div>
</div>
我认为使用 flex 可以解决您的问题。
* {
box-sizing: border-box;
}
.block {
background: #3CAEA3;
display: inline-flex;
justify-content: space-between;
flex-direction: column;
}
.link {
display: inline-block;
padding: 20px;
text-align: center;
text-decoration: none;
}
.title {
font-size: 20px;
}
.subtitle {
font-size: 16px;
}
.price {
padding: 20px;
text-align: center;
/*pointer-events: none;*/
}
<div class="block">
<a class="link" href="https://google.com">
<div class="title">Coffee table</div>
<div class="subtitle">Made of wood</div>
</a>
<a href="https://www.apple.com/" class="link price">
The price is tooooo long: 100€
</a>
</div>
我找到了解决办法!
.block {
background: #3CAEA3;
position: relative;
text-align: center;
max-width: 200px;
margin: 10px;
}
.link,
.fakeLink {
padding: 20px;
}
.link {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
cursor: pointer;
text-decoration: none;
}
.fakeLink{
opacity: 0;
}
.price {
padding: 0 10px 10px 10px;
text-align: center;
pointer-events: none;
}
.title {
font-size: 20px;
}
.subtitle {
font-size: 16px;
}
<div class="block">
<div class="fakeLink">
<div class="title">Coffee table</div>
<div class="subtitle">Made of wood</div>
</div>
<div class="price">
The price is tooooo tooo tooo tooo too long: 100€
</div>
<a class="link" href="https://www.google.com">
<div class="title">Coffee table</div>
<div class="subtitle">Made of wood</div>
</a>
</div>
<div class="block">
<div class="fakeLink">
<div class="title">Coffee table</div>
<div class="subtitle">Made of wood</div>
</div>
<div class="price">
The price is 100€
</div>
<a class="link" href="https://www.google.com">
<div class="title">Coffee table</div>
<div class="subtitle">Made of wood</div>
</a>
</div>
感谢您的帮助。