【问题标题】:Bootstrap layout doesn't work with safari引导布局不适用于 safari
【发布时间】:2017-10-28 04:18:27
【问题描述】:

我创建了一个网站,该网站的布局可以与除 Safari 之外的任何浏览器完美呈现……列未对齐我从它们的 div 中获取图像。我不知道为什么会这样。你遇到过这样的问题吗?

下面是代码示例(使用 Bootstrap 4):

        <div class="row" style="margin: 0px; padding: 0px;">
        <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-6"
            style="margin: 0px; padding: 0px;">
            <div class="row align-items-center" style="margin: 0px; padding: 0px;">
                <div
                    class="hidden-xs hidden-sm col-md-3 col-lg-3 col-xl-3 text-center"
                    style="margin: 0px; padding: 0px;"></div>
                <div
                    class="col-xs-12 col-sm-12 col-md-9 col-lg-9 col-xl-9 text-center"
                    style="margin: 0px; padding: 0px;">
                    <titre2>{{sections[section.sections[0]]['name']}}</titre2>
                </div>
                <div
                    class="hidden-xs hidden-sm col-md-3 col-lg-3 col-xl-3 box empty2"
                    style="margin: 0px; padding: 0px;"></div>
                <div class="col-xs-12 col-sm-12 col-md-9 col-lg-9 col-xl-9 boxsup"
                    style="margin: 0px; padding: 0px;">
                    <a
                        href="{{ path('section', {'section_name': sections[section.sections[0]]['name']}) }}">
                        <center>
                            <img class="ownthumbnail1"
                                src="{{ asset(contents[0]|first) | imagine_filter('medium') }}"
                                alt="">
                        </center>
                    </a>
                </div>
            </div>
        </div>


        <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-6"
            style="margin: 0px; padding: 0px;">
            <div class="row align-items-center" style="margin: 0px; padding: 0px;">
                <div
                    class="col-xs-12 col-sm-12 col-md-9 col-lg-9 col-xl-9 text-center"
                    style="margin: 0px; padding: 0px;">
                    <titre2>{{sections[section.sections[1]]['name']}}</titre2>
                </div>
                <div
                    class="hidden-xs hidden-sm col-md-3 col-lg-3 col-xl-3 text-center"
                    style="margin: 0px; padding: 0px;"></div>
                <div class="col-xs-12 col-sm-12 col-md-9 col-lg-9 col-xl-9 boxsup"
                    style="margin: 0px; padding: 0px;">
                    <a
                        href="{{ path('section', {'section_name': sections[section.sections[1]]['name']}) }}">
                        <center>
                            <img class="ownthumbnail2"
                                src="{{ asset(contents[1]|first) | imagine_filter('medium') }}"
                                alt="">
                        </center>
                    </a>
                </div>
                <div
                    class="hidden-xs hidden-sm col-md-3 col-lg-3 col-xl-3 box empty2"
                    style="margin: 0px; padding: 0px;"></div>
            </div>
        </div>
    </div>

【问题讨论】:

  • 您能否提供一个显示最终内容的示例。当我们看不到实际图像时,很难诊断出诸如“图像超出其 div”之类的问题。
  • 文档清楚地说windows safari is not supported
  • @pbenard ...我不知道你为什么会假设这个人对 Safari 的问题是特定于 Safari for Windows 的,它于 2012 年被 Apple 停产。
  • @RobertC 我知道你不能确定自己,正如你所看到的,这只是一个评论,而不是一个答案。我有没有说提问者正在使用 windows ?不。但有趣的是,windows safari 不支持这个版本的 bootstrap。
  • 请不要在链接后面隐藏代码。而是将所有相关代码带入问题中,以便它是自包含的。如果链接因任何原因而失效,问题就变得毫无用处。谢谢。

标签: html css twitter-bootstrap safari


【解决方案1】:

对于仍然遇到此问题的任何人,我可以通过添加来解决它

.row:before, .row:after {
display: flex !important;
}

显然这不是最优雅的解决方案,您可能需要查看代码以进行检查和平衡,但在此期间它应该可以解决问题,直到他们修复它。

【讨论】:

  • 您能详细说明一下吗?你在说什么问题?
【解决方案2】:

如果没有更好的代码示例,就很难准确诊断出您声称在使用 Apple Safari 和 Bootstrap v4 时遇到的问题。话虽如此,似乎基于提供的结构,您可以大大简化您的代码,这可能具有解决您的问题的额外好处。

如果您在 SO 渲染 Bootstrap v4 Alpha 时遇到问题,您还可以查看此代码的 Bootply:https://www.bootply.com/o8dF8rD9IH

但本质上,这里发生的事情是,我们依靠引导网格系统的.offset-*-* 功能来避免当前代码中出现各种空的&lt;div&gt; 元素。这大大简化了实现相同结果所需的代码量。

.img-responsive 应用于图像(以及该类的宽度)允许图像根据屏幕分辨率更好地缩放。这应该有助于缓解图像超出列范围的情况。

/* Backgrounds just to illustrate .container shape */
.container-fluid {
  background: #eee;
}

.col-md-4 {
  background: #ddd;
}

/* Make .img-responsive images use 100% of the space */
.img-responsive { 
  width: 100%;
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet">

<div class="container-fluid">
	<div class="row text-center">
		<div class="col-xs-12 col-sm-12 col-md-4 offset-md-2">
			<h1>Title #1</h1>
			<a href="#null"><img src="http://placehold.it/350x250/" class="img-responsive" /></a>
		</div>
		
		<div class="col-xs-12 col-sm-12 col-md-4">
			<h1>Title #2</h1>
			<a href="#null"><img src="http://placehold.it/350x250/" class="img-responsive" /></a>
		</div>
	</div>
</div> 

【讨论】:

  • 非常感谢您的提示。我知道代码 sn-p 很短,但我的整个网站在 safari 中看起来很糟糕,在其他浏览器中看起来不错。所以对我来说,这更像是一个普遍的问题,比如“Safari + Bootstrap 4 有什么问题?”
  • @Robert_C 我编辑了问题并给出了我网站的代码 sn-p。
【解决方案3】:

根据我对您问题的理解,首先您需要检查是否添加了图像响应类。在 bootstrap4 中,他们更改了一些类名。所以你可以通过here。如果可能的话,把你的网站的链接,这样我就可以给你更好的答案。

你需要添加类。

img 缩略图

注意

首先检查您的引导程序版本。有时您使用版本引导程序版本 3,而类使用引导程序版本 4。这就是它们按类发生冲突的原因。

【讨论】:

  • 在这里查看:www.debzsud.com
  • @debzsud 实际上您使用的是引导程序版本 3。在您的代码中,您使用了引导程序 4 类。请更改引导程序版本或引导程序类。
猜你喜欢
  • 2016-07-19
  • 2021-05-02
  • 2013-07-18
  • 1970-01-01
  • 1970-01-01
  • 2021-06-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多