April 24, 2012

Cut off effect with overflow:hidden

Question by Team-JoKi

I’d like to create the following in css:

I’ve a long text which should be displayed on a single line, and a hyperlink next to this text (this will later be placed in the header of the website, that’s why it needs to be a single line).

When the there is little room on the screen, I want the string to be cut off (“testtest..” – hyperlink). When the window is resized and there is more room, I want the text to be shown (as much as possible (e.g. “testtesttesttesttesttesttest.. – hyperlink”).

The problem that I’m having is that the string doesn’t want to be cut off. It always remains in its full size.

Here is a link to the JSFiddle: http://jsfiddle.net/PNGDw/1/

note: here I’m trying it with a table, I’ve also tried it with floats, but that didn’t work either.

Thanks for the help

Answer by Mark Schultheiss

You have a 5em width on the table so it will not resize. Use something like:

<style>
    *
    {
        margin: 0;
        padding: 0;
    }

    body
    {
        background: #5e8834;
    }

    div.wrapper        {
        background: #456326;
        border: 3px solid #547a2f;
        margin: 2em;
        width: 100%;
    }
    div.contents{    display:inline-block;}
    .should-cut-off 
    {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        width: 70%;
    }
</style>
<div id='wrapper'>
    <div class="should-cut-off contents">Test - test - test - Test - test - test - Test - test - test - Test - test - test
            - Test - test - test
    </div>
    <div class='contents' style="width:15%;">
        <a href="#">[this is a link]</a>
    </div>
</div>

Answer by Starx

Configure it to display as inline-block

.should-cut-off
{
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 70%;
    display: inline-block;
}

Demo

April 6, 2012

How do I make a overflow:scroll div have the same height of its container? Details inside

Question by Bror Bojlén

I have a website with two columns, within a wrapper div.

The wrapper has the same height as the tallest div by giving floating everything and giving the wrapper height:100%.

Here’s my problem: one of the columns is a div with overflow:scroll and several images in it. I tried to set its height to 100%, thinking that it would take up the full height of the wrapper. Instead, it became the height of all the images on top of each other.

If I set the height of the column with images (#rightbox) to a specific height in pixels, this happens.

I want it to have the same height as the other div with text, so I set its height to 100%. Then this happens.

How can I make the two columns have the same height?

EDIT: I forgot to mention that the amount of text varies, so I can’t define a specific height for the wrapper.

Answer by Starx

You cannot define height as 100% unless your parents provides an actual heights.

#wrapper {
   height: 800px;
}

/* Now you can make the columns inside take the full height of its parent *?
#wrapper .columns {
   height: 100%;
   overflow: auto;
}

Note: if the wrapper sits inside the body element then you will need to set html,body { height: 100%; } before the wrapper can be set to 100%

March 22, 2012

CSS DIV Overflow

Question by Devin

Site: http://partsconsign.com/parts/?custid=1

I don’t know what happened. All of a sudden, without changing the css, when I expand the “browse” categories, they overflow outside of the containing divs. Here is the css of the divs:

.bodyArea
{
    width: 900px;
    background-image:url(/images/bg.jpg);
    background-repeat:no-repeat;
    border-width: thin;
    border-style: solid;
    margin-left:auto;
    margin-right:auto;
    -moz-border-radius: 8px;
    border-radius: 8px;
    min-height: 900px;
}

.pageArea
{
    background-image: url(../images/page_bg.jpg);
    background-repeat: repeat;
    width: 95%;
    position:relative;
    margin-left: 25px;
    margin-top: 30px;
    min-height: 700px;
    height:auto;
}

#partCat {
    width: 775px;
    padding:5px;
    cursor:pointer;
}

I don’t see why expanding these divs would cause any kind of overflow. None of these divs have any absolute positioning. What am I doing wrong? #partcat is within .pageArea, which is within .bodyArea. I’ve looked through many questions asked previous here, but all of them seem to have slightly different issues. Help!

Answer by Starx

You div is fixed on 30px height. Remove the height from this part

<div style="height: 30px; width: 100%">

Tested through the firebug, IT WORKS

March 1, 2012

setting overflow hides li bullets (overflow property conflict with list-style)

Question by missybecks

setting overflow and text-overflow property makes the li hide bullets. I’ve tried putting the bullets “inside” but it still didn’t show bullets. Plus I’d prefer to put it “outside”

ul.hbox_poplist {
    list-style: circle url('/img/bpt_clear.png');
}

ul.hbox_poplist li {
    margin: 0 0 8px;
    max-height:32px;
    text-overflow: ellipsis;
    overflow-y: hidden;
}

does anyone know any solution to this?

Answer by Diodeus

Using a CSS background is much more dependable across browsers than using list-style-image for custom bullets. Controlling the position of a list-image is quite difficult on its own.

Something like:

.bullets {
  background-image:url(/img/bpt_clear.png); 
  background-repeat:no-repeat; 
  padding-left:30px; 
  margin-left:-30px;
}

See: http://preview.moveable.com/JM/ilovelists/

Answer by Starx

I remember this problem long before. Yes, its better to follow to what @Diodeus suggests, but adding padding-left to the ul, miraculously solved my problem a couple of times.

...

Please fill the form - I will response as fast as I can!