I'm writing a "responsive design" layout and it's been kind of a headache so far. I decided to use the :before and vertical-align: middle; workaround to vertically align some text inside 'buttons', and it works on everything, except one button! The thing is, on refresh, Chrome Mobile will sometimes render it correctly, and sometimes it won't; it seems arbitrary, I haven't been able to find a pattern.
Here's how it should not look:
Here's how it should look:
Here's the relevant markup:
<div class="button">
<a href="/login">
<span class='button-container'>
<span class="button-icon">
<i class="fa fa-sign-in"></i>
</span><br/>
<span class="button-label">
Log In
</span>
</span>
</a>
</div>
<div class="button">
<a href="/signup">
<span class='button-container'>
<span class="button-icon">
<i class="fa fa-user-plus"></i>
</span><br/>
<span class="button-label">
Join Us!
</span>
</span>
</a>
</div>
And the CSS:
.button
{
display: inline-block;
text-align: center;
cursor: pointer;
overflow: hidden;
}
.button a
{
display: inline-block;
height: 100%;
}
.button a:before //So its contents vertically-align
{
content: '';
display: inline-block;
height: 100%;
vertical-align: middle;
margin-right: -0.25em;
}
.button-container
{
display: inline-block;
vertical-align: middle;
text-align: center;
}
.button-icon
{
font-size: 180%;
}
.button-label
{
font-size: 90%;
}
It only happens with the "Log In" button (but I included two of them in case it helps). The buttons are contained within a div that has text-align: right;, in case that's relevant.
It renders well on Firefox Mobile, and on desktop, of course. I tested it on Chrome Beta v42, and the most recent version of regular Chrome Mobile, I guess maybe it's a Webkit thing, but I wonder if it's a known issue, and if there are any workarounds, or at least an explanation as to why it happens.
Related
I am working on a react project, and I list some operations ( objects ) in a Table, everything looks fine but the client for something I found very weird and hard, here is how it looks :
But that is not how he wanted the datatable dates looks, he wants something like this :
Is there a CSS property that can make that possible ?
Any help would be much appreciated.
there is too much code to write, but those parts are enough :
HTML :
<div class="co-operations-contrat__date">
<span class="co-operations-contrat__date-text">04/07/2018</span>
</div>
SASS :
.co-operations-contrat {
&__date {
a {
margin-right: 5px;
display: inline-block;
cursor: pointer;
+.co-operations-contrat__date-text {
margin-left: 0;
}
}
&-text {
margin-left: 25px;
font-family: "Poppins", monospace;
}
}
}
Like others have said monospace for the dates would be best. If you can't change the font are you able to wrap each part of the date?
If so what you could do is something like this;
https://jsfiddle.net/8mLwot25/3/
Basically, I've set a width on each span and aligned them with flex on the parent container. (You could also float each span). But by doing this would align the items in a better way.
It's not perfect but its a solution.
.container {
display: flex;
}
.container span {
text-align: center;
width: 20px;
}
.container span:last-child {
width: auto;
}
<div class="container">
<span>01</span>/
<span>04</span>/
<span>2019</span>
</div>
<div class="container">
<span>01</span>/
<span>05</span>/
<span>2018</span>
</div>
<div class="container">
<span>13</span>/
<span>04</span>/
<span>2019</span>
</div>
Maybe letter-spacing can help you with that. I'm not sure if you can achieve a pixel perfect result with that but this property may be usefull.
The issue is related to the Poppins font you are using for these dates. The font is not monospaced (it is sans-serif only).
If using a regular monospace font, the issue no longer appears
See demo below
.co-operations-contrat__date a {
margin-right: 5px;
display: inline-block;
cursor: pointer;
}
.co-operations-contrat__date .co-operations-contrat__date-text {
margin-left: 0;
}
.co-operations-contrat__date-text {
margin-left: 25px;
font-family: "Poppins", monospace;
}
#no-poppins .co-operations-contrat__date-text {
margin-left: 25px;
font-family: monospace;
}
<link href="https://fonts.googleapis.com/css?family=Poppins" rel="stylesheet">
<h2>Poppins In</h2>
<div class="co-operations-contrat__date">
<span class="co-operations-contrat__date-text">30/06/2018</span><br/>
<span class="co-operations-contrat__date-text">31/03/2018</span><br/>
<span class="co-operations-contrat__date-text">04/07/2018</span><br/>
<span class="co-operations-contrat__date-text">31/01/2011</span><br/>
</div>
<h2>Poppins Out</h2>
<div id="no-poppins" class="co-operations-contrat__date">
<span class="co-operations-contrat__date-text">30/06/2018</span><br/>
<span class="co-operations-contrat__date-text">31/03/2018</span><br/>
<span class="co-operations-contrat__date-text">04/07/2018</span><br/>
<span class="co-operations-contrat__date-text">31/01/2011</span><br/>
</div>
<h1>Other workarounds include </h1>
<h2>Usign <TT></h2>
<div class="co-operations-contrat__date">
<tt>30/06/2018</tt><br/>
<tt>31/03/2018</tt><br/>
<tt>04/07/2018</tt><br/>
<tt>31/01/2011</tt><br/>
</div>
<h2>Using <PRE></h2>
<div class="co-operations-contrat__date">
<span>30/06/2018</pre>
<pre>31/03/2018</pre>
<pre>04/07/2018</pre>
<pre>31/01/2011</pre>
</div>
Of course, you can choose any monospaced font of your choosing, I just went the browser's defaults for the demo.
I am trying to put the logout button at the left toolbar , i have done it by position but it is not reponsive nd by smalling the chrome this button disappers , i have tried margin also but of no use!! How can I do it ??
My HTML
<div class="user-button-container at-xl-12 "#userButton>
<button class="user-button " md-button [mdMenuTriggerFor]="menu">
<div fxLayout="row" fxLayoutAlign="start center">
<at-icon class="at-display-block"backgroundColor="purple" backgroundType="border"size="40px" fontSize="30px"></at-icon>
<span class="name" fxHide="true" fxHide.gt-sm="false"></span>
<md-icon></md-icon>
</div>
</button>
</div>
My CSS
.user-button-container {
height: 100%;
font-weight: 400;
.user-button {
height: 100%;
border-radius: 0;
position: relative;
left: 1050px;
md-icon {
font-size: 16px;
width: 16px;
height: 16px;
}
.name {
margin: 0 8px 0 10px;
}
} }
looks like you have the design specified for xl-format, but not for smaller formats. as far as I know you should always start from small (xs) to large (lg) and not the other way around. so maybe just changing the following could help:
div class="user-button-container at-xs-12 "#userButton>
instead of
div class="user-button-container at-xl-12 "#userButton>
if you are using bootstrap use following class for desktop or mobile
<div class="user-button-container col-md-12 col-xs-12">
</div>
also, it appears you are not closing your css items - make sure you are using {}
I've been struggling for a correct alignemt between two icons and a small text but I cant manage to properly align them:
I need the text to be align with both icons, can someone give me a help; i've checked a very similar post but I couldn't make it work.
.icon-company-title {
margin-top: 30px;
}
.material-icons.md-18 {
color: $primary;
font-size: 40px;
line-height: 0!important;
}
.material-icons.edit {
color: $primary;
vertical-align: middle;
}
.business-icon {
display: inline-block;
vertical-align: bottom;
}
<div class="icon-company-title">
<div class="business-icon">
<i class="material-icons md-18">business</i>
</div>
<span class="company-card-title">{{ entity.name }}</span>
<button class="" mat-icon-button [matMenuTriggerFor]="menu">
<i class="material-icons edit">mode_edit</i>
</button>
</div>
Given an inline (or inline-block) element with text of variable length, and another element to the right of the first one that acts as a kind of badge, is there a way to prevent a line break between the last word of the first element and the second element? Both elements occupying the same line is fine; a line break occurring in the text of the first element is also fine; but a line break between the two elements is undesirable. Here is an illustration explaining what I mean.
Is there a way to do this? I tried to have the two elements as spans and put a non-breaking space between them, but that didn't work.
UPDATE: Here's a quick and dirty Codepen example: http://codepen.io/anon/pen/LkzBQJ
html:
<h1>
<span class="title-text">
This is some text
</span><span class="badge">yo!</span>
</h1>
<h1>
<span class="title-text">
This is some broken text
</span><span class="badge">yo!</span>
</h1>
css:
h1 {
width: 350px;
}
.badge {
color: #f6511d;
display: inline-block;
border: 1px solid #f6511d;
border-radius: 3px;
font-size: 0.8em;
padding: 0.1em 0.2em;
line-height: 0.97em;
margin-left: 0.4em;
vertical-align: 1px;
}
UPDATE2: In my particular case, both the text in the first element, and the badge have to be rendered dynamically, using JavaScript. So Ricardo’s solution below (wrap the last word of the text and the badge in a span with white-space: nowrap), although working, will not be very easy to implement.
Check this! This line <h1>This is some text</h1><span class="badge">yo!</span> must be in one line to work.
https://codepen.io/lemonjelly/pen/rNNvLGE
SOLUTION:
The solution I could come up with is creating some sort of fix, wrapping text with the badge in a span and using the css property white-space: nowrap;.
JSFiddle
CODE SNIPPET:
.row {
display: flex;
counter-reset: paragraph;
}
.col {
width: 50%;
padding: 1em;
}
.col--left {
background-color: #011627;
padding-right: 0;
}
.col--right {
background-color: #F71735;
border-left: 2px dotted #ddd;
}
.col p {
color: #fff;
}
.col p::before {
counter-increment: paragraph;
content: counter(paragraph)". ";
}
.badge-fix {
display: inline-block;
white-space: nowrap;
}
.badge {
display: inline-block;
padding: .2em .6em .3em;
font-size: 75%;
font-weight: 700;
line-height: 1;
color: #fff;
text-align: center;
white-space: nowrap;
vertical-align: baseline;
border-radius: .25em;
}
.badge--royalblue {
background-color: royalblue;
}
.badge--tomato {
background-color: tomato;
}
.badge--crimson {
background-color: crimson;
}
<div class="row">
<div class="col col--left">
<p>
This is <span class="badge-fix">some text
<span class="badge badge--royalblue">badge</span></span>
</p>
<p>
This is some <span class="badge-fix">reasonably long
<span class="badge badge--tomato">badge</span></span>
</p>
<p>
This is some <span class="badge-fix">longish text
<span class="badge badge--crimson">badge</span></span>
</p>
</div>
<div class="col col--right">
</div>
</div>
This problem is called a widow in typesetting. There are 3 ways to fix this.
Use the widows css property
Only break the last two words together.
<h1 style="widows: 2;">
<span>This is some broken text</span>
<span class="badge">yo!</span>
</h1>
Caveat: Not supported by Firefox (https://caniuse.com/?search=widows) and seems to only work properly with page breaks and column breaks
Use a character
Add a "physical" non-breaking space character, and only that character, between the last word and the badge.
<h1 style="widows: 2;">
This is some broken text <span class="badge">yo!</span>
</h1>
If you have to do this with multi-line code, you can use HTML comments to avoid breaking spaces.
<h1 style="widows: 2;">
This is some broken text<!--
--> <span class="badge">yo!</span>
</h1>
Caveat: It's ugly
Wrap the last word and the badge in a white-space: nowrap span.
<h1 style="widows: 2;">
This is some broken <span style="white-space: nowrap;">text <span class="badge">yo!</span></span>
</h1>
Caveat: Not always possible if you are dealing with dynamically generated code
You can add padding to the text and a negative margin:
<h1>
<span class="title-text" style="padding-right: 15px;">
This is some text
</span><span class="badge" style="margin-left: -15px;">yo!</span>
</h1>
<h1>
<span class="title-text" style="padding-right: 15px;">
This is some broken text
</span><span class="badge" style="margin-left: -15px;">yo!</span>
</h1>
This works for even dynamically generated content, unlike having to make a tag around the last word of the text and the image.
(Based on an answer I saw here: https://stackoverflow.com/a/25857961/5899236)
So I'm simulating a table layout with a div and a couple spans inside it. I'd like the span on the right to indent any text that wraps. I've tried a few things and can't get it to work. Any help would be appreciated.
jsFiddle: http://jsfiddle.net/2Wbuv/
HTML
<div class="display-element">
<span class="display-label">Field 1</span>
<span class="display-field">This is my string of data, some times it is pretty long. Sometimes it is not. This one is.</span>
</div>
<div class="display-element">
<span class="display-label">Field 2</span>
<span class="display-field">This is another string of data.</span>
</div>
CSS
.display-element {}
.display-label {display: inline-block;
width: 100px;
padding-left: 5px;}
.display-field {display: inline;}
Check this out: http://jsfiddle.net/2Wbuv/2/
.display-element {
}
.display-label {
display: inline-block;
width: 100px;
padding-left: 5px;
}
.display-field {
display: inline-block;
padding-left: 50px;
text-indent: -50px;
vertical-align: top;
width: 200px; /* for testing purposes only */
}
<div class="display-element">
<span class="display-label">Field 1</span>
<span class="display-field">This is my string of data, some times it is pretty long. Sometimes it is not. This one is.</span>
</div>
<div class="display-element">
<span class="display-label">Field 2</span>
<span class="display-field">This is another string of data.</span>
</div>
It sounds like you want a hanging indent. CSS something like this should do the trick:
.hanging-indent
{
text-indent : -3em ;
margin-left : 3em ;
}
But since your <span> is an inline element, the text-indent property, as well as other CSS properties pertaining to a block, is meaningless.
The CSS 3 draft specifies a hanging indent. If supported by Browsers, the following should work:
.hanging-indent
{
text-indent: 3em hanging each-line;
}
Unfortunately neither hanging nor each-line values are currently supported in modern browsers as the specification for CSS Text Module Level 3 is still a Draft.
The feature is implemented with a browser specific prefix for WebKit and Chromium. For Firefox there is an open Bug you may vote on.