我在网页中使用bootstrap。现在我想达到一个特殊的效果。我有一个div类,名称为“container-fluid”,h2标签下有一个文本。如下所示:
<div class="container-fluid" style="background-color: #f8f8f8;text-align: center;height: 76px;">
<br>
<h2 id="mesheading" style="color: #a76281; font-size: 14px; cursor: pointer; margin-top: -4px; font-family: 'brandon_grotesquebold'; text-transform: uppercase; letter-spacing: 2px;">
Helping manufacturers save 20%-30% of the store cost
<span>
<button class="button_one" type="button" onclick="open_win_two()">
LEARN MORE
</button>
</span>
</h2><br>
</div>
我的要求是当浏览器窗口折叠时,h2标签的字体大小会变小。例如,它将变为10px。
在扩展浏览器窗口的实际大小时,它将恢复到原来的字体大小,即14px
我已经做了很多关于jQuery的崩溃相关事件的研究。但它没有帮助我。
所以请帮助我实现这个目标。
提前致谢!!!
答案 0 :(得分:0)
您应该使用媒体查询的默认断点,如下所示:
<强> CSS 强>
/* Extra Small Devices, Phones */
@media only screen and (min-width : 480px) {
.container-fluid h2 {
your font size
}
}
/* Small Devices, Tablets */
@media only screen and (min-width : 768px) {
.container-fluid h2 {
font-size: 10px;
}
}
/* Medium Devices, Desktops */
@media only screen and (min-width : 992px) {
.container-fluid h2 {
your font size
}
}
/* Large Devices, Wide Screens */
@media only screen and (min-width : 1200px) {
.container-fluid h2 {
your font size
}
}
答案 1 :(得分:0)
<强>问题强>
根据屏幕尺寸更改元素上的css。
<强>解决方案强>
您可以使用媒体查询来更改h2
或任何元素的字体大小。
<强>实施例强>
使用此媒体查询为您在查询中提供的两个宽度之间的任何内容设置条件。您可以通过更改min
和max
width
的宽度来重复使用此功能来创建多个方案。
@media only screen and (min-device-width: 481px) and (max-device-width: 1024px) {
.container-fluid h2 {
font-size: 10px;
}
}
然后,在媒体查询之外,您可以将此作为任何不属于任何media queries
条件的默认值。
.container-fluid h2 {
font-size: 14px;
}
定位特定设备
以下是一些针对常用设备的常见必要媒体查询。
/* Smartphones (portrait and landscape) ----------- */
@media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
@media only screen and (min-width : 321px) {
/* Styles */
}
/* Smartphones (portrait) ----------- */
@media only screen and (max-width : 320px) {
/* Styles */
}
/* iPads (portrait and landscape) ----------- */
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) {
/* Styles */
}
/* iPads (landscape) ----------- */
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) {
/* Styles */
}
/* iPads (portrait) ----------- */
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) {
/* Styles */
}
/**********
iPad 3
**********/
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) and (-webkit-min-device-pixel-ratio : 2) {
/* Styles */
}
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) and (-webkit-min-device-pixel-ratio : 2) {
/* Styles */
}
/* Desktops and laptops ----------- */
@media only screen and (min-width : 1224px) {
/* Styles */
}
/* Large screens ----------- */
@media only screen and (min-width : 1824px) {
/* Styles */
}
/* iPhone 4 ----------- */
@media only screen and (min-device-width : 320px) and (max-device-width : 480px) and (orientation : landscape) and (-webkit-min-device-pixel-ratio : 2) {
/* Styles */
}
@media only screen and (min-device-width : 320px) and (max-device-width : 480px) and (orientation : portrait) and (-webkit-min-device-pixel-ratio : 2) {
/* Styles */
}
/* iPhone 5 ----------- */
@media only screen and (min-device-width: 320px) and (max-device-height: 568px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}
@media only screen and (min-device-width: 320px) and (max-device-height: 568px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}
/* iPhone 6 ----------- */
@media only screen and (min-device-width: 375px) and (max-device-height: 667px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}
@media only screen and (min-device-width: 375px) and (max-device-height: 667px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}
/* iPhone 6+ ----------- */
@media only screen and (min-device-width: 414px) and (max-device-height: 736px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}
@media only screen and (min-device-width: 414px) and (max-device-height: 736px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}
/* Samsung Galaxy S3 ----------- */
@media only screen and (min-device-width: 320px) and (max-device-height: 640px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}
@media only screen and (min-device-width: 320px) and (max-device-height: 640px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){
/* Styles */
}
/* Samsung Galaxy S4 ----------- */
@media only screen and (min-device-width: 320px) and (max-device-height: 640px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 3){
/* Styles */
}
@media only screen and (min-device-width: 320px) and (max-device-height: 640px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 3){
/* Styles */
}
/* Samsung Galaxy S5 ----------- */
@media only screen and (min-device-width: 360px) and (max-device-height: 640px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 3){
/* Styles */
}
@media only screen and (min-device-width: 360px) and (max-device-height: 640px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 3){
/* Styles */
}