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/
Related
I would like to set the space between span lines to 15px but it doesn't work when i'm using line-height and i measuring the space with chrome extension the space it's not equal to 15px.
<div class="test">
<span style="line-height:15px;">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
</span>
</div>
result:
enter image description here
Is this what you were looking for. I have added a p element so CSS would recognize this block of text.
<div class="test">
<span>
<p style="line-height:25px;">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
</p>
</span>
</div>
Your code seems to be working. Remember that line-height doesn't affect the font-size but the effective spacing before and after the text (which is why the DOM viewer in chrome shows that the height hasn't changed).
Here is a snippet to highlight what is going on.
.test {
background-color: blue;
}
.test > span {
line-height: 125px;
color: white;
}
<div class="test">
<span>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
</span>
</div>
your code is working . you just probably are measure wrong.
<div class="test" style='width:50px'>
<span style="line-height:1; font-size:15px">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
</span>
</div>
line-height will take values without units as a multiple of the font size.
it is the space each line takes .
Line boxes "belong" to the containing block element - in your case the .test element, and inline elements like your span are broken into multiple inline boxes across the line breaks and the parts are then fitted into the line boxes.
So on each line of the .test element, there's a zero-width inline box called a strut and a part of the span. The span has a line-height of 15px, but the strut has a line-height determined by the .test element.
Since you're not change the font family, or font sizes, or vertical alignments, the distance from the top of one line to the next is simply the maximum of the line height of the strut and the line height of the span.
The default font size, font-family, and line-heights will give a line height of the strut to be around 18 to 19 pixels, hence why you are seeing bigger gaps than you expect.
So to reduce the space between the lines, reduce the strut's line-height as well as the span's line-height, which you do by setting the line-height for the containing block. The span element can then just inherit it. i.e. Use:
body { width:200px; } /* for demo to make multiple lines */
.test {
line-height: 15px;
}
<div class="test">
<span>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
</span>
</div>
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 am trying to use HTML5 to mimic APA6 writing standards. I want to make header tags (<h>) 3-6 not go to the next line and am not sure if/how I can do this by altering the css style.
JSFiddle of Script
<html>
<head>
<title>Title</title>
<style>
h3 {font-size: 16px; font-weight:bold;}
</style>
</head>
<body>
<h2>What it looks like...</h2><hr>
<h3>Level 3 Header.</h3>
<p>Content here. Lots of random text to make an academic sound smart.. I've done my best to maintain APA6 standards in this document but within HTML5 some rules do not make sense. For instance, there are no page breaks.</p>
<br><br><br><br>
<h2>What I'd like it to look like...</h2><hr>
<p><b>Level 3 Header.</b> Content here. Lots of random text to make an academic sound smart.. I've done my best to maintain APA6 standards in this document but within HTML5 some rules do not make sense. For instance, there are no page breaks.</p>
</body>
</html>
It's quite easy, actually. Something like this:
h3, h4, h5, h6 {display: inline;}
EDIT: actually, that doesn't work, as the p still remains below the h3. This is one solution, though it might spawn other problems:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style media="all">
h3, h3+p {display: inline;}
</style>
</head>
<body>
<h3>test</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Non, qui. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Non, qui.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Non, qui.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Non, qui.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Non, qui.</p>
</body>
</html>
Just add display: inline to the css of the H tag you want to remove line break.
you can use h{display: inline;} or h{float: left} but in first case you will lose its block element properties so you can use h{display: inline-block}
Take a look for your reference CSS display: inline vs inline-block
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.
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.