[英]How do I vertically center an image in fullpage.js?
I'm building a site using fullpage.js and Foundation. 我正在使用fullpage.js和Foundation建立一个网站。 I'm trying to vertically center an image inside of a section and I'm having no luck.
我正在尝试将图像垂直放置在某个部分的内部,但我没有运气。
I've tried this: 我已经试过了:
https://css-tricks.com/centering-in-the-unknown/ https://css-tricks.com/centering-in-the-unknown/
I think that the issue has something to do with the fp-tableCell div that fullpage.js creates. 我认为这个问题与fullpage.js创建的fp-tableCell div有关。
<div id="first-section" class="section sTop active">
<div id="first-section-row" class="row inner">
<div id="slide_1_wrapper" class="small-12 medium-6 columns">
<h1 class="title">Hello!</h1>
<h2 class="subtitle">My name is Whatever</h2>
</div>
<div id="main-picture-wrapper" class="small-12 medium-6 columns">
<img id="main-picture" src="img/headshot.jpg" alt="my_picture">
</div>
</div>
</div>
I tried the CSS from the article above with no luck: 我没有运气就尝试了以上文章中的CSS:
#main-picture {
max-height: 400px;
}
#main-picture-wrapper {
display: inline-block;
vertical-align: middle;
}
#slide-1-wrapper {
position: relative;
}
#first-section:before {
content: '';
display: inline-block;
height: 100%;
vertical-align: middle;
margin-right: -0.25em; /* Adjusts for spacing */
}
Screenshot of the rendered html, showing the fp-tableCell 呈现的html的屏幕截图,显示了fp-tableCell
try to add this in html 尝试在html中添加
<div id="page">
<div id="content_container" class="small-12 medium-6 columns">
<div id="main-picture-wrapper">
<img id="main-picture" src="keyboard_search.png" alt="my_picture">
</div>
</div>
</div>
in css 在CSS
*{ margin:0; padding:0;}
#page{display:table;overflow:hidden;margin:0px auto;}
#content_container{display:table-cell;vertical-align: middle;}
#main-picture-wrapper p{text-align:center;}
html,body{height:100%;}
#page{height:100%;width:100%; max-width:600px; text-align:center;}
.bannerimg{width:100%;max-width:600px;margin:0px auto;}
may help you 可以帮助你
By default fullpage.js uses the option verticalCentered:true
, so any image you add will be automatically centered unless you change it by using CSS. 默认情况下,fullpage.js使用选项
verticalCentered:true
,因此,除非您使用CSS对其进行更改,否则添加的任何图像都将自动居中。
You can easily see this in any demo online or in any of the provided examples . 您可以在任何在线演示或任何提供的示例中轻松地看到这一点。
From Michael in the comments: 来自迈克尔的评论:
Try giving the wrapper ID or class position: relative and then the image class or ID position: absolute; 尝试给包装器提供ID或类位置:相对,然后提供图像类或ID位置:绝对; top: 0;
最高:0; left: 0;
左:0; right: 0;
正确:0; bottom: 0;
底部:0 margin: auto;
保证金:自动; - Rough Demo: jsfiddle.net/rrh5c04a
-粗略的演示:jsfiddle.net/rrh5c04a
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.