Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

DIV wrapping problem

Featured Replies

Hey all,

 

Im getting annoyed with some divs and would love so help :)

I cant show you the webpage as its PW protected but here is an example:

 

html

<div id="tableholder">

<div id="box1">Some Text</div>
<div id="box2">Some more Text</div>

</div>

 

css

#tableholder {width:100%; height:auto;}
#box1 {width:50%;height:30px; float:left; display:inline;}
#box2 {width:500px;height:30px; float:left; display:inline;}

 

okay, so I have 2 boxes next to each other, with abit of text in it.

 

What I want to happen is this:

 

As the window resizes - smaller - I want box 2 to say the same width no matter what. However when box2 gets so far left it starts to overlap box one, I want box1 to say the SAME height, but the width of it gets smaller.

 

So as box2 overlaps the text in box1, the box1 text doesnt drop down (so the div gets bigger), it sort of cuts the text off. So like : "Some Te.."

 

Sorry for the waffle, hopefull you understand what I mean! :D

I don't know about getting box2 to overlap box1, but I can help you with stopping the height from changing on box1. Use overflow:hidden. The box will stay the same height, but as the box's width reduces, it will drop and chop the text off and out of visiblity. You could add min-width:300px; for example to stop box1 from being squished to far. Of course, change the number to your needs.

 

Hope this helps.

  • Author

Nice one, here is an example of what I mean :)

 

http://elliothesp.co.uk/test/

 

Now you see they are all in a line, when you resize the window the yellow box drops below, which I dont want... Instead I want it to make the blue box shrink, but when it gets to the text it makes the text cut off:

 

"SOME MORE TEXT THAT I WA..."

 

Like that.

 

Although it just wont stay on that one line :(

HTML

<div id="tableholder">
<div id="box1">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam quis erat quis metus condimentum elementum. Nam sagittis enim ut mi vehicula pulvinar rutrum augue vulputate. Suspendisse potenti. Proin ut nulla non ipsum elementum suscipit. Phasellus interdum, est placerat faucibus molestie, risus justo blandit urna, vitae luctus odio tellus vel lorem. Nullam a est eget purus scelerisque euismod ut quis eros. Vivamus eu lectus felis. Nam sit amet nibh et mi tempus consequat. Duis quis velit metus, in pulvinar sapien. Integer id mattis orci. Fusce condimentum ante nec purus varius sollicitudin et at tortor. Aenean malesuada ante convallis tellus tempus vel malesuada justo sodales. Integer tempus dolor erat, eu ullamcorper felis. Vivamus diam libero, viverra quis vehicula eu, volutpat sed tellus. Donec ut neque vitae lectus dictum congue. Praesent ut nulla eget justo tincidunt molestie. Vestibulum id fringilla leo. Nullam magna eros, rhoncus sed aliquet eget, iaculis ac nibh. Morbi ut risus libero, in euismod ante. Aliquam et est quam, eu blandit quam. </div>
<div id="box2">Some more Text</div>
</div>

 

 

CSS

#tableholder {
position:relative;
margin:0 auto;
width:90%;
}
#box1 {
border:1px solid red; /* Just so you can see the boxes */
height:100px;
overflow:hidden;
margin-right:510px; /* Width of box2 + 10 to create a visual gap between the two */
}
#box2 {
position:absolute;
top:0;
right:0;
border:1px solid blue;
width:500px;
height:100px;
}

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.