简体   繁体   中英

Why does my website looks different in chrome and firefox than it does in Safari using flexbox?

I am new to HTML and CSS and have very basic knowledge of both. I am creating a test website and used a tutorial from Treehouse for part of it. I wanted to use flexbox for the layout. I have created the website, and it looks like I want it to on a smartphone, it's one single column, but when it moves to an iPad screen I want the columns at the bottom to become 2 columns, and on a desktop or mbpro screen I would like all 3 columns to show up.

In chrome and firefox, my website looks exactly how I want it to. However in Safari the website does not look right. The banner in blue is offset to the left on a desktop, and the columns at the bottom are in 3, but are way disproportionate. The first column is huge, and the last two are very slim.

I was hoping someone would be able to help me look in the right direction. I have been learning HTML and CSS for a couple of weeks and am not close to proficient. I just learned about flexbox for first time this past weekend. I would like the final page to be a single column on smartphones. then on iPad, I would like the menu at the top to be in a single column row and the company name and hours etc in the blue ribbon to be centered. And then the bottom column is split into 2, and 1 on the bottom. Then on an iPad Pro, or desktop screen I would like the same as iPad, except the final column splits into 3 equal spaces.

As I have stated, at this time my chrome and firefox is doing exactly what I want, only Safari is not working right.

Correct page

Incorrect page using Safari

Below is the HTML

    <!DOCTYPE html>
    <html>
      <head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">                  <title>Name of Company</title>
<link href='https://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'>

<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/oilChangeStyles.css">

<div id="fb-root">
        <script>(function(d, s, id) {
          var js, fjs = d.getElementsByTagName(s)[0];
          if (d.getElementById(id)) return;
          js = d.createElement(s); js.id = id;
          js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.5";
          fjs.parentNode.insertBefore(js, fjs);
          }(document, 'script', 'facebook-jssdk'));
        </script>
</div>

</head>
   <body>


<header class="main-header">
    <h1 class="name"><a href="#">Name of business</a></h1>
        <ul class="main-nav">
            <li><a href="#">Oil changes</a></li>
            <li><a href="#">Trans flush</a></li>
            <li><a href="#">Trans tune ups</a></li>
            <li><a href="#">Coolant Services</a></li>
            <li><a href="#">4x4 services</a></li>
            <li><a href="#">Air filters</a></li>
        </ul><!-- .main-nav -->


</header><!-- .main-header -->   

<div class="banner">
    <div class="left-side col">
        <a href="tel:800-800-8000">(800) 800-8000</a><br />
        <a href="https://google.com"  target="_blank">1000 West Columbia Blvd<br />
                                                                            Ste 100<br />
                                                                Dearborn<br /> MI 45885</a>
    </div><!-- .left-side -->   
        <div class="center col">
            <h1 class="headline">Company name</h1>
            <span class="tagline">"Your one stop shop for all your auto needs."</span><br />
        </div><!-- center col -->
    <div class="right-side col">            
            Mon 8:30 am - 6:30 pm<br /> 
            Tue 8:30 am - 6:30 pm<br />     
            Wed 8:30 am - 6:30 pm<br />     
            Thu 8:30 am - 6:30 pm<br />     
            Fri 8:30 am - 6:30 pm<br />     
            Sat 8:30 am - 5:00 pm<br />     
            Sun Closed<br />    
    </div><!-- right-side col -->
</div><!--/.banner-->

<div class="pictures">
    <img class="item-1" src="img/frontOfBusiness.png" alt="Front of Business">
    <img class="item-2" src="img/logo.png" alt="Logo">
    <!-- <img class="item-3" src="img/interiorBay.png" alt="The interior bay">   -->
</div><!-- .pictures -->


<div class="row">   



    <div class="primary col">
        <h2>Welcome!</h2>


        <p>At Company name we pride ourselves in customer service and are always willing to go the extra mile to make our customers happy. Drop-ins are always welcome for our wide variety of auto care services. Stop in anytime and talk to our friendly techs about the top notch servicing we provide at a great price. Here at the 1 stop, EVERY SINGLE customer is valued and important to us.

.

</div><!--/.primary col-->
           <div class="secondary col">


  <h3>We offer:</h3>
            <ul>
                <li>10 Minute Oil Changes</li>
                <li>Transmission Services</li>
                <li>Coolant Services</li>
                <li>4x4 Servicing</li>
                <li>Power Steering Servicing</li>
                <li>Replacement of Air Filters, Wiper Blades & Light Bulbs</li>
                <li>Additive Services</li>
            </ul>   
    </div><!-- end .secondary col -->
    <div class="third col">
            <h3>Our specials include:</h3>
            <ul>
                <li>Everyday $19.95 oil change (up to 5qts, 5-30 and 10-30 weight only, standard canister oil filters only internals have fees)</li>
                <li>$69.95-$89.95 Transmission Service - beats any competitors price! </li>
                <li>$5 off any Valvoline Maxlife change</li>
                <li>$10 off any Valvoline Syn power change</li>
                <li>Multi-Service layered discounts, so the more services you combine, the more you save!</li>
            </ul>   
        </div><!-- end .third col-->
