简体   繁体   English

HTML / CSS Bootstrap响应式布局与广告并排div?

[英]HTML/CSS Bootstrap responsive layout with side by side div's for ads?

I have a website, already built in bootstrap, it's a wordpress theme and it's responsive. 我有一个网站,已经内置了bootstrap,它是一个wordpress主题,它的响应。

It's not up on the web so i can't show you exactly example of my theme but it follows this kind of markup http://getbootstrap.com/examples/carousel/ 它不是在网上,所以我无法向您展示我的主题的确切示例,但它遵循这种标记http://getbootstrap.com/examples/carousel/

My header with menu is full width and slider is full width, and content is wrapped in container very similar as example from getbootstrap. 带有菜单的标题是全宽度,滑块是全宽度,内容被包装在容器中,与getbootstrap的示例非常相似。

Now i need to add ads to the left and right side of the content, and this need to be something like this http://www.bigblue.rs/ 现在我需要在内容的左侧和右侧添加广告,这需要像这样的内容http://www.bigblue.rs/

but since bootstrap layout is responsive i tested with various width % and floats but i can't make it work. 但由于bootstrap布局是响应我测试了各种宽度%和浮动但我无法使其工作。 when i watch site on 21" they need to cover whole left and right emptiness, as site is resized, they should simply go out of the screen and not interfere with rest of the center content. 当我在21英寸观看网站时,他们需要覆盖整个左右空虚,因为网站调整大小,他们应该只是走出屏幕而不干扰其余的中心内容。

EDIT: heres demo on bootply with layout that i have on my website http://bootply.com/108951 编辑:在我的网站http://bootply.com/108951上使用布局进行bootply演示

While it won't get you the exact feel of the linked site, where the ads slide off the edge of the page, probably the easiest thing to do would be to use Bootstrap's responsive utilities classes ( http://getbootstrap.com/css/#responsive-utilities-classes ) to show and hide the ad divs as you resize the screen. 虽然它不能让您了解链接网站的确切感觉,广告从页面边缘滑落,但最简单的方法可能是使用Bootstrap的响应式实用程序类( http://getbootstrap.com/css / #response-utilities-classes )在调整屏幕大小时显示和隐藏广告div。 I've edited your Bootply demo to show what I mean, in context: http://bootply.com/108988# 我编辑了你的Bootply演示来展示我的意思,在上下文中: http ://bootply.com/108988#

If you don't feel like digging through the code: 如果你不想挖掘代码:

  1. Choose at which point you would like your content to appear. 选择您希望内容显示的位置。 Bootstrap's defaults (which can be found under "grid media queries" in the CSS documentation, sorry, I'm out of links) are sm , md , or lg . Bootstrap的默认值(可以在CSS文档中的“网格媒体查询”下找到,抱歉,我没有链接)是smmdlg We'll go with lg for the sake of brevity here. 为了简洁,我们将在这里使用lg

  2. Add one <div class="visible-lg col-lg-1>Ad Content goes here!</div> above and below your existing three <div> s, for a total of 5 div s in the row. 添加一个<div class="visible-lg col-lg-1>Ad Content goes here!</div>在现有的三个<div>的上方和下方,共计5个div

  3. Change the # on your existing <div class="col-lg-#> s so that there are 12 per row. This might be somewhat wonky, since you now have 5 columns. 更改#在你现有的<div class="col-lg-#> 。这么有12%列。这可能有点靠不住的,因为你现在有5列。

This will cause the ad divs to show and hide at the breakpoints. 这将导致广告div在断点处显示和隐藏。 While they are visible, they will resize responsively, just like the rest of the site. 虽然它们是可见的,但它们会响应地调整大小,就像网站的其他部分一样。

Alright the approach is very simple. 好的方法很简单。

On top of the page i added 2 divs. 在页面顶部我添加了2个div。 But to solve the problem with responsiveness i had to set margin of those 2 divs for each media size. 但要解决响应问题,我必须为每种媒体大小设置这两个div的余量。 Here is the styling. 这是造型。

.advertis-left {
left: 50%;
margin-left: -1050px;
position: fixed;
text-align: right;
top: 0;
width: 500px;
}
.advertis-right {
left: 50%;
margin-left: 570px;
position: fixed;
top: 0;
width: 500px;
}
/* Responsive Styles */
@media (max-width: 1199px) {

.advertis-left {
    margin-left: -950px;
}
.advertis-right {
    margin-left: 470px;
}

}
@media (max-width: 991px) {
.advertis-left {
    margin-left: -840px;
}
.advertis-right {
    margin-left: 360px;
}
}
@media (max-width: 767px) {

.navbar-nav .dropdown-submenu > .dropdown-menu {
    margin-left:10px;
    display:block;
}
.advertis-left,
.advertis-right {
    display:none;
}
}

So now i have 2 banners fixed on left and right side not overlaping with main content and when switched to other screen size it follows @media size untill it's on smallest device where it's no point to be visible at all. 所以现在我有2个横幅固定在左侧和右侧不与主要内容重叠,当切换到其他屏幕尺寸时,它遵循@media大小,直到它在最小的设备上,在那里根本不可见。

Here is a bootply example but i don't know why it's overlapping there, i guess i use different padding and margin on my content div. 这是一个bootply示例,但我不知道为什么它在那里重叠,我想我在我的内容div上使用不同的填充和边距。 http://bootply.com/110193 http://bootply.com/110193

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

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