2016-11-15 57 views
0

將鼠標懸停在圖像上時,您會看到它將被文本塊替換。修復字體響應

當你收縮瀏覽器時,你會看到字體大小保持不變,儘管我在EM中指定它應該使字體響應。

我需要懸浮元素的佈局在移動視圖中保持不變,即我需要避免在縮小瀏覽器大小時出現的滾動條。任何想法如何實現這一目標?

/*Programs*/ 
 

 
ul.img-list { 
 
    list-style-type: none; 
 
    margin: 0; 
 
    padding: 0; 
 
    text-align: center; 
 
} 
 

 
ul.img-list li { 
 
    display: inline-block; 
 
    width: 100%; 
 
    height: 100%; 
 
    margin: 0; 
 
    position: relative; 
 
} 
 

 
div.text-content { 
 
    background: rgba(26,33,43,0.9); 
 
    color: white; 
 
    cursor: pointer; 
 
    left: 0; 
 
    position: absolute; 
 
    top: 0; 
 
    bottom: 0; 
 
    width: 100%; 
 
    height: 100%; 
 
    opacity: 0; 
 
    font-size: 1.250em; 
 
    font-family: Roboto; 
 
    line-height: 1em; 
 
    font-weight: 300; 
 
    text-align: center; 
 
    overflow-y: auto; 
 
    box-sizing: border-box; 
 
    padding-right: 25px; 
 
    padding-left: 25px; 
 
    padding-top: 25px; 
 
    padding-bottom: 25px; 
 
-webkit-transition: opacity 500ms; 
 
    -moz-transition: opacity 500ms; 
 
    -o-transition: opacity 500ms; 
 
    transition: opacity 500ms; 
 
    text-align: center; 
 
    vertical-align: middle; 
 
} 
 

 
ul.img-list li:hover div.text-content { 
 
    opacity: 1; 
 
} 
 

 
/* Events page */ 
 

 
/*Event link button*/ 
 

 
.btn { 
 
background-color: transparent; 
 
border-radius: 42px; 
 
border: 2px solid #ffffff; 
 
display: inline-block; 
 
cursor: pointer; 
 
font-family: Roboto; 
 
line-height: 1.750em; 
 
font-size: 1.500em; 
 
padding: 5px 15px 5px 15px; 
 
margin-right: 45px; 
 
margin-left: 45px; 
 
} 
 

 
.btn:link { 
 
    color: #ffffff; 
 
    text-decoration: none; 
 
} 
 

 
.btn:visited { 
 
    color: #1b1c16; 
 
    text-decoration: none; 
 
} 
 

 
.btn:hover { 
 
    background-color: #ffffff; 
 
    color: #1b1c16 !important; 
 
} 
 

 
.btn:active { 
 
    position: relative; 
 
\t top: 1px; 
 
} 
 

 
/*All events button*/ 
 

 
.evens_btn { 
 
background: ; 
 
} 
 

 
.events_btn>span{ 
 
color: #f9c70f; 
 
font-family: Roboto; 
 
color: #ffffff; 
 
font-size: 1.5em !important; 
 
background: ; 
 
text-decoration: none !important; 
 
padding: 10px 0px 10px 0px; 
 
} 
 

 
.events_btn>i{ 
 
color: #ffffff; 
 
margin-right: 15px; 
 
font-size: 3.125em; 
 
} 
 

 
.events_btn:link>i { 
 
    color: #f9c70f; 
 
} 
 

 
.events_btn:visited>i { 
 
    color: #ffffff; 
 
    text-decoration: none; 
 
} 
 

 
.events_btn:hover>i { 
 
color: #f9c70f; 
 
} 
 

 
.events_btn:active>i { 
 
    color: #f9c70f; 
 
} 
 

 
.events_btn:link>span { 
 
    color: #f9c70f; 
 
} 
 

 
.events_btn:visited>span { 
 
    color: #ffffff; 
 
    text-decoration: none; 
 
} 
 

 
.events_btn:hover>span { 
 
color: #f9c70f ; 
 
} 
 

 
.events_btn:active>span { 
 
    color: #f9c70f; 
 
}
<ul class="img-list"> 
 
    <li><img style="width: 100%; height: 100%;" src="http://www.sflsupport.org/wp-content/uploads/2016/06/Programs-11.jpg" />        
 
    <div class="text-content"> 
 
     <div> 
 
     <h5 style="color: white; font-size: 2.375em; font-family: Montserrat; font-weight: 600; line-height: 1em; letter-spacing: 0.125em;">WEBINAR<br/>ARCHIVE</h5> 
 
     <hr style="border-top: 0.125em solid #ffffff; width: auto; margin: 0.625em 1.875em;"/>Throughout the years SFL has ammased the library of recorded webinars from some of the leading libertarian voices about numerous topics in philosophy, politics, and economics. How can the government fix the higher education bubble? What is Ayn Rand's theory of natural rights? Tune in to our videos for answers to these questions and many more. 
 
     <br> 
 
     <a class="btn" style="color: white; text-align: center; margin-top: 0.625em; padding-top: 0.313em; padding-bottom: 0.313em; padding-left: 1.875em; padding-right: 1.875em; text-decoration: none; font-size: 1.500em; font-weight: 600; border: 3px solid white; letter-spacing: 0.125em;" href="http://www.google.com/" target="_blank">READ MORE</a> 
 
     </div> 
 
    </div> 
 
    </li> 
 
</ul>

+0

您可能需要檢查什麼是* EM *不僅僅是設置你的尺寸,並會有所反應......無論如何,你需要定義噸他斷點 – DaniP

回答

2

你可以簡單地設置字體大小vw而不是em

/*Programs*/ 
 

 
ul.img-list { 
 
    list-style-type: none; 
 
    margin: 0; 
 
    padding: 0; 
 
    text-align: center; 
 
} 
 

 
ul.img-list li { 
 
    display: inline-block; 
 
    width: 100%; 
 
    height: 100%; 
 
    margin: 0; 
 
    position: relative; 
 
} 
 

 
div.text-content { 
 
    background: rgba(26,33,43,0.9); 
 
    color: white; 
 
    cursor: pointer; 
 
    left: 0; 
 
    position: absolute; 
 
    top: 0; 
 
    bottom: 0; 
 
    width: 100%; 
 
    height: 100%; 
 
    opacity: 0; 
 
    font-size: 3vw; 
 
    font-family: Roboto; 
 
    line-height: 1em; 
 
    font-weight: 300; 
 
    text-align: center; 
 
    overflow-y: auto; 
 
    box-sizing: border-box; 
 
    padding-right: 25px; 
 
    padding-left: 25px; 
 
    padding-top: 25px; 
 
    padding-bottom: 25px; 
 
-webkit-transition: opacity 500ms; 
 
    -moz-transition: opacity 500ms; 
 
    -o-transition: opacity 500ms; 
 
    transition: opacity 500ms; 
 
    text-align: center; 
 
    vertical-align: middle; 
 
} 
 

 
ul.img-list li:hover div.text-content { 
 
    opacity: 1; 
 
} 
 

 
/* Events page */ 
 

 
/*Event link button*/ 
 

 
.btn { 
 
background-color: transparent; 
 
border-radius: 42px; 
 
border: 2px solid #ffffff; 
 
display: inline-block; 
 
cursor: pointer; 
 
font-family: Roboto; 
 
line-height: 1.750em; 
 
font-size: 1.500em; 
 
padding: 5px 15px 5px 15px; 
 
margin-right: 45px; 
 
margin-left: 45px; 
 
} 
 

 
.btn:link { 
 
    color: #ffffff; 
 
    text-decoration: none; 
 
} 
 

 
.btn:visited { 
 
    color: #1b1c16; 
 
    text-decoration: none; 
 
} 
 

 
.btn:hover { 
 
    background-color: #ffffff; 
 
    color: #1b1c16 !important; 
 
} 
 

 
.btn:active { 
 
    position: relative; 
 
\t top: 1px; 
 
} 
 

 
/*All events button*/ 
 

 
.evens_btn { 
 
background: ; 
 
} 
 

 
.events_btn>span{ 
 
color: #f9c70f; 
 
font-family: Roboto; 
 
color: #ffffff; 
 
font-size: 1.5em !important; 
 
background: ; 
 
text-decoration: none !important; 
 
padding: 10px 0px 10px 0px; 
 
} 
 

 
.events_btn>i{ 
 
color: #ffffff; 
 
margin-right: 15px; 
 
font-size: 3.125em; 
 
} 
 

 
.events_btn:link>i { 
 
    color: #f9c70f; 
 
} 
 

 
.events_btn:visited>i { 
 
    color: #ffffff; 
 
    text-decoration: none; 
 
} 
 

 
.events_btn:hover>i { 
 
color: #f9c70f; 
 
} 
 

 
.events_btn:active>i { 
 
    color: #f9c70f; 
 
} 
 

 
.events_btn:link>span { 
 
    color: #f9c70f; 
 
} 
 

 
.events_btn:visited>span { 
 
    color: #ffffff; 
 
    text-decoration: none; 
 
} 
 

 
.events_btn:hover>span { 
 
color: #f9c70f ; 
 
} 
 

 
.events_btn:active>span { 
 
    color: #f9c70f; 
 
}
<ul class="img-list"> 
 
    <li><img style="width: 100%; height: 100%;" src="http://www.sflsupport.org/wp-content/uploads/2016/06/Programs-11.jpg" />        
 
    <div class="text-content"> 
 
     <div> 
 
     <h5 style="color: white; font-size: 2.375em; font-family: Montserrat; font-weight: 600; line-height: 1em; letter-spacing: 0.125em;">WEBINAR<br/>ARCHIVE</h5> 
 
     <hr style="border-top: 0.125em solid #ffffff; width: auto; margin: 0.625em 1.875em;"/>Throughout the years SFL has ammased the library of recorded webinars from some of the leading libertarian voices about numerous topics in philosophy, politics, and economics. How can the government fix the higher education bubble? What is Ayn Rand's theory of natural rights? Tune in to our videos for answers to these questions and many more. 
 
     <br> 
 
     <a class="btn" style="color: white; text-align: center; margin-top: 0.625em; padding-top: 0.313em; padding-bottom: 0.313em; padding-left: 1.875em; padding-right: 1.875em; text-decoration: none; font-size: 1.500em; font-weight: 600; border: 3px solid white; letter-spacing: 0.125em;" href="http://www.google.com/" target="_blank">READ MORE</a> 
 
     </div> 
 
    </div> 
 
    </li> 
 
</ul>

+0

非常感謝!雖然,我不太明白你如何設定1.250em是3vw。你能解釋一下嗎,或者轉介給我一些文章? – Ira

+0

'em'和'vw'是完全不同的東西。 'em'與當前字體大小有關,並且不響應(它不隨調整窗口大小而改變)。 'vw'對於當前視口的1%是真實的,所以它肯定是響應式的。所以你不能轉換X'em' = Y'vw'。你的項目中的3vw只是我的建議,你可以改變它,但對我來說它看起來不錯;)你可以在這裏獲得更多關於'vw'的信息:https://css-tricks.com/viewport-sized-typography – Arkej