如何让我的 div 动态缩小,而不隐藏某些内容?
How to make my div's shrink dynamically, and not hide certain content?
我不太清楚如何表达我的要求。我对 CSS 还是很陌生。
这里有一些图片来解释:
这是我网站的导航栏在全尺寸下的样子。
https://dl.dropboxusercontent.com/u/16240136/stackoverflw/fullsize.png
左边是最小的样子,
在右边,我们有我想要它最小的样子。
https://dl.dropboxusercontent.com/u/16240136/stackoverflw/smallest.png
基本上,我希望那些导航链接开始消失,但我不希望 zxci 文本消失。还要注意导航链接是如何向右移动的。不过,我认为这可能是保证金?
我尝试将 .navlinks 设置为显示内联块,但这对我来说没有任何改变。不知道该怎么做。
这是我的 HTML 和 CSS.. 我将背景颜色更改为灰色以便可以看到对比度,因为背景图像不可用
@charset "utf-8";
body {
background-color: #a8a8a8;
background-position: 50% 45px;
background-repeat: no-repeat;
background-image: url(assets/dark-bg.jpg);
width: 100%;
height: 100%;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 0px;
padding-top: 0px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 0px;
}
* {
margin: 0;
padding: 0;
}
div .contentBox {
width: 100%;
background-color: rgba(0,0,0,0.3);
margin-bottom: 30px;
}
div .navSpan {
top: 0px;
left: 0px;
position: fixed;
width: 100%;
height: 45px;
}
div .navLinks {
height: 45px;
float: left;
display: inline;
min-width: 300px;
overflow-x: hidden;
overflow-y: hidden;
}
div .navLinks p {
margin-left: 23px;
margin-right: 15px;
color: #0066CC;
font-variant: small-caps;
font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
display: inline;
font-weight: bolder;
float: left;
padding-top: 18px;
}
div .navContainer span{
color: #CCCCCC;
font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
font-variant: small-caps;
font-weight: bold;
font-size: xx-large;
-webkit-transition: all .2s ease-in 0s;
-moz-transition: all .2s ease-in 0s;
-ms-transition: all .2s ease-in 0s;
-o-transition: all .2s ease-in 0s;
transition: all .2s ease-in 0s;
display: inline;
float: right;
}
div .navLinks a {
border-bottom-width: thin;
border-bottom-style: solid;
}
div .navContainer {
margin-left: auto;
margin-right: auto;
margin-bottom: 40px;
width: 50%;
min-width: 300px;
height: 45px;
overflow-y: hidden;
overflow-x: hidden;
}
.container {
margin-left: auto;
margin-right: auto;
width: 50%;
height: 100%;
margin-bottom: 40px;
margin-top: 0px;
min-width: 350px;
}
.content {
color: #0066CC;
font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
opacity: 1;
padding-top: 25px;
padding-left: 15px;
padding-right: 15px;
padding-bottom: 15px;
}
a:hover {
color: #0099CC;
text-decoration: none;
}
}
div .contentHeader {
width: 100%;
display: inline;
}
.backbtn {
font-style: normal;
font-variant: normal;
font-weight: normal;
font-size: x-large;
right: 10.px;
display: inline;
text-align: right;
float: right;
padding-top: 10px;
border-style: none;
}
.content img {
max-width: 100%;
max-height: 100%;
width: auto;
height: auto;
}
<body>
<div class="navSpan" style="background-color:#000">
<div class="navContainer">
<div class="navLinks">
<p><a href="index.html">Home</a></p>
<p>Empty</p>
<p>Empty</p>
<p>Empty</p>
<p>Empty</p>
<p>Empty</p>
</div> <!-- navLinks end -->
<span class="zxci">ZXCi</span>
</div> <!-- navContainer end -->
</div> <!-- navBarFull end -->
<div class="container">
<div class="contentBox">
<div class="content">
<center>Site is still under construction. Sorry!</center>
</div> <!-- content end -->
</div> <!-- contentBox end -->
<div class="contentBox">
<div class="content">
<center>
<img src="assets/falloutboy-picture.png" alt="falloutboy"/>
</center>
</div> <!-- content end -->
</div> <!-- contentBox end -->
</div> <!-- container end -->
</body>
</html>
好吧,没关系!我找到了解决方案。我相信这是相对简单的事情。
.navLinks 现在只有 overflow: hidden
.navLinks p 现在包含位置:相对和浮动:左。
.navContainer span 现在只包含 float: right
我推断 "ZXCi" 被隐藏的原因是它出现在 float: left 元素之后。因此,当屏幕调整大小时,它是第一个看到的需要隐藏的东西,并且被隐藏了。因此,通过将它移动到导航容器中的所有内容之前,它现在是最后要剪切的东西(并且最终不会被最小宽度剪切)。
我不确定为什么,但它拒绝对齐到我的导航栏容器的最右侧 div。我正在摆弄设置,不小心偶然发现了一个工作配置。考虑到应用的设置很少,我认为这是一个很好的设置。
我的猜测是某处存在一些格式设置冲突。我不知道。不过,它现在就像一个魅力。 (此外,调整大小时出现的奇怪间隙实际上是边距,而且我的导航栏容器的宽度设置为大于其他容器的宽度)
我不太清楚如何表达我的要求。我对 CSS 还是很陌生。
这里有一些图片来解释: 这是我网站的导航栏在全尺寸下的样子。 https://dl.dropboxusercontent.com/u/16240136/stackoverflw/fullsize.png
左边是最小的样子, 在右边,我们有我想要它最小的样子。 https://dl.dropboxusercontent.com/u/16240136/stackoverflw/smallest.png
基本上,我希望那些导航链接开始消失,但我不希望 zxci 文本消失。还要注意导航链接是如何向右移动的。不过,我认为这可能是保证金?
我尝试将 .navlinks 设置为显示内联块,但这对我来说没有任何改变。不知道该怎么做。
这是我的 HTML 和 CSS.. 我将背景颜色更改为灰色以便可以看到对比度,因为背景图像不可用
@charset "utf-8";
body {
background-color: #a8a8a8;
background-position: 50% 45px;
background-repeat: no-repeat;
background-image: url(assets/dark-bg.jpg);
width: 100%;
height: 100%;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 0px;
padding-top: 0px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 0px;
}
* {
margin: 0;
padding: 0;
}
div .contentBox {
width: 100%;
background-color: rgba(0,0,0,0.3);
margin-bottom: 30px;
}
div .navSpan {
top: 0px;
left: 0px;
position: fixed;
width: 100%;
height: 45px;
}
div .navLinks {
height: 45px;
float: left;
display: inline;
min-width: 300px;
overflow-x: hidden;
overflow-y: hidden;
}
div .navLinks p {
margin-left: 23px;
margin-right: 15px;
color: #0066CC;
font-variant: small-caps;
font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
display: inline;
font-weight: bolder;
float: left;
padding-top: 18px;
}
div .navContainer span{
color: #CCCCCC;
font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
font-variant: small-caps;
font-weight: bold;
font-size: xx-large;
-webkit-transition: all .2s ease-in 0s;
-moz-transition: all .2s ease-in 0s;
-ms-transition: all .2s ease-in 0s;
-o-transition: all .2s ease-in 0s;
transition: all .2s ease-in 0s;
display: inline;
float: right;
}
div .navLinks a {
border-bottom-width: thin;
border-bottom-style: solid;
}
div .navContainer {
margin-left: auto;
margin-right: auto;
margin-bottom: 40px;
width: 50%;
min-width: 300px;
height: 45px;
overflow-y: hidden;
overflow-x: hidden;
}
.container {
margin-left: auto;
margin-right: auto;
width: 50%;
height: 100%;
margin-bottom: 40px;
margin-top: 0px;
min-width: 350px;
}
.content {
color: #0066CC;
font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
opacity: 1;
padding-top: 25px;
padding-left: 15px;
padding-right: 15px;
padding-bottom: 15px;
}
a:hover {
color: #0099CC;
text-decoration: none;
}
}
div .contentHeader {
width: 100%;
display: inline;
}
.backbtn {
font-style: normal;
font-variant: normal;
font-weight: normal;
font-size: x-large;
right: 10.px;
display: inline;
text-align: right;
float: right;
padding-top: 10px;
border-style: none;
}
.content img {
max-width: 100%;
max-height: 100%;
width: auto;
height: auto;
}
<body>
<div class="navSpan" style="background-color:#000">
<div class="navContainer">
<div class="navLinks">
<p><a href="index.html">Home</a></p>
<p>Empty</p>
<p>Empty</p>
<p>Empty</p>
<p>Empty</p>
<p>Empty</p>
</div> <!-- navLinks end -->
<span class="zxci">ZXCi</span>
</div> <!-- navContainer end -->
</div> <!-- navBarFull end -->
<div class="container">
<div class="contentBox">
<div class="content">
<center>Site is still under construction. Sorry!</center>
</div> <!-- content end -->
</div> <!-- contentBox end -->
<div class="contentBox">
<div class="content">
<center>
<img src="assets/falloutboy-picture.png" alt="falloutboy"/>
</center>
</div> <!-- content end -->
</div> <!-- contentBox end -->
</div> <!-- container end -->
</body>
</html>
好吧,没关系!我找到了解决方案。我相信这是相对简单的事情。
.navLinks 现在只有 overflow: hidden
.navLinks p 现在包含位置:相对和浮动:左。
.navContainer span 现在只包含 float: right
我推断 "ZXCi" 被隐藏的原因是它出现在 float: left 元素之后。因此,当屏幕调整大小时,它是第一个看到的需要隐藏的东西,并且被隐藏了。因此,通过将它移动到导航容器中的所有内容之前,它现在是最后要剪切的东西(并且最终不会被最小宽度剪切)。
我不确定为什么,但它拒绝对齐到我的导航栏容器的最右侧 div。我正在摆弄设置,不小心偶然发现了一个工作配置。考虑到应用的设置很少,我认为这是一个很好的设置。
我的猜测是某处存在一些格式设置冲突。我不知道。不过,它现在就像一个魅力。 (此外,调整大小时出现的奇怪间隙实际上是边距,而且我的导航栏容器的宽度设置为大于其他容器的宽度)