总结
:hover:after 显示图像.outercontainer:hover 上的图像淡入有效,但它不会在后淡出>:hover 状态是 terminated 我尝试使用单独的动画/相同的动画向后但没有运气 期望的效果:
所有东西都装在标有蓝色边框的容器内
.outercontainer
编辑: 图片应该有自己的空间 - 大约 80% 的容器 宽度和选项/菜单将是另外 20% - 没有重叠(如果图像重叠在选项上,平板电脑用户将停留在:悬停状态)
.outercontainer 和 everyting inside 根据屏幕调整
宽度
需要支持的最小设备宽度为 600 像素(忽略小于 600 像素的屏幕)
步骤:
:hover:hover类似的帖子/问题
Scale image inside div up AND/OR down to fit largest side of image with CSS (将图像定位为元素而不是伪元素的背景)
Scale all images to fit container proportionally (地址图像是 一个元素的背景,而不是它是一个元素的背景 :after 伪元素)
在 SO 上还有很多类似的问题.我还没有找到一个解决图像作为 :after 伪元素背景的问题
我的问题
如何将使用 :hover:after 显示的图像放入其父容器中? (我希望它占用的空间不超过该容器宽度的 80%-85% - 其余空间应分配给选项/菜单/列表项)
如何使图像显示为 :hover:after responsive?
如何让元素在取消悬停后淡出?
我的 CSS 和 HTML 在下面的代码段中 (不完全响应 - 请全屏打开)
/* Start Miscellaneous stuff */
body {
background: #131418;
color: #999;
text-align: center;
}
.optionlist a {
color: #999;
text-decoration: none;
}
@keyframes mycoolfade {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* End Miscellaneous stuff */
.outercontainer {
border: 1px solid blue; /*This needs to be in the middle of the screen and everthing should fit inside it*/
position: fixed; /*border to highlight only - not part of final product*/
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 1200px;
max-width: 80%
}
.optioncontainer {
width: 250px;
max-width: 20vw;
}
.optionlist li {
background: #fff;
padding: .5em;
box-shadow: inset 10px 10px 100px 25px rgba(0, 0, 0, .8);
list-style-type: none;
}
.optionlist li:nth-child(odd) {
background: #000;
}
.optionlist li:hover {
background: red;
}
.optionlist li:hover:after { /* The part the needs to be fixed */
content: '';
width: 800px;
height: 600px;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
animation: mycoolfade 1s;
}
/* Start Background Control */
#red:after {background: url(http://lorempixel.com/800/600/)}
#blue:after {background: url(http://lorempixel.com/800/601/)}
#green:after {background: url(http://lorempixel.com/801/600/)}
#yellow:after {background: url(http://lorempixel.com/801/601/)}
#orange:after {background: url(http://lorempixel.com/799/600/)}
#white:after {background: url(http://lorempixel.com/800/599/)}
#black:after {background: url(http://lorempixel.com/801/599/)}
/* End Background Control */<body>
The initial hiccup when the images load is not an issue
<div class="outercontainer">
<div class="optioncontainer">
<div class="optionlist">
<li id="red">Red</li>
<li id="blue">Blue</li>
<li id="green">Green</li>
<li id="yellow">Yellow</li>
<li id="orange">Orange</li>
<li id="white">White</li>
<li id="black">Black</li>
</div>
</div>
</div>
</body>
谢谢。
最佳答案
只要在任何你想要的地方设置你的outercontainer。将 outercontainer position 样式更改为 relative 并将 after 伪元素样式更改为 position: absolute 后;左:0;顶部:0;宽度:100%; height: 100%; 似乎可以正常工作。使用 CSS 动画,您可以应用淡入淡出效果。
============最新变化==============
为 outercontainer 添加了与位置和边距相关的样式以将其显示到中心,添加了伪元素 background 样式,如 no-repeat 和背景大小:覆盖。将 div 标记更改为 ul 和 ul 的 flex 样式。
/* Start Miscellaneous stuff */
body {
background: #131418;
color: #999;
text-align: center;
}
.optionlist a {
color: #999;
text-decoration: none;
}
@keyframes mycoolfade {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* End Miscellaneous stuff */
.outercontainer {
border: 1px solid blue; /*This needs to be in the middle of the screen and everthing should fit inside it*/
position: absolute; /*border to highlight only - not part of final product*/
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
min-width: 50%;
min-height: 50%;
width: 80%;
height: 80%;
transform: translate(-50%, -50%);
}
.optioncontainer {
width: 250px;
max-width: 20vw;
height: 100%;
}
.optionlist {
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
height: 100%;
}
.optionlist li {
background: #fff;
padding: .5em;
box-shadow: inset 10px 10px 100px 25px rgba(0, 0, 0, .8);
list-style-type: none;
}
.optionlist li:nth-child(odd) {
background: #000;
}
.optionlist li:hover {
background: red;
}
.optionlist li:hover:after { /* The part the needs to be fixed */
content: '';
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
transform: translate(-50%, -50%);
animation: mycoolfade 1s;
z-index:-1;
}
/* Start Background Control */
#red:after {
background: url(http://lorempixel.com/800/600/) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#blue:after {
background: url(http://lorempixel.com/800/601/) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#green:after {
background: url(http://lorempixel.com/801/600/) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#yellow:after {
background: url(http://lorempixel.com/801/601/) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#orange:after {
background: url(http://lorempixel.com/799/600/) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#white:after {
background: url(http://lorempixel.com/800/599/) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#black:after {
background: url(http://lorempixel.com/801/599/) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
/* End Background Control */<body>
The initial hiccup when the images load is not an issue
<div class="outercontainer">
<div class="optioncontainer">
<ul class="optionlist">
<li id="red">Red</li>
<li id="blue">Blue</li>
<li id="green">Green</li>
<li id="yellow">Yellow</li>
<li id="orange">Orange</li>
<li id="white">White</li>
<li id="black">Black</li>
</ul>
</div>
</div>
</body>
关于html - 伪元素背景显示在 :hover,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41236294/
我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h
我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
在我的Controller中,我通过以下方式在我的index方法中支持HTML和JSON:respond_todo|format|format.htmlformat.json{renderjson:@user}end在浏览器中拉起它时,它会自然地以HTML呈现。但是,当我对/user资源进行内容类型为application/json的curl调用时(因为它是索引方法),我仍然将HTML作为响应。如何获取JSON作为响应?我还需要说明什么? 最佳答案 您应该将.json附加到请求的url,提供的格式在routes.rb的路径中定义。这
所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择
我试图在索引页中创建一个超链接,但它没有显示,也没有给出任何错误。这是我的index.html.erb代码。ListingarticlesTitleTextssss我检查了我的路线,我认为它们也没有问题。PrefixVerbURIPatternController#Actionwelcome_indexGET/welcome/index(.:format)welcome#indexarticlesGET/articles(.:format)articles#indexPOST/articles(.:format)articles#createnew_articleGET/article
我有一张背景图片,我想在其中添加一个文本框。我想弄清楚如何将标题放置在其顶部的正确位置。(我使用标题是因为我需要自动换行功能)。现在,我只能让文本显示在左上角,但我需要能够手动定位它的开始位置。require'RMagick'require'Pry'includeMagicktext="Loremipsumdolorsitamet"img=ImageList.new('template001.jpg')img 最佳答案 这是使用convert的ImageMagick命令行的答案。如果你想在Rmagick中使用这个方法,你必须自己移植
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c
我正在使用Rails构建一个简单的聊天应用程序。当用户输入url时,我希望将其输出为html链接(即“url”)。我想知道在Ruby中是否有任何库或众所周知的方法可以做到这一点。如果没有,我有一些不错的正则表达式示例代码可以使用... 最佳答案 查看auto_linkRails提供的辅助方法。这会将所有URL和电子邮件地址变成可点击的链接(htmlanchor标记)。这是文档中的代码示例。auto_link("Gotohttp://www.rubyonrails.organdsayhellotodavid@loudthinking.
查看我的Ruby代码:h=Hash.new([])h[0]=:word1h[1]=h[1]输出是:Hash={0=>:word1,1=>[:word2,:word3],2=>[:word2,:word3]}我希望有Hash={0=>:word1,1=>[:word2],2=>[:word3]}为什么要附加第二个哈希元素(数组)?如何将新数组元素附加到第三个哈希元素? 最佳答案 如果您提供单个值作为Hash.new的参数(例如Hash.new([]),完全相同的对象将用作每个缺失键的默认值。这就是您所拥有的,那是你不想要的。您可以改用