English 中文(简体)
停止将母子转成集体
原标题:stop div resizing parent div using css
  • 时间:2012-05-21 20:13:03
  •  标签:
  • css
  • resize

http://jsfiddle.net/ETkkR/

<div id="Blog1">
    <div class="post">
    <img src="http://dummyimage.com/180x120/000/fff" alt="Image 1" title="This is my first image"/>
        <div class="post-info">
            <span>post title post title post title</span>
        </div>
    </div>
    <div class="post">
    <img src="http://dummyimage.com/175x104/f0f/fff" alt="Image 2" title="The second one is pretty"/>
                <div class="post-info">
            <span>post title post title post title</span>
        </div>
    </div>        
</div>​

div.post-info, in some cases (images of width than the div.post-info content)fits div. 但是,有时是干 d的主食。 通过重新配置员额。 如何使post后info子适合parent子的 w子,如果更多的话,则不会再 res。

my css

#Blog1{
    padding:10px;
}
#Blog1 .post{
    border:1px solid #000000;
    margin:3px;
    text-align:center;
    position: relative;
    display: inline-block;
    *display: inline;
    zoom: 1
}
.post img{
    height:100px;
}
.post .post-info{
    text-align:left;
}
.post .post-info span{
    word-wrap:break-word;
}​

Edit

YOU CAN CHANGE THE ELEMENTS AS LONG AS THE CONTENT REMAINS SAME TO CREATE A SOLUTION people keep giving solutions which are not suitable for what i m asking...what i need is for the child div .post-info to not be a greater width than that of the .post parent div

最佳回答

这里是一句空话,但你应真正解释:,你希望高能变异?

<js Fiddle demo

CSS(仅改动内容):

#Blog1 .post{
    border:1px solid #000000;
    margin:3px;
    text-align:center;
    position: relative;
    display:block;         /**/
    float:left;            /**/
    overflow:hidden;       /**/
    padding-bottom:24px;   /**/
}
.post .post-info span{
    position:absolute;     /**/
    word-wrap:break-word;
} 

P.S: this question associates me to an old answer of mine :)
Pop Images like Google Images
If you need help ... I m here

问题回答

It seems to work with the following change to your CSS:

.post .post-info span{
    display: block;
    max-width: 90%;
    margin: 0 auto;
}​

JS Fiddle demo

Reasoning:

  • display: block; allows a width (and therefore max-width) to be assigned to the element.
  • max-width: 90%; to ensure that the element s maximum width is less than the width of the parent, allowing some space between the content of the element and the borders of the parent.
  • margin: 0 auto; horizontally centres the element within its parent.
#Blog1 .post{
    border:1px solid #000000;
    margin:3px;
    text-align:center;
    position: relative;
    display: inline-block;
    *display: inline;
    zoom: 1;
    max-width: 200px;
    overflow-x: hidden;
}

This solution will not however work in IE6 I think.

您可制定<条码>。

#Blog1 .post {
  width: 100%;
}

.post-info {
  width: 100%;
}

我认为,这将使其母体成为<代码>。

I had the same issue as the OP and the solution for me was to set

box-sizing: border-box;

我 could不敢在玩弄行为,但只是把上述行为补充到我所想的内在因素中,因此我希望能帮助某人。

处理这些不动产<代码> 最大程度





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

Drop down background url in Safari Issue

selectBox.selectCSS { background: url(/Images/replacementSelectBackground.png) top left no-repeat height:auto; } I have an issue in Safari only where the image is not rendering on top ...

CSS specific for Safari

How do you target specifically safari in css with styles?

Aligning textarea in a form

Ive used the following css code to align my form elements: form { position:relative; } form input { position:absolute; left:11em; } However, the textarea element is not aligned correctly with the ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

CSS problem with page footer

I have defined my page footer in the css file as: #footer { position: absolute; height: 50px; text-align: center; background: #66CCCC; bottom: 0px; left: 0px; width: 100%; height: ...

热门标签