Media queries with css3 and @font face

时间:2016-10-20 13:12:07

标签: css3 font-face

I'm trying to have the 4 icon fonts (above call, email, studio and hours texts) to scale based on the size of the screen. (my website - scroll below slider

I've been successful in making the text scale, but not the icon fonts.

Here is the code I am currently using (sourced from https://colorlib.com/wp/font-face-inside-media-query/):

 @media screen and (max-width: 299px) {
   @font-face {
    font-family: 'debssite';
    src: url('./fonts/debssite.svg?#debssite') format('svg');
font-size: 10vw;
}

@media screen and (min-width: 300px) and (max-width: 799px) {
    @font-face {
    font-family: 'debssite';
    src: url('fonts/debssite.eot');
    src: url('fonts/debssite.eot?#iefix') format('embedded-opentype'),
    url('fonts/debssite.woff2?') format('woff2'),
    url('fonts/debssite.woff?') format('woff'),
    url('fonts/debssite.ttf?') format('truetype'),
    url('fonts/debssite.svg?') format('svg');
    font-weight: normal;
    font-style: normal;
font-size: 10px;
    }

p{
font-size: 10vw;}
}

@media screen and (min-width: 800px) {
   @font-face {
    font-family: 'debssite';
    src: url('./fonts/debssite.svg?#debssite') format('svg');
        font-size: 2px;
    }
}

My original code comes from this code block:

/********************
Icon Fonts To Use
********************/


@font-face {
    font-family: 'debssite';
    src: url('fonts/debssite.eot');
    src: url('fonts/debssite.eot?#iefix') format('embedded-opentype'),
    url('fonts/debssite.woff2?') format('woff2'),
    url('fonts/debssite.woff?') format('woff'),
    url('fonts/debssite.ttf?') format('truetype'),
    url('fonts/debssite.svg?') format('svg');
    font-weight: normal;
    font-style: normal;
}
/* Chrome hack: SVG is rendered more smooth in Windozze. 100% magic, uncomment if you need it. */
/* Note, that will break hinting! In other OS-es font will be not as sharp as it could be */
/*
@media screen and (-webkit-min-device-pixel-ratio:0) {
  @font-face {
    font-family: 'debssite';
    src: url('./fonts/debssite.svg?#debssite') format('svg');
  }
}
*/

[class^="icon-"]:before, 
[class*=" icon-"]:before {
    font-family: "debssite";
    font-style: normal;
    font-weight: normal;
    speak: none;

    display: inline-block;
    text-decoration: inherit;
    width: 1em;
    margin-right: .2em;
    text-align: center;
    /* opacity: .8; */

    /* For safety - reset parent styles, that can break glyph codes*/
    font-variant: normal;
    text-transform: none;

    /* fix buttons height, for twitter bootstrap */
    line-height: 1em;

    /* Animation center compensation - margins should be symmetric */
    /* remove if not needed */
    margin-left: .2em;

    /* you can be more comfortable with increased icons size */
    /* font-size: 120%; */

    /* Font smoothing. That was taken from TWBS */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;

    /* Uncomment for 3D effect */
    /* text-shadow: 1px 1px 1px rgba(127, 127, 127, 0.3); */
}

.icon-calendar:before { 
    content: "\e800"; 
    font-size: 64px;
    color: #b31b1b;
} 
.icon-location:before { 
    content: "\e801"; 
    font-size: 64px;
    color: #b31b1b;
} 
.icon-mail:before { 
    content: "\e802"; 
    font-size: 64px;
    color: #b31b1b;
} 
.icon-facebook:before { 
    content: "\f09a"; 
    font-size: 32px;
    color: #b31b1b;
    margin-right 4%;
} 
.icon-mobile:before { 
    content: "\f10b"; 
    font-size: 64px;
    color: #b31b1b;
    margin:0px;
} 
.icon-youtube:before { 
    content: "\f167"; 
    font-size: 32px;
    color: #b31b1b;
    margin-right 4%;
} 
.icon-instagram:before { 
    content: "\f16d"; 
    font-size: 32px;
    color: #b31b1b;
    margin-right 4%;
} 
.icon-pinterest:before { 
    content: "\f231"; 
    font-size: 32px;
    color: #b31b1b;
    margin:10px;
}
/**********************/

I'd really appreciate any advice/help.

Thank you

************Edit**************

Trying Nathalia's suggestion, I decided to add colour changes to each field:

    @media screen and (max-width: 299px) {
    .icon-calendar {
    font-size: 10vw;
    color: #0000ff; 
    }
}

@media screen and (min-width: 300px) and (max-width: 799px) {
    .icon-mobile, .caption{
        font-size: 10vw;
        color: #00ff00;
    }   
    p {font-size: 10vw;
        color: #3ef43e;
    }  
}

@media screen and (min-width: 800px) {
    .icon-mail, .item {
        font-size: 2vw;
        color: #551a8b;
    }
}

The colour changes only fire off on the classes ".item" and ".caption" and only affect the text and not the icons. Here is now my HTML is set up:

<div class="item"> 
<span class = "icon-mobile"></span>
<span class="caption">Call</span>
</div> 

<div class="item"> 
<span class = "icon-mail"></span> 
<span class="caption">Email</span> 
</div> 

<div class="item"> 
<span class = "icon-location"></span> 
<span class="caption">Studio</span> 
</div>

 <div class="item"> 
<span class = "icon-calendar"></span> 
<span class="caption">Hours</span> 
</div>

And here is how I styled them in CSS (using the class "contact_details"):

/**********************
Contact Icon Fonts
**********************/

/*Icon Fonts*/

.contact_details{
    text-align: center;
}

.item {
    vertical-align: top;
    display: inline-block;
    width:auto;
    height:auto;
    margin:0% auto; 
    color: #b31b1b;
}

/* Text Below Icon Fonts*/

.caption {
    display: block;
    text-align: center;
}
/**********************/

I'm clueless as to why the icons do not change but the captions do. Should they have separate classes?

2 个答案:

答案 0 :(得分:2)

您应该使用@ font-face导入字体,而不是设置其大小。您也可以将@ font-face置于媒体查询之外。然后,使用带有选择器的媒体查询(.entry-content .item span)来设置字体大小。试试这个:

@font-face {
    font-family: 'debssite';
    src: url('fonts/debssite.eot');
    src: url('fonts/debssite.eot?#iefix') format('embedded-opentype'),
    url('fonts/debssite.woff2?') format('woff2'),
    url('fonts/debssite.woff?') format('woff'),
    url('fonts/debssite.ttf?') format('truetype'),
    url('fonts/debssite.svg?') format('svg');
    font-weight: normal;
    font-style: normal;
}
 @media screen and (max-width: 299px) {
    .entry-content .item span { font-size: 10vw;}
}

@media screen and (min-width: 300px) and (max-width: 799px) {
    .entry-content .item span { font-size: 10px;}
    p{ font-size: 10vw;}
}

@media screen and (min-width: 800px) {
    .entry-content .item span { font-size: 2px;}
    p {font-size: 10vw;}
}

答案 1 :(得分:1)

解决!谢谢你Nathalia(赞成你),我需要引用我的字体,因为它们最初设置(出于某种原因?)与&#34;:之前&#34;后缀;如:

@media screen and (max-width: 299px) {
    .icon-calendar:before {
    font-size: 10vw;
    color: #0000ff; 
    }
}

@media screen and (min-width: 300px) and (max-width: 799px) {
    .icon-mobile:before, .caption{
        font-size: 10vw;
        color: #00ff00;
    }   
    p {font-size: 10vw;
        color: #3ef43e;
    }  
}

@media screen and (min-width: 800px) {
    .icon-mail:before, .item {
        font-size: 2vw;
        color: #551a8b;
    }
}