Stop text horizontal overflow - css

I have a div and inside of this div is text and this text overflows horizontally and I want to stop that.
Unfortunately, this is a little bit more complicated than it first sounds, because I want to create a div that has two columns and I want the right column to be 30px less wide than the left one.
I know I can solve this by creating two divs, but it would be really cool if there is a way to do this with one div. I was more or less able to do this by working with a parent- and child-element and adding margin-right: -30px; to the child, but unfortunately this margin, even though it is there, seems to collapse into the child and the text complete ignores it.
It would save me quite some work if I could figure this out, any ideas?
Fiddle: https://jsfiddle.net/qxnc3fts/3/
-> GOAL: Make it so that the text does not overflow out of the lightgrey div.
Edit: There is a similar question: Is there a way to specify different widths for columns in CSS3?, and there's a great answer there by #Quentin that definitely helped me but that answer does not make the text break and I would like that to happen. – But it seems like that's impossible. At least in the current CSS-version.
.ref {
width: 200px;
height: 10px;
background-color: black;
}
.parent {
background-color: lightgrey;
width: 400px;
}
.child {
column-count: 2;
column-gap: 30px;
margin-right: -30px;
}
<div class="ref"></div>
<div class="parent">
<div class="child">
i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i
</div>
</div>

Your setting the box as an absolute width and the content no-overflow.
Here's a working solution:
.ref {
width: 200px;
height: 10px;
background-color: black;
}
.parent {
background-color: lightgrey;
width: 400px;
}
.child {
column-count: 2;
column-gap: 3.5%;
margin-right: -30px;
overflow-x: auto, hidden;
padding: 8px 30px;
word-break: keep-all;
display: inline-block;
text-align: center;
}
<div class="ref"></div>
<div class="parent">
<div class="child">
i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i i
</div>
</div>

Related

Stack div under an absolute div?

So I currently have the following HTML/CSS:
<style type="text/css">
body {
background: #eeeeee;
}
.table {
display: table;
margin: 0px auto;
max-width: 400px;
position: relative;
}
.row {
display: table-row;
max-width: 400px;
}
.td1,
.td2 {
display: table-cell;
border: 2px #aaaaaa solid;
padding: 15px;
background: #ffffff;
font-size: 18px;
color: #333333;
}
.td2 {
border-top: none;
color: #777777;
position: absolute;
max-width: 400px;
right: 0px;
left: 0px;
}
.under_div {
position: relative;
}
</style>
<body>
<div class="table">
<div class="row">
<div class="td1">Some random text that changes and can change the height of this div/td</div>
</div>
<div class="row">
<div class="td2">Some random text that changes and can change the height of this div/td</div>
</div>
<div class="row">
<div class="under_div">
<p>Some random text that remains the same always
</div>
</div>
</div>
</body>
My problem is that the second td (td2) needs to be position: absolute. There is a reason why it is so, so therefore it just can't be a regular div, as that would make this much easier :)
So, as you can see the next in the under_div is occupying the same space as the td2div. What I would like is for that to right under the td2div. In principle I could just try to position it so that it fits right under. But as stated in text of the divs the text changes, and therefore the height will be random for both the td1 and td2 divs.
So is there a way where I can stack the under_div div just under the td2 div where it of course follows along according to whatever size the two other divs have, and not just stick around in one position ?
I have tried just making another table-div after the first one. But that doesn't seem to do anything either...
I think you need to rethink your design a little as I don't think it's possible to do this with an absolutely positioned element. You can accomplish what I believe you want using float and clear. An example jsfiddle is here.

Responsive CSS - how to 'dynamically' align div to parent width with padding/margin?

I can't make it any clearer than this, sorry. I want to properly align 4 divs (on a width of 1150px as that is max-width of the content div) and upon resizing when it can't do 4, 3 in the center etc etc)
On >1150px screens it would/should like this: http://i.imgur.com/KaOPqZK.png. Now, the closest I can come is this: http://i.imgur.com/6khwQkR.png. I can set the first-child margin to 0 on the left one, but as there are multiple rows, those would still have the padding. Creating new rows as divs isn't possible either, because that would ruin everything when it's resized and only shows 3/1 on both rows.
When resizing it should center, with even margins on all sides, and not like this as it is right now: http://i.imgur.com/GiR1nZ2.png.
Basically all the code I have right now is this, simply because I know of no other way.
div.project-container {
float: left;
margin: 0 8px 30px 8px;
position: relative;
width: 270px;
}
I'm guessing it has to be Javascript who rescues the day, and I'm fine with that. Pointers in the right direction, examples on the internets, all is welcome. Thank you.
Adapted from an old answer :
HTML
<div id="container">
<div class="obj">1</div>
<div class="obj">2</div>
<div class="obj">3</div>
<div class="obj">4</div>
<div class="obj">5</div>
<div class="obj">6</div>
<div class="obj">7</div>
<div class="obj push"></div>
<div class="obj push"></div>
<div class="pushend"></div>
</div>
CSS
#container
{
max-width: 980px;
background-color: lavender;
display: inline-block;
text-align: justify;
}
.obj
{
width: 180px;
height: 180px;
background-color: lightgreen;
display: inline-block;
margin-bottom: 20px;
}
.obj.push {
height: 0px
}
.pushend {
width: 100%;
height: 0px;
display: inline-block;
}
demo

Center child div in parent div