</div><!-- end .row -->

<footer class="main-footer">

<div class="fb-like" data-href="https://www.facebook.com/pages/Company name" data-width="50px" data-layout="button_count" data-action="like" data-show-faces="true" data-s  hare="true"></div>

    <div class="footer-inner">
        <span>&copy;2016 Oil Change.</span>
    </div>
</footer>

Here is the CSS

/* ================================= 
  Base Element Styles
==================================== */

* {
    box-sizing: border-box;
}
body {
    font-family: 'Varela Round', sans-serif;
    line-height: 1.6;
    color: #3a3a3a;
    margin: 0;
}
ul {
  margin: 0;
  padding: 0;
  list-style: none;
}
p {
    font-size: .95em;
}
h2,
h3,
a {
    color: #093a58;
}
h1,
h2,
h3 {
    margin-top: 0;
}
a {
    text-decoration: none;
}
img {
    max-width: 100%;
}

/* ================================= 
  Base Layout Styles
==================================== */

/* ---- Navigation ---- */

.name {
    font-size: 1.35em;
    margin: 0;
}
.main-nav {
    margin-top: 5px;
}
.name a,
.main-nav a {
    text-align: center;
    display: block;
    padding: 10px 15px;
}
.main-nav a {
    font-size: .95em;
    color: #243432;
    text-transform: uppercase;
}
.main-nav a:hover {
    color: #91aab6;
}

/* ---- Layout Containers ---- */

.main-header {
    padding-top: .35em;
    padding-bottom: .35em;
}

.banner,
.main-footer {
    text-align: center;
}

.banner {
    color: #fff;
    background: #130897;
    padding: 1em 0;
    margin-bottom: 24px;
}

.col {
    padding-right: 1em;
    padding-left: 1em;
}

.main-footer {
    background: #130897;
    padding: 2em 0;
    margin-top: 30px;
}




/* ---- Page Elements ---- */

.item-1,
.item-2,
.item-3 {
    width: auto;
    margin-top: 8px;
    margin-left: 20px;
    box-shadow: 10px 10px 5px #000;
}
.headline {
    margin-bottom: 0;
}
.feat-img {
    border-radius: 5px;
}

.footer-inner {
    color: #fff;
}

.col h2 {
    margin-top: 20px;
}

.col h3 {
    color: white;
}

.tagline {
    margin-top: 10px;
    font-style: italic;
}


.left-side a {
    color: white;
}

.left-side a:hover {
    color: red;
}


.map {
    float: left;
    margin-left: 150px;
}


.secondary h3,
.third h3 {
    color: black;
}

.secondary ul,
.third ul {
    list-style: disc;
    margin-left: 20px;
    padding-left: 20px;
}

.row {
    padding-top: 30px;
}


.fb-like {
    padding-bottom: 20px;
}

/* ================================= 
  Media Queries
==================================== */

@media (min-width: 769px) {

      body {
      display: flex;
      flex-direction: column;
      min-height: 100vh;
      }

    .main-header,
    .row,
    .footer-inner{
        width: 80%;
        margin: 0 auto;
        max-width: 1150px;
    }

    .tagline {
        font-size: 1.4em;
    }


.pictures {
    display: flex;
    flex-wrap: wrap;
    flex-direction: row;
    justify-content: center;
    width: auto;

    }

.row {
  display: flex;
  }

    .main-header,
    .main-nav,
    .banner {
        display: flex;
    }
/*

    .main-header {
        flex-direction: column;
        align-items: center;
    }

    /*
.banner {
        flex-direction: column;
        align-items: center;
        flex-wrap: wrap;
        flex-grow: 1;
    }
*/


    /*
.col {
        flex: 1 100%;
        justify-content: space-between;
    }
*/



}

@media (min-width: 880px) {

    .row {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
    }


    .col {
        flex: 1 50%;
        justify-content: space-between;
    }

@media (min-width: 1025px) {

    .main-header {
        flex-direction: row;
        justify-content: space-between;
    }

    .col {
        flex: 1 33%;
        justify-content: space-between;
    }

}



*/

Note that flexbox is supported by all major browsers, except IE 8 & 9 .

Some recent browser versions, such as Safari 8 and IE10, require vendor prefixes . This appears to be what you're missing.

For a quick way to add all the prefixes you need, post your CSS in the left panel here: Autoprefixer .

To Safari you need to write -webkit-flex, and to IE 10 - 11 you need to write -ms-flex.

You can read more about flex here: http://www.w3schools.com/cssref/css3_pr_flex.asp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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