html - CSS div 在缩小时缩小

标签 html css css-float

我正在为我网站的面包屑使用一个 div。它在浏览器窗口的实际大小和放大时保持恒定大小。但在缩小时 div 正在缩小。

这是我正在使用的代码。我需要在某处进行编辑吗?

    <style>

.breadcrumb { 
        list-style: none; 
        overflow: hidden; 
        font: 18px Lucida Sans Unicode;
        text-align: center;
}
.breadcrumb li { 
        float: left;

}
.breadcrumb li a {
        color: white;
        text-decoration: none; 
        padding: 11px 0 11px 55px;
        background:  #327ea4;                   /* fallback color */
        background:  #327ea4; 
        position: relative; 
        display: block;
        float: left;
        width: 15.12em;
        /*width: 15.1185em;*/
        cursor: default;
        border-top-left-radius: .4em;
        pointer-events: none;
}
.breadcrumb li a:after { 
        content: " "; 
        display: block; 
        width: 0; 
        height: 0;
        border-top: 50px solid transparent;           /* Go big on the size, and let overflow hide */
        border-bottom: 50px solid transparent;
        border-left: 30px solid  #327ea4;
        position: absolute;
        top: 50%;
        margin-top: -50px; 
        left: 100%;
        z-index: 2; 
}   
.breadcrumb li a:before { 
        content: " "; 
        display: block; 
        width: 0; 
        height: 0;
        border-top: 50px solid transparent;           /* Go big on the size, and let overflow hide */
        border-bottom: 50px solid transparent;
        border-left: 30px solid white;
        position: absolute;
        top: 50%;
        margin-top: -50px; 
        margin-left: 1px;
        left: 100%;
        z-index: 1; 
}   
.breadcrumb li:first-child a {
        padding-left: 30px;
}
.breadcrumb li:nth-child(2) a       { background:        #7fc1ec; color: #327ea4; cursor: default;}
.breadcrumb li:nth-child(2) a:after { border-left-color: #7fc1ec; color: #327ea4; cursor: default;}
.breadcrumb li:nth-child(3) a       { background:        #7fc1ec; color: #327ea4; cursor: default;}
.breadcrumb li:nth-child(3) a:after { border-left-color: #7fc1ec; color: #327ea4; cursor: default;}
.breadcrumb li:nth-child(4) a       { background:        #7fc1ec; color: #327ea4; cursor: default;}
.breadcrumb li:nth-child(4) a:after { border-left-color: #7fc1ec; color: #327ea4; cursor: default; }
.breadcrumb li:last-child a {
        /*background: white !important;*/
        /*color: black;*/
        pointer-events: none;
        cursor: default;
        border-top-right-radius: .4em;
}
.breadcrumb li:last-child a:after { border: 0; }
    </style>

<div style="width:75em;" oncontextmenu="return false"  >
    <ul class="breadcrumb">
        <li><a href="#">Step 1</a></li>
        <li><a href="#">Step 2</a></li>
        <li><a href="#">Step 3</a></li>
                    <li><a href="#">Step 4</a></li>
    </ul>

</div>

提前致谢。

最佳答案

当您在 EM 中定义元素的高度或宽度时,如以下代码片段...

.breadcrumb li a {
        color: white;
        text-decoration: none; 
        padding: 11px 0 11px 55px;
        background:  #327ea4;
        background:  #327ea4; 
        position: relative; 
        display: block;
        float: left;
        width: 15.12em; /* <-- RIGHT HERE */
        cursor: default;
        border-top-left-radius: .4em;
        pointer-events: none;
}

...您实际上是将元素的大小绑定(bind)到该元素的字体大小。

当您增加浏览器“缩放”时,所发生的一切都是在增加字体大小(以像素为单位)。

例子:

font-size: 10px,因此 width: 2em == width: 20px

缩放(增加字体大小)

font-size: 12px,因此 width: 2em == width: 24px

关于html - CSS div 在缩小时缩小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16198766/

相关文章:

html - 带有 float :right or similar 的 IE 中的 css 错误

javascript - 使用目标 href 参数创建一个函数

html - Web 元素的命名约定

html - CSS:四个div动态共享父级的高度

css - 在不影响文本或页面外观的情况下扩大文本链接热点?

css - 左边距在溢出时不起作用 :auto element following the float

html - 所有分辨率的 CSS 元素定位

javascript - 如何在窗口 Canvas 中制作移动图像的效果?

链接到另一个 html 的 html

HTML水平导航菜单