I have a problem. As you can see from the code, in div named "div1" I have 3 divs. I want first (yellow) div to be on top, third (yellow) to be on bottom, and the second div (pink) to fill the remaining space. The only fixed heights are the heights of yellow divs. Can you please help me, how to make the pink div fill the remaining space? Here is my code:
<div style="width:100%;background-color: lime;display: table;border-collapse: collapse;">
<div style="display: table-row;">
<div id=div1 style="display: table-cell;background-color: #0f0;">
<div style="background-color:yellow;width:100%;height:20px;">s</div>
<div style="background-color:pink; width:100%;">
Lorem dsadsad dsa d sad dsa Lorem dsadsad dsa d sad dsa Lorem dsadsad dsa d sad dsa Lorem dsadsad dsa d sad dsa Lorem dsadsad dsa d sad dsa Lorem dsadsad dsa d sad dsa Lorem dsadsad dsa
</div>
<div style="background-color:yellow;width:100%;height:20px;">s</div>
</div>
<div style="background-color: #f00;display: table-cell;width:250px">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.Lorem ipsum dolor sit amet, consectetur adipiscing elit.Lorem ipsum
</div>
</div>
Having to post this as an answer in order to include the graphic. In Firefox and Chrome and IE, your page looks as I think you've described it:
Is this how it should appear?
With a little trickery this can be done:
Text in right cell is taller: http://jsfiddle.net/UQgXM/2/
Text in left cell is taller: http://jsfiddle.net/UQgXM/3/
I've separated the CSS from the HTML.
Major changes:
Given the table a height. This is needed to make the divs in the cell respond to the height setting. The table height is ignored. I set it to 1%, but the table want to be larger.
Given the pink div a height of 100% and a margin and padding to position the content right.
Given the yellow divs (especially the top one) a z-index of 1 and position: relative to make it respond to the z-index. Otherwise it would drop behind the pink div.
<div class="top">s</div>
<div class="middle">
Lorem dsadsad dsa d sad dsa Lorem dsadsad dsa d sad dsa Lorem dsadsad dsa d sad dsa Lorem dsadsad dsa d sad dsa Lorem dsadsad dsa d sad dsa Lorem dsadsad dsa d sad dsa Lorem dsadsad dsa
</div>
<div class="bottom">s</div>
</div>
<div class="rightcell">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.Lorem ipsum dolor sit amet, consectetur adipiscing elit.Lorem ipsum
Lorem ipsum dolor sit amet, consectetur adipiscing elit.Lorem ipsum dolor sit amet, consectetur adipiscing elit.Lorem ipsum
Lorem ipsum dolor sit amet, consectetur adipiscing elit.Lorem ipsum dolor sit amet, consectetur adipiscing elit.Lorem ipsum
Lorem ipsum dolor sit amet, consectetur adipiscing elit.Lorem ipsum dolor sit amet, consectetur adipiscing elit.Lorem ipsum
Lorem ipsum dolor sit amet, consectetur adipiscing elit.Lorem ipsum dolor sit amet, consectetur adipiscing elit.Lorem ipsum
</div>
And the CSS:
.table {
width:100%;
height: 1%;
background-color: lime;
display: table;
border-collapse: collapse;
}
.row {
display: table-row;
}
#div1 {
display: table-cell;
background-color: #0f0;
}
.top,
.bottom{
background-color:yellow;
width:100%;
height:20px;
z-index: 1;
position: relative;
}
.middle {
background-color:pink;
width:100%;
height: 100%;
margin: -20px 0;
position: relative;
padding: 20px 0;
}
.rightcell {
background-color: #f00;
display: table-cell;
width:250px;
}
With a little javascript, you can do some math and calculate the height the pink div should be.
var rightD = document.getElementById('rightDiv');
var yellowD = document.getElementById('yellowD');
var middleD = document.getElementById('middleDiv');
var height = rightD.clientHeight - (yellowD.clientHeight * 2);
middleD.style.height = height + 'px';
http://jsfiddle.net/kX4UB/1/
You don't need to declare so many variables, but I did just for easy display. I just set the height to the red div's height minus the yellow div's height x2. Note, this code should be placed in js tags after these divs in the doc.
Related
I have an editable page and content, that consists of blocks of text and tags as separators bwetween paragraphs. I want to make distance between paragraphs larger and I found solution with
br {
display:block;
margin-top: 15px;
content: " "
}
but in this case multiple br tags in row are collapsed. Also i found solution with line-height, but in this case cursor on empty line looks weird. I can't use p tag, so are there any other solutions?
body {
display: flex;
}
.first {
margin-right: 30px;
}
.first br {
display: block;
margin-top: 15px;
content: " ";
}
.second br {
display: block;
margin-top: 15px;
line-height: 50px;
}
<body contenteditable="true">
<div class="first">
<h3>display:block solution</h1>
Lorem ipsum dolor sit amet
<br>
Lorem ipsum dolor sit amet
<br>
<br>
Lorem ipsum dolor sit amet
</div>
<div class="second">
<h3>line-height solution</h1>
Lorem ipsum dolor sit amet
<br>
Lorem ipsum dolor sit amet
<br>
<br>
Lorem ipsum dolor sit amet
</div>
</body>
but in this case multiple br tags in row are collapsed
Try adding a transparent border-top, to avoid the effect of collapsing margins.
body {
display: flex;
}
.first {
margin-right: 30px;
}
.first br {
display: block;
margin-top: 15px;
border-top: 1px solid transparent;
content: " ";
}
.second br {
display: block;
margin-top: 15px;
line-height: 50px;
}
<body contenteditable="true">
<div class="first">
<h3>display:block solution</h1>
Lorem ipsum dolor sit amet
<br>
Lorem ipsum dolor sit amet
<br>
<br>
Lorem ipsum dolor sit amet
</div>
<div class="second">
<h3>line-height solution</h1>
Lorem ipsum dolor sit amet
<br>
Lorem ipsum dolor sit amet
<br>
<br>
Lorem ipsum dolor sit amet
</div>
</body>
That achieves a double line height between the second and third line in the first example, at least on Chromium. Firefox seems not to have this problem in the first place, in that both of your example look the same. Have not tested Internet Explorer and Edge.
But this is a rather hack-y and error-prone solution. You say you “can’t” use proper paragraph elements - but you should be able to, otherwise your content editing system rather … well, sucks. This is not just a matter of “how it looks”, but also of semantics, and with that possibly search engine ranking, etc.
I am interested, if there is any chance to increase/decrease width of white-space chars inside <textarea>?
You can use word-spacing:
.triple {
word-spacing: 200%;
}
.extra-1 {
word-spacing: 1em;
}
<dl>
<dt>Normal space:</dt>
<dd class="normal">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</dd>
<dt>Triple space:</dt>
<dd class="triple">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</dd>
<dt>Extra 1em space:</dt>
<dd class="extra-1">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</dd>
</dl>
Percentage values were recently introduced and are not widely supported yet.
Quite interesting, I have found out, that spacing especially in <textarea> can be solved by font-family, which you choose for that textarea.
See in action: https://jsfiddle.net/hz3rv73a/6/
Ok, I have a situation where I need to display a custom image for the list bullets; obviously you can do this via list-style-image; however I want to use a sprite.
So another method I came across was to just put the background on the li itself, however without being able to restrict the width/height of the background more of the sprite shows.
I read this solution but..
It didn't seem to work for me for some reason - no background image
showed at all
I would like to support IE8 (extra styles ok though)
I also tried doing something like this and floating the divs inside:
<ul>
<li>
<div class="icon"></div>
<div class="text"></div>
</li>
<li>
<div class="icon"></div>
<div class="text"></div>
</li>
</ul>
... but if the text wrapped to the next line it would go under the icon as the icon height didn't extend high enough.
Is there anything I can do here?
You can use pseudo :before element for styling list
ul {
list-style:none;
padding: 0 0 0 40px;
}
ul li {
position:relative;
margin:5px 0;
}
ul li:before {
content:'';
background: url('http://blog.fogcreek.com/wp-content/uploads/2013/01/sprite.png') no-repeat;
width: 20px;
height: 20px;
display: inline-block;
border: 1px solid black;
vertical-align: middle;
background-position: -197px 0px;
position: absolute;
left: -34px;
background-size: 492px auto;
}
<ul>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. amet, consectetuer adipiscing elit.</li>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing amet, consectetuer adipiscing elit. elit.</li>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
</ul>
I have a #comments element which contains .comment elements. I would like to have 5 vertical lines from left to right, each 1px in width, 100% height (till the end of the #comments element), with 20px between them and without images. I tried to do that myself, but my CSS-fu isn't that high. Any help would be much appreciated.
HTML:
<div id="comments">
<div class="comment level1">Lorem ipsum dolor sit amet</div>
<div class="comment level2">Lorem ipsum dolor sit amet</div>
<div class="comment level3">Lorem ipsum dolor sit amet</div>
</div>
CSS:
#comments {
width: 400px;
border: 1px solid black;
}
.comment {
margin: 10px 0;
}
.level1 {}
.level2 { margin-left: 20px; }
.level3 { margin-left: 40px; }
Demo.
Here's how I imagine it:
|[comment ]
| |[comment ]
| |[comment ]
| | |[comment]
Is there some reason you need to have all the divs as direct children of the outer parent div? If you nest the divs you can accomplish this very easily:
css:
div div {
border-left: 1px solid black;
padding-left:20px;
}
nested html
<div id="comments">
<div>Lorem ipsum dolor sit amet</div>
<div>Lorem ipsum dolor sit amet
<br/>
<div>Lorem ipsum dolor sit amet
<br/>
<div>Lorem ipsum dolor sit amet
<br/>
<div>Lorem ipsum dolor sit amet</div>
<div>Lorem ipsum dolor sit amet
<br/>
<div>Lorem ipsum dolor sit amet</div>
</div>
</div>
</div>
</div>
</div>
updated fiddle showing how it would look here nested down to 5 levels:
http://jsfiddle.net/webchemist/tuZB6/4/
I have a paragraph like this
<p> Lorem ipsum dolor sit amet, /* consectetur adipiscing elit. */ </p>
I want to have a CSS class that have a different font color for the text between /* and */
Thanks for help!
You can't use Expressions to do this.
CSS / HTML Way, by inserting an element inside.
You can use this way:
<p> Lorem ipsum dolor sit amet, <span class="comment">/* consectetur adipiscing elit. */</span> </p>
CSS:
p span.comment {color: #999;}
Demo: http://jsfiddle.net/jNvSw/
Or, if you wanna do in the JavaScript way (uses jQuery, but it can also be done using pure JavaScript):
$(document).ready(function(){
$("p").html($("p").html().replace('/*', '<span class="comment">/*'));
$("p").html($("p").html().replace('*/', '*/</span>'));
});
Demo: http://jsfiddle.net/jNvSw/1/
<p> Lorem ipsum dolor sit amet, <label class="classA"> /* consectetur adipiscing elit. */ </label></p>
<style>
.classA
{
font-size:12px;
font-family:Arial;
color:blue;
}
</style>
Replace your markup (/**/) with <span> tags if possible, then assign class with appropriate color to them.
You could hack it using the :first-line pseudo-element, assuming there's a linebreak:
<p> Lorem ipsum dolor sit amet, /* consectetur adipiscing elit. */ </p>
p { color: grey;
p:first-line { color: black; }
Note that this answer is not to be taken seriously.