动态高度问题(Dynamic height issue)
我试图实现一个幻灯片,但它不完全动态。 图像部分动态调整大小,但无论浏览器窗口有多大,导航按钮/面板左右以及整个框/框都保持不变。
这部分代码似乎是问题,更确切地说,是“高度”线:
.slides { padding: 0; width: 100%; height: 840px; display: block; margin: 0 auto; position: relative; }
我还不是很擅长html / css,但我尝试过将高度和宽度设置为auto或100%的各种组合。
这里是完整的CSS代码:
<style type="text/css"> @import url(https://fonts.googleapis.com/css?family=Varela+Round); .slides { padding: 0; width: 100%; height: 840px; display: block; margin: 0 auto; position: relative; } .slides * { user-select: none; -ms-user-select: none; -moz-user-select: none; -khtml-user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; } .slides input { display: none; } .slide-container { display: block; } .slide { top: 0; opacity: 0; width: 100; height: 100; display: block; position: absolute; transform: scale(1); transition: all .7s ease-in-out; } .slide img { width: 100%; height: 100%; } .nav label { width: 200px; height: 100%; display: none; position: absolute; opacity: 0; z-index: 9; cursor: pointer; transition: opacity .2s; color: rgb(255,133,102); font-size: 156pt; text-align: center; line-height: 380%; font-family: "Varela Round", sans-serif; background-color: rgba(255, 255, 255, .3); text-shadow: 0px 0px 15px rgb(119, 119, 119); } .slide:hover + .nav label { opacity: 0.5; } .nav label:hover { opacity: 1; } .nav .next { right: 0; } input:checked + .slide-container .slide { opacity: 1; transform: scale(1); transition: opacity 1s ease-in-out; } input:checked + .slide-container .nav label { display: block; } .nav-dots { width: 100%; bottom: 9px; height: 11px; display: block; position: absolute; text-align: center; } .nav-dots .nav-dot { top: -5px; width: 11px; height: 11px; margin: 0 4px; position: relative; border-radius: 100%; display: inline-block; background-color: rgba(255, 0, 0, 0.6); } .nav-dots .nav-dot:hover { cursor: pointer; background-color: rgba(255, 0, 0, 0.8); } input#img-1:checked ~ .nav-dots label#img-dot-1, input#img-2:checked ~ .nav-dots label#img-dot-2, input#img-3:checked ~ .nav-dots label#img-dot-3, input#img-4:checked ~ .nav-dots label#img-dot-4, input#img-5:checked ~ .nav-dots label#img-dot-5, input#img-6:checked ~ .nav-dots label#img-dot-6 { background: rgba(255, 0, 0, 1); } </style>
任何人的想法?
编辑:
@showdev
HTML部分:
<ul class="slides"> <input type="radio" name="radio-btn" id="img-1" checked /> <li class="slide-container" > <div class="slide"> <img src="https://images.pexels.com/photos/91217/pexels-photo-91217.jpeg" /> </div> <div class="nav"> <label for="img-6" class="prev">‹</label> <label for="img-2" class="next">›</label> </div> </li> <input type="radio" name="radio-btn" id="img-2" /> <li class="slide-container"> <div class="slide"> <img src="https://images.pexels.com/photos/91217/pexels-photo-91217.jpeg" /> </div> <div class="nav"> <label for="img-1" class="prev">‹</label> <label for="img-3" class="next">›</label> </div> </li> <input type="radio" name="radio-btn" id="img-3" /> <li class="slide-container"> <div class="slide"> <img src="" /> </div> <div class="nav"> <label for="img-2" class="prev">‹</label> <label for="img-4" class="next">›</label> </div> </li> <input type="radio" name="radio-btn" id="img-4" /> <li class="slide-container"> <div class="slide"> <img src="" /> </div> <div class="nav"> <label for="img-3" class="prev">‹</label> <label for="img-5" class="next">›</label> </div> </li> <input type="radio" name="radio-btn" id="img-5" /> <li class="slide-container"> <div class="slide"> <img src="" /> </div> <div class="nav"> <label for="img-4" class="prev">‹</label> <label for="img-6" class="next">›</label> </div> </li> <input type="radio" name="radio-btn" id="img-6" /> <li class="slide-container"> <div class="slide"> <img src="" /> </div> <div class="nav"> <label for="img-5" class="prev">‹</label> <label for="img-1" class="next">›</label> </div> </li> <li class="nav-dots"> <label for="img-1" class="nav-dot" id="img-dot-1"></label> <label for="img-2" class="nav-dot" id="img-dot-2"></label> <label for="img-3" class="nav-dot" id="img-dot-3"></label> <label for="img-4" class="nav-dot" id="img-dot-4"></label> <label for="img-5" class="nav-dot" id="img-dot-5"></label> <label for="img-6" class="nav-dot" id="img-dot-6"></label> </li>
现在只有两张相同的图片被链接,但是想法是这些图片都是相同的大小。 我根据另一个答案编辑了代码,最初忘记了两个百分比符号,现在图像与框对齐,但尺寸仅沿水平轴而非垂直轴调整。 其结果基本上是一个非常挤压的图像,总是具有相同大小的前后窗格/按钮并且高度一致。 这个问题被下调了,不知道为什么。 我一直试图想出一个解决方案,我只是不成功,因此我的职位在这里。
I tried to implement a slideshow, but it's not fully dynamic. The image part resizes dynamically, but the navigation buttons/panels left and right as well es the overall box/frame stay the same, no matter how large the browser window.
This part of the code seems to be the issue, to be more exact, the "height" line:
.slides { padding: 0; width: 100%; height: 840px; display: block; margin: 0 auto; position: relative; }
I am not that good at html/css yet, but I tried various combination of setting the height and width to auto or 100%.
Here is the complete css code:
<style type="text/css"> @import url(https://fonts.googleapis.com/css?family=Varela+Round); .slides { padding: 0; width: 100%; height: 840px; display: block; margin: 0 auto; position: relative; } .slides * { user-select: none; -ms-user-select: none; -moz-user-select: none; -khtml-user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; } .slides input { display: none; } .slide-container { display: block; } .slide { top: 0; opacity: 0; width: 100; height: 100; display: block; position: absolute; transform: scale(1); transition: all .7s ease-in-out; } .slide img { width: 100%; height: 100%; } .nav label { width: 200px; height: 100%; display: none; position: absolute; opacity: 0; z-index: 9; cursor: pointer; transition: opacity .2s; color: rgb(255,133,102); font-size: 156pt; text-align: center; line-height: 380%; font-family: "Varela Round", sans-serif; background-color: rgba(255, 255, 255, .3); text-shadow: 0px 0px 15px rgb(119, 119, 119); } .slide:hover + .nav label { opacity: 0.5; } .nav label:hover { opacity: 1; } .nav .next { right: 0; } input:checked + .slide-container .slide { opacity: 1; transform: scale(1); transition: opacity 1s ease-in-out; } input:checked + .slide-container .nav label { display: block; } .nav-dots { width: 100%; bottom: 9px; height: 11px; display: block; position: absolute; text-align: center; } .nav-dots .nav-dot { top: -5px; width: 11px; height: 11px; margin: 0 4px; position: relative; border-radius: 100%; display: inline-block; background-color: rgba(255, 0, 0, 0.6); } .nav-dots .nav-dot:hover { cursor: pointer; background-color: rgba(255, 0, 0, 0.8); } input#img-1:checked ~ .nav-dots label#img-dot-1, input#img-2:checked ~ .nav-dots label#img-dot-2, input#img-3:checked ~ .nav-dots label#img-dot-3, input#img-4:checked ~ .nav-dots label#img-dot-4, input#img-5:checked ~ .nav-dots label#img-dot-5, input#img-6:checked ~ .nav-dots label#img-dot-6 { background: rgba(255, 0, 0, 1); } </style>
Anyone an idea?
Edit:
@showdev
HTML part:
<ul class="slides"> <input type="radio" name="radio-btn" id="img-1" checked /> <li class="slide-container" > <div class="slide"> <img src="https://images.pexels.com/photos/91217/pexels-photo-91217.jpeg" /> </div> <div class="nav"> <label for="img-6" class="prev">‹</label> <label for="img-2" class="next">›</label> </div> </li> <input type="radio" name="radio-btn" id="img-2" /> <li class="slide-container"> <div class="slide"> <img src="https://images.pexels.com/photos/91217/pexels-photo-91217.jpeg" /> </div> <div class="nav"> <label for="img-1" class="prev">‹</label> <label for="img-3" class="next">›</label> </div> </li> <input type="radio" name="radio-btn" id="img-3" /> <li class="slide-container"> <div class="slide"> <img src="" /> </div> <div class="nav"> <label for="img-2" class="prev">‹</label> <label for="img-4" class="next">›</label> </div> </li> <input type="radio" name="radio-btn" id="img-4" /> <li class="slide-container"> <div class="slide"> <img src="" /> </div> <div class="nav"> <label for="img-3" class="prev">‹</label> <label for="img-5" class="next">›</label> </div> </li> <input type="radio" name="radio-btn" id="img-5" /> <li class="slide-container"> <div class="slide"> <img src="" /> </div> <div class="nav"> <label for="img-4" class="prev">‹</label> <label for="img-6" class="next">›</label> </div> </li> <input type="radio" name="radio-btn" id="img-6" /> <li class="slide-container"> <div class="slide"> <img src="" /> </div> <div class="nav"> <label for="img-5" class="prev">‹</label> <label for="img-1" class="next">›</label> </div> </li> <li class="nav-dots"> <label for="img-1" class="nav-dot" id="img-dot-1"></label> <label for="img-2" class="nav-dot" id="img-dot-2"></label> <label for="img-3" class="nav-dot" id="img-dot-3"></label> <label for="img-4" class="nav-dot" id="img-dot-4"></label> <label for="img-5" class="nav-dot" id="img-dot-5"></label> <label for="img-6" class="nav-dot" id="img-dot-6"></label> </li>
Right now there are just two of the same picture linked, but the idea is that these are all the same size. I edited the code based on the other answer, forgot two percentage signs initially, and now the image is aligned with the box, but the size is only adjusting along the horizontal, not vertical axis. The result is basically a very squished image with always identically sized back and forth panes/buttons and consistent in height. This question got down-voted, not quite sure why. I have been trying to come up with a solution, I was just not successful, hence my post here.
原文:https://stackoverflow.com/questions/48454386
最满意答案
只需向Application Controller添加一个方法,该方法禁止访问未经身份验证的用户(使用
before_filter
),并为要为其授予访问权限的控制器覆盖此方法。所以在应用控制器中:
before_filter :only_authenticated_users_are_welcome def only_authenticated_users_are_welcome !user.blank? end
并授予对某些页面及其控制器的访问权限:
def only_authenticated_users_are_welcome true end
或者添加一些逻辑以仅授予对控制器内某些操作的访问权限。
Just add a method to Application Controller that forbids access to nonauthenticated users (using
before_filter
) and overwrite this method for controllers where you want to give them access.So in application controller:
before_filter :only_authenticated_users_are_welcome def only_authenticated_users_are_welcome !user.blank? end
And to grant access to some pages and in their controller:
def only_authenticated_users_are_welcome true end
Or add some more logic to grant access only to some actions within the controller.
相关问答
更多-
Rails 4 + Devise:为经过身份验证的用户设置默认根路由(Rails 4 + Devise: set default root route for authenticated users)[2022-12-06]
更改routes.rb以便包装未经身份验证的root路由,就像经过身份验证的路由一样: devise_for :users, :path => 'account', controllers: { registrations: "registrations", confirmations: "confirmations" } authenticated :user do root 'calendars#index', as: :authenticated_root end unauthenticate ... -
取决于你的路由/网址。 如果你在url中公开了user-id,你肯定应该因为一旦登录,我就很容易尝试重置其他人的密码。 黑客很容易显示自己的表单,然后在发布之前inspect和编辑表单。 如果您使用的URL如GET :profile和POST/PUT :profile允许用户只能查看和编辑他们自己的配置文件,他们不能再尝试编辑别人的配置文件(因为用户/配置文件之间的链接 -数据和登录的会话是在服务器端进行的)。 如果您使用UUID网址,您的网址已经更安全了(很难猜测其他网址),但这仍然不是安全防护措施,因此 ...
-
经过身份验证的用户从jQuery向rails API发出AJAX请求(Authenticated user making AJAX requests to rails API from jQuery)[2024-02-27]
AJAX请求(XMLHttpRequest)将在同一域的标准HTTP请求中包含相同的标头。 至于从标题中读取cookie,查找会话信息以及授权请求,行为将是相同的。 An AJAX request (XMLHttpRequest) will contain the same headers at a standard HTTP request for the same domain. As far as reading the cookie from the header, looking up the s ... -
我不知道它是否有效,但我会试过这个 class ApplicationController < ActionController::Base skip_before_filter :verify_authenticity_token end I don't know if it works but i would have tried this class ApplicationController < ActionController::Base skip_before_filter :veri ...
-
只需向Application Controller添加一个方法,该方法禁止访问未经身份验证的用户(使用before_filter ),并为要为其授予访问权限的控制器覆盖此方法。 所以在应用控制器中: before_filter :only_authenticated_users_are_welcome def only_authenticated_users_are_welcome !user.blank? end 并授予对某些页面及其控制器的访问权限: def only_authenticated ...
-
走这条路怎么样? 在你的控制器中: skip_before_filter :verify_authenticity_token, :only => :api def api @callback = request.body.read if !@callback.blank? People.create :name => @callback end end 在routes.rb中: map.api '/api ...
-
HTTPS是一种直接通过线路保护通信的方式。 可以使用oAuth完成重用和令牌以进行后续通信。 您可能想要采用Facebook在其iOS SDK中采用的方法。 他们在UIWebView(HTTPS)中放置了他们的登录页面,并返回oAuth令牌以进行后续调用。 编辑:由于SSL似乎“脱离了桌面” - 为什么不用基本身份验证进行身份验证,并让每个调用重新进行身份验证而不是使用令牌。 HTTPS is a straight forward way to secure communication as is pas ...
-
似乎门卫可以处理它的初始化器。 只需添加它就可以了。 admin_authenticator do redirect_to new_user_session_url unless current_user && current_user.admin? end Seems Doorkeeper can handle in it's initializer. Just add this and it works. admin_authenticator do redirect_to new_ ...
-
Rails:如何使用dragonfly保护上传到S3的图像(Rails: How to protect images uploaded to S3 using dragonfly)[2022-05-18]
Dragonfly允许:expires remote_url的:expires选项,它是S3DataStore的url_for的包装器。 看到这里 。 设置限制下载链接如何在10秒内过期,就像使用回形针一样 ? 您还可以在其URL中为您的图像添加随机guid,以便根据此SO问题提供更高的安全性。 不是真正的解决方案,只是一些想法。 Since I’m currently using a routed endpoint, expiring urls unfortunately don’t work for m ... -
Rails:如何在Heroku上快速保护整个站点进行开发测试?(Rails: How to quickly secure entire site for development testing on Heroku?)[2022-06-13]
如果将它添加到application_controller.rb中, http_basic_authenticate_with是一个简单的单行内容 http://apidock.com/rails/ActionController/HttpAuthentication/Basic http_basic_authenticate_with is a simple one liner if you add it to you application_controller.rb http://apidock.co ...