The following code causes #headline to overflow #wrapper and I do not understand why this is happening.
HTML:
<div id="wrapper">
<div id="logo">
<img src="/test.png">
</div>
<div id="headline">
<h1>This headline overflows its wrapping div. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #</h1>
</div>
</div>
CSS:
#wrapper {
background: #fea;
white-space: nowrap;
width: 50%;
}
#logo {
display: inline-block;
vertical-align: middle;
}
#logo img {
width: 6em;
}
#headline {
display: inline-block;
vertical-align: middle;
white-space: normal;
}
Example code: http://jsfiddle.net/XjstZ/21/ or http://tinkerbin.com/XvSAEfrK
As the name suggests, inline-blocks participate in inline layout, which means they act just like inline elements, and text. white-space: nowrap causes text to overflow in an element by preventing it from wrapping; the same thing happens with inline-blocks. It's that simple.
The fact that #headline has white-space: normal has no impact on its own layout. An element's white-space property affects the layout of its contents, not itself, even if the element's own box is inline-level.
Setting width to headline element fixes the issue.
#headline {
display: inline-block;
vertical-align: middle;
width: 60%;
}
It's responsive if both image wrapper and image have their max-width defined.
#logo {
display: inline-block;
vertical-align: middle;
max-width: 35%;
}
#logo img {
width: 6em;
max-width: 100%;
}
http://jsfiddle.net/tt1k2xmL/
You need to use overflow: hidden; in your wrapper element
#wrapper {
background: #fea;
white-space: nowrap;
width: 50%;
overflow: hidden;
}
I updated your sample in jsfiddle http://jsfiddle.net/XjstZ/72/
This content wrap because of white-space: normal;.
The white-space CSS property determines how whitespace inside an element is handled. To make words break within themselves, use overflow-wrap, word-break, or hyphens instead.
Now there if you want to limit this with #wrapper than you can limit the overflow property for the div.If you using white-space: nowrap; for div this clear the overflow text and show the div in a single line (ROW).
#wrapper {
background: #fea;
width: 50%;
overflow: hidden;
}
#logo {
display: inline-block;
vertical-align: middle;
}
#logo img {
width: 6em;
}
#headline {
display: inline-block;
vertical-align: middle;
}
Related
We need to declare the top margin for .Article-UnorderedList when it goes after .Article-Paragraph.
We can write selector .Article-Paragraph+.Article-UnorderedList, but it is not suites with below code (in comments, I wrote why).
.Article
&-Paragraph
font-size: 16px
line-height: 18px
// In this line, we don't not know about ".Article-UnorderedList" yet.
// There could be a lot of unknown at advance selectors like ".Article-UnorderedList" below.
// So, we can't write "&.+Article-UnorderedList" here.
// Article-UnorderedList declaration begins here. Now we know about it and also about ".Article-Paragraph"
// So, this selector MUST know how to shift from ".Article-Paragraph"
&-UnorderedList
list-style-type: disc
list-style-position: outside
padding-left: 20px
>li
line-height: 18px
&:not(:first-child)
margin-top: 4px
// We need to declare the margin from .Article-Paragraph
// Some way to create .Article-Paragraph+.Article-UnorderedList HERE?
// Works but lame: we need to exit from &-UnorderedList level and re-declare styles
// for .Article-Paragraph
&-Paragraph+.Article-UnorderedList
margin-top: 16px
You could set a global variable in your parent selector and then use it in your UnorderedList element.
.Article
&-Paragraph
$parent: & !global
font-size: 16px
line-height: 18px
&-UnorderedList
list-style-type: disc
list-style-position: outside
padding-left: 20px
>li
line-height: 18px
&:not(:first-child)
margin-top: 4px
#{$parent} + &
margin-top: 16px
Your result:
.Article-Paragraph {
font-size: 16px;
line-height: 18px;
}
.Article-UnorderedList {
list-style-type: disc;
list-style-position: outside;
padding-left: 20px;
}
.Article-UnorderedList > li {
line-height: 18px;
}
.Article-UnorderedList > li:not(:first-child) {
margin-top: 4px;
}
.Article-Paragraph + .Article-UnorderedList {
margin-top: 16px;
}
I am having trouble ellipsis text (.title) found in between a span that is floated left and a span that is floated right. When overflow occurs .length is pushed down onto a new line. How can I fix this?
JS FIDDLE:
http://jsfiddle.net/VfHdS/6/
HTML:
<div class="song">
<span class="tracknumber">4</span>
<div class="title">This is the song tittle!!!!!!!!!!!</div>
<span class="length">4:31</span>
</div>
CSS:
.song {
font-size: 14px;
padding: 2px 20px;
}
.tracknumber {
margin-right: 10px;
}
.title {
color: #262626;
display:inline-block;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.length {
float: right;
}
Using the sample html you provided I set up a fiddle. Setting the .title element to display block is what gets the ellipses to show up.
http://jsfiddle.net/f4uUJ/
I've also repositioned the track number and play time absolutely so the song title can be 100% width. You just need to add padding to the track to give the title some breathing room.
CSS
.song {
font-size: 14px;
padding: 2px 40px 2px 20px;
position:relative;
}
.tracknumber {
position:absolute;
left:0;
top:2px;
}
.title {
white-space: nowrap;
width: 100%;
display:block;
overflow: hidden;
text-overflow:ellipsis;
}
.length {
position:absolute;
right:0;
top:2px;
}
I have looked through a tonne of posts which have similar issues, but I just can't figure out my problem. Please could someone help, it is driving me insane.
The below code is for my Site Navigation. I would like the background to be an image rather than just a background colour. I would also like the background image to change on hover. As our Meerkat friends would say...Simples!....but not for me.
<div class="sub-menu" id="sub-menu">
<ul>
<li><a class="on" href="#" title=" You Are Here ">ยป Overview</a></li>
<li>Endorsements</li>
<li>The Detail</li>
<li>Funding</li>
<li>Apply Online</li>
<li><a class="end" href="graduates-terms.html" title=" Terms & Conditions ">Terms</a></li>
</ul>
</div>
div.sub-menu { position: relative; width: 920px; height: 40px; padding: 0; margin: 0; border-top: solid 1px #FFFFFF; }
#sub-menu ul { list-style: none; padding: 0; margin: 0; }
#sub-menu li { float: left; margin: 0; }
#sub-menu li a { padding: 0 30px; width: 93px; height: 40px; line-height: 36px; text-align: center; float: left; display: block; color: #FFFFFF; text-decoration: none; background-color: #555555; border-right: solid 1px #858585; }
#sub-menu li a:hover { color: #050505; background-color: #f3b607; }
#sub-menu li a.on { background-color: #555555; color: #FBAF5D; cursor: default; }
#sub-menu li a.end { width: 89px; }
#sub-menu li a.end-on { text-align: center; float: left; display: block; color: #FBAF5D; text-decoration: none; border-right: none; }
/* Hide from IE5-Mac \*/
#sub-menu li a{ float: none }
/* End hide */
#sub-menu { font-weight: normal; font-size: 14px; font-family: verdana; }
Thank you, I really appreciate your help.
In your question subject, you said you wish to put background image to "li" tag, but as per the code you have shown, you have given background to "a" tag.
You can put background image and color both together to any of the tag "li" and "a"
Eg.
background: #00ff00 url('smiley.gif') no-repeat fixed center;
For details refer:
http://www.w3schools.com/cssref/css3_pr_background.asp
If you want to put hover effect as well, implement it on anchor "a" tag. Because old browsers like ie6 doesn't have inbuilt support for li hover effect.
Use following pattern.
a{
background: url('img1') no-repeat fixed center;
}
a:hover{
background: url('img2') no-repeat fixed center;
}
Hope it helps you.
Trying to create a content box that has a background color of white. It is inbetween the header div and footer div which are both images. I can't get it to align with the two divs AND have it without white space, only one or the other.
This is the CSS:
#content {
background-color:#ffffff;
width:1024px;
margin: 0 auto;
font-family:Verdana, Geneva, sans-serif;
font-size:12px;
padding: 0;
display: inline-block;
}
How do I get the content box to align with the rest of the page and not have any whitespaces?
This is what it looks like at the moment, I want to get rid of the space between the HELLO box and the images above and below it.
It doesn't seem as a clean solution to me, but here I go:
#content {
margin-top: -15px; margin-bottom: -15px;
}
Actually I don't know if -15px is good enough, you should try your own values.
It's not a great solution, but with the given information it's the only one i can come up with.
CSS
#content {
background-color:#ffffff;
width:1024px;
margin: 0 auto;
font-family:Verdana, Geneva, sans-serif;
font-size:12px;
padding: 0;
display: inline-block;
position:relative;
}
#topWhiteFix, #botWhiteFix {
position:absolute;
left:0px;
height:12px;
width:100%;
background:#FFFFFF;
}
#topWhiteFix {
top:-12px;
}
#botWhiteFix {
bottom:-12px;
}
HTML
<div id="content">
<div id="topWhiteFix"></div>
<div id="botWhiteFix"></div>
HELLO
</div>
(Untested)
How I can add solarized-dark colors to coderay ?
I'm thinking about tweaking the alpha.rb file, but not sure which css class definitions substitute with which color code.
Any better ideas ?
Maybe there exist some out of the box solution ?
Found also this but not sure how to make usage of it.
The results of what follows are very close to the look of solarized but not perfect. Basically, I used this this stylesheet for solarize and went through selector by selector and did my best to translate it into the styles used by Coderay.
Here is the original solarized example for ruby:
Here is the results I am able to produce with coderay:
SO: it's not perfect, but will get anyone that wants to use a Solarized-like 'theme' for Coderay on their way.
Here is what you need to do (for a Rails 3 app):
First you will need to override the module within the coderay gem that it uses to generate inline styles. Create a file called coderay.rb within config/initializers.
Next paste in the following into the config/intializers/coderay.rb file you've just created:
module CodeRay
module Styles
# A colorful theme using CSS 3 colors (with alpha channel).
class Alpha < Style
register_for :alpha
code_background = '#073642'
numbers_background = 'hsl(180,65%,90%)'
border_color = '#c0c0c0'
normal_color = '#d5f6f6'
CSS_MAIN_STYLES = <<-MAIN # :nodoc:
.CodeRay {
background-color:##073642;
border:1px solid #c0c0c0;
background: #002B36;
color:#eee8d5;
}
.CodeRay pre {
margin: 0px;
}
span.CodeRay { white-space: pre; border: 0px; padding: 2px; }
table.CodeRay { border-collapse: collapse; width: 100%; padding: 2px; }
table.CodeRay td { padding: 2px 4px; vertical-align: top; }
.CodeRay .line-numbers {
background-color:#d5f6f6;
color:#808080;
text-align:right;
-webkit-user-select:none;
-moz-user-select:none;
user-select:none;
}
.CodeRay .line-numbers a {
background-color:#d5f6f6;
color:#808080;
text-decoration:none
}
.CodeRay .line-numbers a:target { color:#00f !important; }
.CodeRay .line-numbers .highlighted { color: red !important; }
.CodeRay .line-numbers .highlighted a { color: red !important; }
.CodeRay span.line-numbers { padding: 0px 4px; }
.CodeRay .line { display: block; float: left; width: 100%; }
.CodeRay .code { width: 100%; }
MAIN
TOKEN_COLORS = <<-'TOKENS'
.debug{color:#fff;background:#00f}
.annotation{color:#586E75}
.attribute-name{color:#93A1A1}
.attribute-value{color:#93A1A1}
.binary{color:#509}
.char .content{color:#d20}
.char .delimiter{color:#710}
.char{color:#2AA198}
.class{color:#268BD2;font-weight:bold}
.class-variable{color:#268BD2}
.color{color:#eee8d5}
.comment{color:#586E75}
.comment .char{color:#859900}
.comment .delimiter{color:#859900}
.complex{color:#a08}
.constant{color:#B58900;font-weight:bold}
.decorator{color:#268BD2}
.definition{color:#099;font-weight:bold}
.delimiter{color:#000}
.directive{color:#088;font-weight:bold}
.doc{color:#93A1A1}
.doc-string{color:#93A1A1;font-weight:bold}
.doctype{color:#DC322F}
.entity{color:#CB4B16;font-weight:bold}
.error{color:#93A1A1;background-color:#faa}
.escape{color:#CB4B16}
.exception{color:#CB4B16;font-weight:bold}
.float{color:#2AA198}
.function{color:#268BD2;font-weight:bold}
.global-variable{color:#268BD2}
.hex{color:#2AA198}
.imaginary{color:#f00}
.include{color:#b44;font-weight:bold}
.inline{background-color:transparent;color:#93A1A1!important}
.inline-delimiter{font-weight:bold;color:#DC322F}
.instance-variable{color:#268BD2}
.integer{color:#2AA198}
.key .char{color:#DC322F}
.key .delimiter{color:#268BD2}
.key{color:#859900}
.keyword{color:#859900;font-weight:bold}
.label{color:#93A1A1;font-weight:bold}
.local-variable{color:#268BD2}
.namespace{color:#859900;font-weight:bold}
.octal{color:#2AA198}
.operator, .predefined{color:#859900;font-weight:bold}
.predefined-constant{color:#2AA198}
.predefined-type{color:#DC322F;font-weight:bold}
.preprocessor{color:#859900}
.pseudo-class{color:#859900;font-weight:bold}
.regexp .content{color:#2AA198}
.regexp .delimiter{color:#DC322F}
.regexp .modifier{color:#CB4B16}
.regexp{background-color:transparent}
.reserved{color:#268BD2;font-weight:bold}
.shell .content{color:#2b2}
.shell .delimiter{color:#161}
.shell{background-color:transparent}
.string .char{color:#2AA198}
.string .content{color:#2AA198}
.string .delimiter{color:#DC322F}
.string .modifier{color:#2AA198}
.string{background-color:transparent}
.symbol .content{color:#2AA198}
.symbol .delimiter{color:#2AA198}
.symbol{color:#2AA198}
.tag{color: #268BD2}
.type{color:#DC322F;font-weight:bold}
.value{color:#268BD2}
.variable{color:#268BD2}
.insert{background:transparent}
.delete{background:transparent}
.change{color:#CB4B16;background:transparent}
.head{color:#CB4B16;background:transparent}
.head .filename{color:#CB4B16}
.delete .eyecatcher{background-color:rgba(255,0,0,0.2);border:1px solid rgba(230,0,0,0.5);margin:-1px;border-bottom:none;border-top-left-radius:5px;border-top-right-radius:5px}
.insert .eyecatcher{background-color:rgba(0,255,0,0.2);border:1px solid rgba(0,128,0,0.5);margin:-1px;border-top:none;border-bottom-left-radius:5px;border-bottom-right-radius:5px}
.insert .insert{color:#CB4B16;background:transparent;font-weight:bold}
.delete .delete{color:##2AA198;background:transparent;font-weight:bold}
.change .change{color:#CB4B16}
.head .head{color:#CB4B16}
TOKENS
end
end
end
You'll also add the following CSS to your application (or, if you want, make a file in assets/stylesheets called coderay.css for it):
pre {
background: #002A35!important;
color: #93A1A1!important;
}
The above will set your code background to the dark background used by solarize and any code not annotated by codeway to the fallback color used in solarize.
Now just restart your app.
** Again, this isn't perfect and youll probably want to crack open that coderay.rb file again at some point and refine things. You can use this to help with that: http://jsfiddle.net/bradleygriffith/CNTw4/ **