I've gotten blind on this one.. I came across other similar topic but none of them helped in the ind.
Long story short, I cant the "a,b,c,d" boxes in the center of the parent div - they need to be aligned to the boxed beneath, so the left is in the very left and the right is all the way to the right.
I've posted my code here in this fiddle, so you can see:
http://jsfiddle.net/sdHhp/
and my code: .right_content_wrap{ width: 300px; height: 250px; background: #e3e3e3; float: right; margin: 15px 0px 0px 0px; }
.featured_items_wrap{ width: 980px; height: 140px; background: blue; text-align: center;}
<div class="content_wrap">
<div class="featured_items_wrap">
<div class="featured_item">a</div>
<div class="featured_item">b</div>
<div class="featured_item">c</div>
<div class="featured_item">d</div>
</div>
If you have any question regarding my issue, feel free to write me!
I'm looking forward to a possible solution!
Thanks a lot and have a great evening ahead!
You need to margin: auto on the child divs. Also, you needed to make sure that the child divs are not as wide as the wrapper. I made them 75% in the demo and it works.
div {
width: 75%;
margin: auto;
}
http://jsfiddle.net/sdHhp/4/
EDIT: Note that this is on the wrapper in your JSFiddle, as that is what holds your child divs.
Further EDIT: I realize that I misunderstood you at first. I believe I have gotten your JSFiddle how you wanted it. Check this one out:
http://jsfiddle.net/sdHhp/9/
Expanding on Chad's anwer if you wanted exactly set within the div you can set a margin of 25px; of course it will vary with size, etc. http://jsfiddle.net/r2pLP/1/
div {
border: 1px solid black;
}
#one {
height: 100px;
width: 100px;
}
#two {
height: 50px;
width: 50px;
margin: 25px;
}
<div id="one">
<div id="two"></div>
</div>

Showing the part of a hidden DIV within a DIV

I'm missing something obvious today, guys - would appreciate some help please.
I've got a horizontal row of DIVs inside another DIV. I want the third DIV to show as partly hidden by the top DIV. But it isn't showing at all.
Here's the CSS:
.outer {
background: #800;
height: 90px;
width: 300px;
overflow: hidden;
white-space: nowrap;
}
.label {
float: left;
display: block;
background: #888;
width: 75px;
height: 50px;
margin: 10px;
padding: 10px;
line-height: 50px;
font-size: 45px;
text-align: center;
}
Here's the HTML:
<div class="outer">
<div class="label">1</div>
<div class="label">2</div>
<div class="label">3</div>
<div class="label">4</div>
</div>
Thanks for your help!
I'm missing something obvious today, guys - would appreciate some help
please.
The "obvious" thing you're missing is that the third and fourth inner divs are dropping underneath because there is not enough horizontal space. For instance, if I check it using Chrome's Developer Tools:
The simplest way to fix this is to switch from float: left to display: inline-block, with white-space: nowrap (you already have it!) on the containing element:
http://jsfiddle.net/rGfNY/
you need to wrap them in a new div, give the div a width, (bigger than your outer div) it will be cut off by the outer div's overflow hidden.
on thing to note: the width of that inner div is not adjusting with the content, either you specifically set it very high, or you have to calculate it to the content either just put it hardcoded in css, or use javascript.
html:
<div class="outer">
<div class="inner">
<div class="label">1</div>
<div class="label">2</div>
<div class="label">3</div>
<div class="label">4</div>
</div>
</div>
css:
.outer {
background: #800;
height: 90px;
width: 300px;
overflow: hidden;
white-space: nowrap;
}
.inner {
width: 460px;
}
.label {
float: left;
display: block;
background: #888;
width: 75px;
height: 50px;
margin: 10px;
padding: 10px;
line-height: 50px;
font-size: 45px;
text-align: center;
}
working example:
http://jsfiddle.net/f2wpm/

How to align the top lines of two DIVs?

I want the top lines of two DIVs (<div></div>) to be aligned horizontally, how to do it?
Steven,
In addition to T. Stone's suggestion to float both divs, a simple way to align two divs is to make both have the display: inline-block; CSS rule and give the lower div the vertical-align: top; CSS rule.
Take a look at this simple jsFiddle example to see how this works.
div {
display: inline-block;
}
div#tall {
height: 4em;
}
div#short {
height: 2em;
vertical-align: top;
}
In response to "is there another way to do it", sure you could use display: inline but you have a bunch of hacks to remember to get it to work in IE6/7. This way is generally better (but it all comes down to the individual circumstances)
<style type="text/css">
.keeper {
overflow: hidden; /* expand to contain floated children */
}
.keeper div {
width: 200px;
height: 30px;
float: left;
border-top: 1px solid red; /* so you can see the 'tops' */
}
</style>
<div class="keeper">
<div>
</div>
<div>
</div>
</div>
Float them in a container.
.parent div { float: left; width: 50%; }
<div class="parent">
<div>1</div>
<div>2</div>
</div>
Note: The sum of the width of the child divs can not be greater than 100% of the parent div, including margin and padding.
Alternative
If maintaining flow with the page isn't a requirement, and all that really matters is aligning, them, the divs can always be positioned absolutely.
.abs { position: absolute; top: 100px; width: 50px; }
.left { left: 0px; }
.right { left: 50px; }
<div class="abs left">1</div>
<div class="abs right">2</div>

Resources