I have a multi-line address in my footer and need lines to break at certain screen widths.
I have each line set in a <span> tag with a class and then allocated either block or inline-block in CSS.
For some reason a couple of lines are no longer behaving as they should and I cannot work out why.
Regardless of what I set a particular line to, it always appears in a line on its own, which is not what I want. And another 2 lines break when they should, 768px, but a gap between the lines appears.
HTML
<span class="address">FEAST THAILAND</span>
<span class="address1">10 NAEBKHEHART ROAD HUA HIN</span>
<span class=“address2”>(Inside The Memory Hua Hin) </span>
<span class="address3">PRACHUAP KHIRI KHAN, 77110 THAILAND</span>
<span class=“address4”>+66 (0) 32 510 207</span>
<span class="address5">OPERATED BY FOOD DISCOVERY (THAILAND) CO., LTD.</span>
<span class="address6"><strong>PRIVACY POLICY</strong> <strong>TERMS & CONDITIONS</strong></span> <span class="address7"><strong>WAIVER & RELEASE OF LIABILITY</strong></span>
<span class="address8"><strong>©2017</strong> ALL RIGHTS RESERVED</span>
<span class="address9">TAT License No. 14/02344</span>
CSS
.address,
.address1,
.address2,
.address4,
.address6,
.address7 {
font-size: 11px;
font-weight: normal;
font-family: Lato, sans-serif;
letter-spacing: 1.5px;
text-align: center;
display: inline-block;
color: #000000;
}
.address3,
.address5,
.address8,
.address9 {
font-size: 11px;
font-weight: normal;
font-family: Lato, sans-serif;
letter-spacing: 1.5px;
text-align: center;
display: block;
color: #000000;
}
Obviously that's just the standard CSS without the media query, but .address4, which has display: inline-block; should be sitting alongside .address3, which has display: block; Any suggestions why it is not?
When the media query comes into play at 768px, .address7 drops down below .address6, which is what I want, but a line of space appears between the 2. Again, any ideas why?
Is this the best way to handle breaking lines where required, or is there a better way? I have even tried using with a class added as well as trying another method found here:
CSS
#media only screen and (max-width: 414px){
.address2 {
font-size: 10px;
font-family: Lato, sans-serif;
letter-spacing: 1.5px;
text-align: center;
color: #000000;
display: block;
}
.address2:after {
content:"\a";
white-space: pre;
}
}
This last part with the .address2:after I thought should have moved the line after .address2 to the next line at 414px, yet it did not.
Any suggestions as to the best way to handle breaking the lines where I want?
cheers
One issue with display:block is that those elements always are displayed on a line of their own, no matter what the surrounding elements look like; be it display:inline or not.
So to answer your questions: an inline-block span next to a block span will not sit next to it on the same line. And two block spans with in between will each be on their own line, with another line in between where the are (this will look like a blank line).
To solve the whole issue, I'd start with simplifying it down to this:
div.addressblock {
text-align: center;
}
div.addressblock span {
font: normal 11px 'Lato', sans-serif;
letter-spacing: 1.5px;
display: inline-block;
color: #000000;
}
div.addressblock a {
font-weight:bold;
padding:0 .5em}
<div class="addressblock">
<span>FEAST THAILAND</span>
<span>10 NAEBKHEHART ROAD HUA HIN</span>
<span>(Inside The Memory Hua Hin) </span>
<span>PRACHUAP KHIRI KHAN, 77110 THAILAND</span><br>
<span>+66 (0) 32 510 207</span>
<span>OPERATED BY FOOD DISCOVERY (THAILAND) CO., LTD.</span><br>
<span>PRIVACY POLICY
TERMS & CONDITIONS
WAIVER & RELEASE OF LIABILITY</span>
<span><b>©2017</b> ALL RIGHTS RESERVED</span><br>
<span>TAT License No. 14/02344</span>
</div>
With actual breaks where you want the line breaks to be, and all the spans turned into inline-blocks to avoid unwanted breaks inside them, and let the page flow do the rest.
If you then want other things to happen at certain screen widths, you can always add some extra CSS.
Related
Is there a way to vertically center a minus sign on even font sizes? I understand the problem, that on font-size: 16px; there is no "center" pixel, therefore the 1px high minus sign has to be in the upper or lower part. On font-size: 17px; there is a center, and it looks much better:
font-size: 16px;
font-size: 17px;
I know it's marginal, but for some users, this looks wrong.
Here is an example.
The problem isn't in centering, but in the middle font height (x-height), I think.
<P style="font-family: arial; font-size: 17px;">ABC-DEF</P>
<P style="font-family: times; font-size: 17px;">ABC-DEF</P>
<P style="font-family: georgia; font-size: 17px;">ABC-DEF</P>
<P style="font-family: cambria; font-size: 17px;">ABC-DEF</P>
<P style="font-family: opensans; font-size: 17px;">ABC-DEF</P>
<P style="font-family: tahoma; font-size: 17px;">ABC-DEF</P>
<P style="font-family: verdana; font-size: 17px;">ABC-DEF</P>
In the code above you can see that font with small x-height (times) has a minus under the vertical center, in tahoma/verdana it's centered better.
Use display-flex on the button and use the value of line-height to position the plus or minus sign vertically within the button. Increase in line-height value moves the signs downward and and decrease in line-height value moves the signs upward. Thanks!
This answer is based on the practical behavior of concerned css properties to achieve vertical align of minus sign and plus sign inside button(I haven't tried for other elements like span or div but I believe it works the same, if not pardon my guess) upon increasing the font-size(to any extent) regardless of font-family used.
Use Case: Sometimes you want bigger buttons with a plus or minus sign inside it. But the font-size is too small for the button. As you increase the font-size of the button, the plus and minus sign fails to align vertically as was the case with me. That's when I came up with the following solution.
Note: I could't find a solution anywhere else, so I ended up with this solution. I am open to any say you have on the solution so feel free to leave some comments:)
/* common style */
button {
height: 50px;
width: 200px;
background: #216AFF;
color: white;
}
.minus {
font-size: 70px;
display: flex;
justify-content: center;
line-height: 35px;
}
.plus {
font-size: 50px;
display: flex;
justify-content: center;
line-height: 45px;
}
<button class="minus">-</button>
<br>
<button class="plus">+</button>
two CSS settings :
h6 {
font-size: 18px;
color: #000;
font-weight: 400;
letter-spacing: 0.05em;
}
h6red{
font-size: 18px;
color: #ff0000;
font-weight: 400;
white-space: nowrap;
}
<h6red>LE CHIC</h6red><h6> jouw partner in kleur</h6>
The output is on two lines, can i prevent this?
Thanks in advance
Erwin
<h6red> isn't valid markup. But what you're looking for is display. Add display:inline-block; to both of the above and they will stay on one line.
As mentioned by Marc Audet, <h6red> isn't valid HTML and therefore we shoud start there. Header tags are <h1>,<h2>,<h3>,<h4>,<h5> and <h6> with no other variations other than the number change. the smaller the number, the larger the text gets. Anything else wont be properly read by the browser as a heading.
With that being said, here's what I'd do.
Using a <span> tag, you could isolate(or 'wrap') one word within a sentence and decorate the<span> in CSS. This would keep the text inline while adding the style. My recommendation would be use a classname on the <span> to allow its use for different things later, unless you only plan to use it once. I would suggest:
<h6>
<span class="makeRed">LE CHIC</span>jouw partner in kleur
</h6>
along with this CSS:
h6{
font-size: 18px;
color: #000;
font-weight: 400;
letter-spacing: 0.05em;
}
.makeRed{
color: #f39999;
}
I would appreciate a little assistance working with Psuedo Selectors for an ID within CSS. I cannot seem to display the first line of an ID in small caps. A snippet of both my CSS and the corresponding HTML is included for reference.
#introtext {
margin: 0px 0px 20px 0px;
background: transparent;
font-face: "arial black";
font-size: 22px;
font-weight: bold;
letter-spacing: .1em;
line-height: 1;
text-align: center;
}
#introtext:first-line {
font-variant: small-caps;
}
HTML:
<div id="introtext"><span id="introcap">H</span><span id="introtext.first">ere you will
find links to Scouting related websites and forms.</div>
Perhaps...
...your expectations are incorrect (and I know your code has an error). While I agree with the comments here that your code is working as expected, I am speculating you are attempting something different.
Did you want the first sentence in small caps?
I noticed in your code you have the "opening" tag of <span id="introtext.first"> but you failed to put the closing tag for that </span>. This is an error. However, if your intent is to have the whole first sentence to become small-caps, your code will still not work because the :first-line pseudo-element does not look at the first sentence, but the first-line (which varies based off of the container width).
Additionally
It is best to not use a . in an id, since the . is used for designating classes. And perhaps a class is what you really want anyway.
Finally, A Solution?
If my speculations about your goals are correct, then I recommend doing the following (keeping your #introtext css the same, but changing the html and :first-line code), as demonstrated in this FIDDLE.
HTML
<div id="introtext">
<span id="introcap">H</span><span class="first-sentence">ere you will find
links to Scouting related websites and forms.</span> More text to follow
in a second sentence. And a third. Blah. Blah.
</div>
CSS
.first-sentence {
font-variant: small-caps;
}
Although
It almost appears as though you intend this to be a header (since the text is centered), so maybe something like this is more semantic and also eliminates the need for your leading "H" to be separate (unless you want OLD browser support). Here is its demo FIDDLE.
HTML
<div>
<h2 id="introtext">Here you will find links to Scouting related websites
and forms.</h2> More text to follow in a second sentence. And a third.
Blah. Blah.
</div>
CSS
#introtext {
margin: 0px 0px 20px 0px;
background: transparent;
font-face: "arial black";
font-size: 22px;
font-weight: bold;
letter-spacing: .1em;
line-height: 1;
text-align: center;
font-variant: small-caps; /*<-- moved this to here*/
}
#introtext::first-letter {
font-variant: none; /*<-- reset the pseudo-element to normal */
}
I have a heading (<h1>) that has a sort of tagline below it. (I used a <small> tag and set font-size to a certain percent so it lines up perfectly when I change font-size of the heading for smaller screens. I'm using em units, if that matters.)
At first, the <small> tag sat nicely underneath the main heading, but I realized I forgot the HTML5 DOCTYPE declaration. So, after I discovered this omission and corrected it, the spacing was all wrong.
Here's my code:
HTML:
<h1 class="banner">Justin Wilson<br /><small>WEB + GRAPHIC DESIGNER</small></h1>
CSS:
h1.banner {
text-align: center;
display: block;
font-family: 'arvil';
font-size: 6.5em;
color: #94babd; }
h1.banner > small {
font-family: Helvetica, Arial, sans-serif;
font-size: 27%;
color: #888;
letter-spacing: 1px;
font-weight: 100; }
And here's the before and after:
I have searched through StackOverflow, but I'm not sure how to proceed. I've read that a <br /> tag simply line breaks, but it inherits the line-spacing, and line-spacing: (value) does not work, nor do margins or padding.
What I need is a simple, cross-browser solution. I used Chrome for the screenshot. Support for IE6-7 is not needed, though support for IE8 would be nice.
The problem is caused by the default line height for the heading element. The default depends on the browser and on the font, but it tends to be about 1.1 to 1.3 times the font size. In any case, with a very large font size set, this creates a problem, because the line height value also sets the height of the second line. By CSS specifications, for a block element, line-height sets the minimum height of line boxes.
There are various ways around this. Setting display: block on the small element is one way, since then its default line height will be determined according to its own font size. Another way is to set a line height that is considerably smaller than the font size, e.g.
h1.banner { line-height: 0.5; }
You need to control the line-height css property (see W3 Schools) to make sure all browsers set the same height for each line.
It's actually advisable to do this to pretty much all elements containing text, which is why most people use CSS resets for production, which sets a default line-height across all elements.
In this case, the <span> and <h1> will likely have different line heights.
I'm sure the <br /> tag is doing nothing wrong, unless you've altered its properties with CSS which I would not advise.
There's also a shorthand version in case you're setting other font properties for the same element(s):
font: <font weight> <font size>/<line height> <font face>;
For example:
font: bold 12px/18px sans-serif;
Hope this helps.
Drop the <br /> and set the display of the <small> element to block.
http://cssdeck.com/labs/uoqfo4xw
<h1 class="banner">Justin Wilson <small>WEB + GRAPHIC DESIGNER</small></h1>
h1.banner {
text-align: center;
display: block;
font-family: 'arvil';
font-size: 6.5em;
color: #94babd; }
h1.banner > small {
font-family: Helvetica, Arial, sans-serif;
font-size: 27%;
color: #888;
letter-spacing: 1px;
font-weight: 100;
display: block; }
An alternative is to set the span to display: block; and then adjust the line-height of the <h2> tag.
I would do this, instead of using a <br /> tag.
Ultimately the answer that works as the best solution is found here (3rd example):
http://www.w3.org/html/wg/drafts/html/master/common-idioms.html#sub-head
#cimmanon posted a very helpful solution, but to be safe, I'll stick with what Steve Faulkner said about this being a more semantic and SEO-friendly solution over using an <h1> tag and <h2> tag for a subheading, or inline elements inside a heading tag, regardless of styling.
Here's the solution:
HTML:
<header>
<h1 class="banner">Justin Wilson</h1>
<p>WEB + GRAPHIC DESIGNER</p>
</header>
CSS:
h1.banner {
text-align: center;
display: block;
font-family: 'arvil';
font-size: 6.5em;
color: #94babd;
font-weight: normal;
margin: 1em 0 0 0;/*purely for display purposes, really*/ }
header > p {font-family: Helvetica, sans-serif;
font-size: 1.75em;
color: #888;
letter-spacing: 1px;
font-weight: 100;
text-align: center;
margin:0; }
And the live demo (might not look good to you without the free Arvil font, from Lost Fonts).
http://cssdeck.com/labs/xysgkffs
Thanks for all the answers thus far.
UPDATED....
Change <small> to <p> in HTML and CSS and add line to the h1.banner > p
margin: 0 auto;
FIDDLE
I've got some words like WORD and REALLYLONGWORD. Both have light font and I want them to become bold on mouse over. Both have float: left; width: auto;. I can't give them fixed width.
The problem is when I hover WORD, the REALLYLONGWORD jumps to the right because WORD gets bolder font (and larger width value). Is there any CSS-only workaround to that?
EDIT (I can't answer my own question, so I'm posting answer below):
I found some CSS-only solution. HTML:
<div class="thtitled-thtitle"><div class="thtitles-title">WORD</div><div class="thtitles-titlebold">WORD</div></div>
<div class="thtitled-thtitle"><div class="thtitles-title">REALLYLONGWORD</div><div class="thtitles-titlebold">REALLYLONGWORD</div></div>
CSS:
.thtitled-thtitle { float: left; }
.thtitles-titlebold { visibility: hidden; color: #F5F5F5; cursor: pointer; float: left; font-family: 'BOLDFONT',Arial,sans-serif; font-size: 72px; line-height: 96px; min-height: 100px; text-transform: uppercase; width: auto; word-wrap: break-word; }
.thtitles-title { color: #F5F5F5; cursor: pointer; font-family: 'LIGHTFONT',Arial,sans-serif; font-size: 72px; line-height: 96px; min-height: 100px; text-transform: uppercase; width: auto; word-wrap: break-word; position: absolute; }
.thtitles-title:hover { font-family: 'BOLDFONT',Arial,sans-serif; }
Basically, I create one more hidden container with BOLD font (its width is main width) and put LIGHT font inside. After hover it still has width of BOLD word so there is no jumping.
You do not want to add any width to fonts at all, I suggest you delete the width property competely. (I also hope you noticed the writing error in your css, with should be width)
The next thing is assign a class to the the ahref this can be easily done with SPAN tags
once done in the css just do:
.firstlinkclass{
font-weight: bold;
}
Use letter spacing. For example {letter-spacing:0.04em}
If you style your WORD with enough letter spacing to make it the same overall width as the same word when it is bold, and remove the letter spacing when it is bold, everything else will stay put.
It works - try this (this just demos the concept - not what I'm recommending for production):
<b>Rotterdam</b><br>
<span style="letter-spacing:0.04em">Rotterdam</span><br/>
<b>and</b><br>
<span style="letter-spacing:0.04em">and</span><br/>
<b>Oslo</b><br>
<span style="letter-spacing:0.04em">Oslo</span><br/>
<b>letter</b><br>
<span style="letter-spacing:0.04em">letter</span><br/>
I know this was asked a long long time ago, but I just came up with a solution to fix the jump that works well so I thought I'd share.
Instead of making the font bold on hover, make it have a text-shadow. No jump, same effect, one line of CSS.