簡體   English   中英

保持容器的寬度,最長的孩子的寬度

[英]Keep width of container that of the longest child

簡而言之:當我有一個容器和一些內聯塊div時,容器的寬度將圍繞div縮小。 但是,如果div太長,因此其中一個轉到另一行,則容器寬度將呈現為100%。

在圖片中,默認行為是第一個,而所需行為是第二​​個。

在此處輸入圖片說明

這是一個帶有示例的小提琴: http : //jsfiddle.net/gzbx4upq/

See fiddle for desired results

無論使用

display:block;

要么

display:inline;

要么

max-width:250px ;

使用偽類似乎可行。

CSS

div {
    display: inline;
    position: relative;
}
div:before {
    content:"";
    position: absolute;
    left: 0px;
    right: 0px;
    bottom: -5px;
    top: -5px;
    background-color: blue;
    z-index:-1;
}
div:after {
    content:"";
    display: block;
}
p {
    display: inline-block;
    background-color: red;
}

工作小提琴

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM