我有一個名爲「nav」的父級div容器,充當導航欄以及作爲選擇的子div。我如何使一個容器內的div有一個像其他div的兄弟姐妹一樣大小的圖像?
問題:我想有一個圖像一路左側,在這個導航欄內。然而,它只是不顯示(沒有寬度),除非我讓div「logo」具有固定的寬度和高度。當我這樣做時,圖像不會適當地重新調整大小以適應div內部。我只看到圖像的一部分。另外我想div /圖像相對於div「名稱」的大小進行縮放,而不是相反。作爲一個例子給div「標誌」一個100px的寬度/高度,並且看到它改變了div「nav」的大小。圖像應重新調整到與div「名稱」相同的高度。如果div「name」的高度爲30px,那麼div「logo」的寬度和高度應爲30px(給出或佔用像素)。
我該怎麼做? div有可能嗎?如果不是最接近的方式,我可以做到這一點(我寧願使用div)?
代碼:http://jsfiddle.net/x3f63cye/3/
html, body {
height: 100%;
margin: 0px;
font-family:'Myriad Pro Regular';
color:#1E3264;
}
.flexer {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
}
div#nav {
position:relative;
width:100%;
background: white;
box-shadow: 0px 0px 3px 1px #888888;
}
div#logo {
background-size:contain;
background: url('https://lh5.googleusercontent.com/-SnVrCsddc7c/AAAAAAAAAAI/AAAAAAAAAEM/v3eM1AEdb70/photo.jpg') center center no-repeat;
border-right-style:solid;
border-width:1px;
border-color: rgba(0, 0, 0, 0.15);
}
div#name {
padding: 0% 5% 0% 5%;
border-right-style:solid;
border-width:1px;
border-color: rgba(0, 0, 0, 0.15);
font-size:2em;
align-items:center;
justify-content: center;
}
<div id="nav" class="flexer">
<div id="logo" class="flexer"></div>
<div id="name" class="flexer">Choice1</div>
</div>