简体   繁体   English

如何创建占用100%宽度的内联块元素。 第二个元素还有一个悬停显示的元素

[英]How do I create inline block elements that take up 100% width. The second element has another element that shows on hover

I have an unordered list of images with a text overlay at the bottom of each image. 我有一个无序的图像列表,每个图像的底部都有一个文本覆盖。 The text overlay are inline blocks with different background color. 文本叠加层是具有不同背景颜色的嵌入式块。

First I get a whitespace in between the background colors which I do not need. 首先,我在不需要的背景颜色之间得到一个空格。 ✔️ ✔️

Secondly, the left inline block has a fixed width while the right needs to cover up the remaining width ✔️ 其次,左边的内联块具有固定的宽度,而右边的内联块需要掩盖剩余的宽度✔️

Thirdly, the second block should have another element which is hidden and ought to show on hover 第三,第二个方块应具有另一个元素,该元素应隐藏并在悬停时显示

Lastly I want the two blocks to have an even height at all times when the height of either of them changes 最后,当两个块中任何一个的高度发生变化时,我都希望它们始终保持均匀的高度

EDIT Paragraph div needs to show on hover. 编辑段落div需要在悬停时显示。 Also I want the height of the inline blocks to come out even whenever either of them changes. 我也希望内联块的高度能够出现,即使它们中的任何一个改变。

This is what I have so far 这就是我到目前为止

 .slideList { width: 100%; } .slideList li { position:relative; } .slideList .service-highlight { position: absolute; color: white; bottom: 0; left: 0; right:0 } .slideList .service-highlight p { display: inline-block; color: white; font-size: 18px; font-weight: bold; } .slideList .service-highlight .services-box{ text-align: center; background-color: #003768; width: 200px; font-weight: bold; float: left; } .slideList .service-highlight .services-detail{ background-color: #0088ff; width:calc(100% - 200px); float: left; padding-left: 5px; } .slideList .hide-description { display: none; font-weight:normal; } .slideList .hide-description p { font-weight:normal; padding-top: 10px 5px 10px; } .services-detail:hover + .hide-description { display: block; position: absolute; } .clearFloat { clear: both; } 
 <ul class="slideList"> <li data-transition="fade"> <img src="https://images.unsplash.com/photo-1532274402911-5a369e4c4bb5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&q=80" > <div class="service-highlight"> <p class="services-box">SOME SERVICE:</p> <div class="services-detail"> <p>Some headline</p> <div class="hide-description"> <p>Some text that appears here. Text describes some service I intend to achieve. This may or may not take up to three lines maybe two </p> </div> </div> </div> </li> <ul> 

1 & 2) The white space can be removed by simply floating .services-box & .service-highlight to the left, and then set the fixed width to .service-box and give a percentage width to .service-highlight . 1和2)可以通过简单地将.services-box.service-highlight浮动到左侧,然后将固定宽度设置为.service-box并将百分比宽度设置为.service-highlight.service-highlight

3) To achieve this, you need to use :hover . 3)为此,您需要使用:hover However, take note you can't put it on the same line because when you hover, the hidden box appear, and since your mouse is on it, the mouse is on the new box, so it loses its :hover effect and goes back to the original state, thus it will make it blink. 但是,请注意,您不能将其放在同一行上,因为当您将鼠标悬停时,将显示隐藏的框,并且由于鼠标位于其上,因此鼠标位于新框上,因此它失去了:hover效果并返回到原始状态,它将使其闪烁。 So put that new display box above to avoid this. 因此,请在上方放一个新的显示框,以避免出现这种情况。

Hope this helped! 希望这对您有所帮助!

 .slideList { width: 100%; } .slideList li { position:relative; } .slideList .service-highlight { position: absolute; color: white; bottom: 0; left: 0; right:0 } .slideList .service-highlight p { display: inline-block; color: white; font-size: 18px; font-weight: bold; } .slideList .service-highlight .services-box{ text-align: center; background-color: #003768; width: 200px; font-weight: bold; float: left; } .slideList .service-highlight .services-detail{ background-color: #0088ff; width:calc(100% - 202px); float: left; } .slideList .hide-description { display: none; } .services-detail:hover + .hide-description { display: block; position: absolute; bottom: 50px; } .clearFloat { clear: both; } 
 <ul class="slideList"> <li data-transition="fade"> <img src="https://images.unsplash.com/photo-1532274402911-5a369e4c4bb5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&q=80" > <div class="service-highlight"> <p class="services-box">SOME SERVICES:</p> <p class="services-detail">Service headline detail</p> <div class="hide-description"> <!-- Div should be a continuation of .services-detail --> <p>A more detailed description of services. This should appear here. In about 3 sentences and at least three lines long</p> </div> <div class="clearFloat"></div> </div> </li> <ul> 

UPDATE 2: 更新2:

From the reference you linked, that is hover on box and not the text. 在您链接的参考中,将鼠标悬停在框上而不是文本上。 I've changed the markup abit, please take a look now: 我已更改了标记升迁的范围,请立即查看:

 * { margin: 0; padding: 0; } .slideList { width: 100%; height: 550px; background-image: url("https://images.unsplash.com/photo-1532274402911-5a369e4c4bb5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&q=80"); background-repeat: no-repeat; background-size: cover; position: relative; } .slideList ul { list-style: none; } .service-highlight { position: absolute; bottom: 0; width: 100%; } .services-box { text-align: center; background-color: #003768; width: 200px; font-weight: bold; float: left; } .services-detail { background-color: #0088ff; width: calc(100% - 200px); float: left; } .hide-description { display: none; } .slideList:hover .hide-description { display: block; position: absolute; bottom: 0px; background-color: #0088ff; } .clearFloat { clear: both; } 
 <ul class="slideList"> <li data-transition="fade"> <div class="service-highlight"> <p class="services-box">SOME SERVICES:</p> <p class="services-detail">Service headline detail</p> <div class="hide-description"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quisquam animi accusamus officia accusantium quaerat distinctio, omnis neque adipisci! Rerum nemo vitae necessitatibus autem fugit ipsam in nam asperiores. Eius, vitae. </div> <div class="clearFloat"></div> </div> </li> <ul> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM