简体   繁体   English

引导分隔器在较小的屏幕上移动

[英]Bootstrap divider displaced on smaller screens

I'm currently developing a website, one of my first bootstrap websites. 我目前正在开发一个网站,这是我的第一个引导网站之一。

Facing a problem that I've been trying to solve for a few hours now. 面对一个我已经尝试解决了几个小时的问题。

I'm placing a divider or separator that I made in photoshop (png image) on the edge of a section. 我将在Photoshop中制作的分隔线或分隔线(png图像)放在部分的边缘上。

It looks like this on desktop size: 在桌面尺寸上看起来像这样:

https://www.dropbox.com/s/qxf7dheb0k79q2b/Screenshot%202014-09-30%2023.02.50.png?dl=0 https://www.dropbox.com/s/qxf7dheb0k79q2b/Screenshot%202014-09-30%2023.02.50.png?dl=0

But on smaller screens this happens: 但是在较小的屏幕上会发生这种情况:

https://www.dropbox.com/s/w4je7milallfrqn/Screenshot%202014-09-30%2023.10.50.png?dl=0 https://www.dropbox.com/s/w4je7milallfrqn/Screenshot%202014-09-30%2023.10.50.png?dl=0

I'm sure it due to my bad CSS. 我确定是由于我的CSS不好所致。

Here is my html and css: 这是我的HTML和CSS:

<section class="hero-section text-center">
  <img class="separator img-responsive"src="images/separator.png">
  <div class="container">
    <h1>Download Now</h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
    consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
    cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
    proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
    <hr>
    <button class="btn btncta">Download Now</button>
    <p class="small">*Needed for developers</p>
  </div>
</section>

CSS: CSS:

.separator{
display: block;
margin-left: auto;
margin-right: auto;
position: relative;
top:318px;

}

Any way I could fix this? 有什么办法可以解决吗?

Is it using a image for divider outdated (probably is)? 它是否使用了过时的图像(可能是)?

There's nothing wrong with using that separator image approach , but you're doing it wrong. 使用该分隔符图像方法没有什么错,但是您做错了。 Just replace your CSS like this: 只需像这样替换您的CSS:

.separator{
display: block;
margin-left: auto;
margin-right: auto;
position: relative;
top:0px;
width:100%; height:1px;
}

and your HTML like this: 和你的HTML是这样的:

<section class="hero-section text-center">

  <div class="container">
    <h1>Download Now</h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
    consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
    cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
    proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
    <hr>
    <button class="btn btncta">Download Now</button>
    <p class="small">*Needed for developers</p>
  </div>
  <img class="separator "src="images/separator.png">
</section>

I did a bootply so you can see (the background color is not needed, is just so you see the effect since I don't have your image) 我做了一个bootply,所以您可以看到(不需要背景颜色,只是因为您没有图像,所以您可以看到效果)

Adding new method based in new information: 根据新信息添加新方法:

/* CSS used here will be applied after bootstrap.css */
 body {
    background:#f00;
}
.separator {
    display: block;
    margin-left: auto;
    margin-right: auto;
    position: relative;
    top:0px;
    background:#f00;
    width:100%;
    height:1px;
}
.hero-section {
    background:#fff url('http://www.customstairsandmouldings.com/images/circle.jpg') no-repeat center bottom; / we center the background and position it at the bottom of the div */
    padding-bottom: 100px; /* padding-bottom has to be enough to give room to the image in the background, so if image height is 80px, padding bottom should be at least 80px, or better 100px to add spacing */
}

See new Bootply here 在这里查看新的Bootply

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

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