Responsive text and character removal when on mobile - html

I'm absolutely no HTML/CSS expert, so I beg your pardon if this may sound too basic.
I have an ordered list.
The list is made this way (a name, a dash, a string with a title, a string with some other data, within brackets):
1. John Doe - Balloon last position (other data)
2. Foo Bar - Metallic balloon from out of nowhere (other data)
...
and so on.
Now, to manage responsivity (mobile), I want the following:
the number and the name must be on the same line;
the dash must disappear when on mobile;
the title must be displayed on a second line;
(other data) must be displayed on a third line;
So, I did the following.
In HTML:
<ol>
<li class="myclass">
<span class="name">John Doe – </span>
<span class="title"> Balloon last position</span>
<span class="otherdata">(Canada)</span>
</li>
...
</ol>
and found that basically the three lines idea works with this CSS code:
li.myclass {
display: list-item;
flex-direction: row;
}
#media (max-width: 760px) {
li.myclass {
display: list-item;
}
.name, .title, .otherdata {
display: block;
width: 100%;
}
}
Now, first of all, I don't know if what I did to achieve the result is correct or there's a better way. But at this point I don't know how to eliminate the dash when the list is displayed on mobile. I red about the CSS content property but I failed to understand how to use it in this scenario.
Any help is appreciated, thanks in advance.

I would wrap all the span elements in a div (to keep the ordered list numbering visible. If you use display flex on a list item you will lose some of the list properties) and also put the dash in it's own span and then just hide it on mobile
#media (max-width: 760px) {
li div {
display: flex;
flex-direction: column
}
.dash {
display: none
}
}
<ol>
<li class="myclass">
<div>
<span class="name">John Doe</span>
<span class="dash"> - </span>
<span class="title"> Balloon last position</span>
<span class="otherdata">(Canada)</span>
</div>
</li>
</ol>

Related

How to swap element position using Css?

I want to change the position of two elements using CSS.
The structure of my website is as follows and it show up del ins.
<span class="main-price">
<del aria-hidden="true">
<span class="price">
</del>
<ins>
<span class="price">
</ins>
</span>
No CSS is applied to these elements.
So I applied CSS like below.
.main-price{
text-align: left;
display: inline-flex;
flex-direction: column-reverse;
}
However, this will place the two elements vertically as shown below.
ins
del
So I re-applied the below css, still no change.
.ins{
display:inline;
}
I've tried many times other than that, but no matter what I do, it doesn't show up as ins del.
Can someone give me some advice on what to do?
Instead of flex-direction: column-reverse, use flex-direction: row-reverse.

Why are my columns' contents starting at different heights?

I read that one should not use tables as means of layout, but do all the styling with CSS, so I tried the most basic thing I can think of to mimic tables, by using CSS multi-column layout.
I have created a CodePen to illustrate the problem. As you can see, the content of the two columns starts at different heights, and I do not understand why.
.skill-explanation {
-webkit-column-count: 2;
-moz-column-count: 2;
-ms-column-count: 2;
column-count: 2;
}
.align-left {
text-align: left;
}
.align-right {
text-align: right;
}
<div class="skill-explanation">
<div class="align-right">
<p>★☆☆☆ ‒ <br>
★★☆☆ ‒ <br>
★★★☆ ‒ <br>
★★★★ ‒
</p>
</div>
<div class="align-left">
<p>I can put it into context and am able to use it's basics <br>
intermediate knowledge, used several times <br>
good undestanding, used frequently <br>
deep understanding, used on a daily basis
</p>
</div>
</div>
I wanted to give an update on this post in case someone stumbles upon it.
1) The marked answer is an improvment over mine, but I still find it unintuitive, since it uses the default flex flow which puts the main axis on the horizontal.
The way this should be from a logical standpoint would be columns tho.
Therefore here is an updated solution, which is the most simple and intuitive (at least in my opinion):
.center-wrapper {
margin: 0 auto;
display:table;
}
.skill-explanation {
list-style: none;
}
.rating {
}
.skill {
}
.skill-item {
list-style: none;
}
<div class="center-wrapper" <ul class="skill-explanation">
<li class="skill-item">
<span class="rating">★☆☆☆ ‒</span>
<span class="skill">I can put it into context and am able to use it's basics</span>
</li>
<li class="skill-item">
<span class="rating">★★☆☆ ‒</span>
<span class="skill"></span>
intermediate knowledge, used several times
</li>
<li class="skill-item">
<span class="rating"> ★★★☆ ‒</span>
<span class="skill"></span>
good undestanding, used frequently
</li>
<li class="skill-item">
<span class="rating">★★★★ ‒</span>
<span class="skill"></span>
deep understanding, used on a daily basis
</li>
</ul>
</div>
You can add padding: 1px 0 to the two containers .align-left and .align-right. That way the default top and bottom margins of the p tags stay inside their containers, not causing any vertical offset due to collapsing margins like in your codepen.
https://codepen.io/anon/pen/YBxWbY
Your problem is that the margins are collapsing on the p elements, as they would if the divs were stacked vertically. See Johannes answer.
Howevwer, your concept is flawed. You probably want to actually associate the rating with the skill
ul.skill-explanation {
list-style: none;
padding-left: 0;
}
.skill-item {
display: flex;
}
.skill-item > div {
width:50%;
}
.rating {padding-right: 0.5em;
text-align:right;
}
<ul class="skill-explanation">
<li class="skill-item">
<div class="rating">★☆☆☆ ‒</div>
<div class="skill">I can put it into context and am able to use it's basics</div>
</li>
<li class="skill-item">
<div class="rating">★★☆☆ ‒</div>
<div class="skill">intermediate knowledge, used several times</div>
</li>
<li class="skill-item">
<div class="rating">★★★☆ ‒</div>
<div class="skill">good undestanding, used frequently</div>
</li>
<li class="skill-item">
<div class="rating"> ★★★★ ‒</div>
<div class="skill">deep understanding, used on a daily basis</div>
</li>
</ul>
EDIT
If you would like to use the code you already have. Remove the margin from the paragraph "p" tag that is set be the browser. then set the line height to your desired height.
ORIGINAL answer
You will want to use something like flexbox if you want to easily line you items up. You may also want to set the line height so that you can ensure your unicode icons and your text line up correctly
This will allow you to have full control over where the text and icons align. More info on flexbox at W3schools
p{
margin: 0;
line-height: 1.5em;
}
Flex Box example:
.skill-explanation {
display: flex;
align-items: center;
}
.align-left, .align-right {
line-height: 1.5rem;
}
.skill-explanation {
display: flex;
align-items: center;
}
.align-left, .align-right {
line-height: 1.5em;
}
<div class="skill-explanation">
<div class="align-right">
<p>★☆☆☆ ‒ <br>
★★☆☆ ‒ <br>
★★★☆ ‒ <br>
★★★★ ‒</p>
</div>
<div class="align-left">
<p>I can put it into context and am able to use it's basics <br>
intermediate knowledge, used several times <br>
good undestanding, used frequently <br>
deep understanding, used on a daily basis</p>
</div>
</div>
But you may be better off revisiting your HTML code as someone else suggested and making it into a list as this would be more semantically correct and easier to maintain
<ul>
<li>★☆☆☆ ‒ I can put it into context and am able to use it's basics</li>
<li>★★☆☆ ‒ intermediate knowledge, used several times</li>
<li>★★★☆ ‒ good undestanding, used frequently</li>
<li>★★★★ ‒ deep understanding, used on a daily basis</li>
</ul>

How to left-align some content in Clarity <clr-dg-footer>

I have a Clarity datagrid with pagination and a filter. I have some text that I would like to left-align on the same line as the pagination information. What's the correct way to do this? I've tried setting float: left; and float:right; in the two spans and also using the built-in "row" class. For reference, my footer looks like
<clr-dg-footer>
<span style="width:100%;">Search by value</span>
<span *ngIf="procs.length>0">
{{pagination.firstItem + 1}} - {{pagination.lastItem + 1}}
of {{pagination.totalItems}}
</span>
<clr-dg-pagination #pagination [clrDgPageSize]="10"></clr-dg-pagination>
</clr-dg-footer>
</clr-datagrid>
This is transformed into something like:
<clr-dg-footer _ngcontent-c25="" class="datagrid-foot">
<div class="datagrid-foot-description">
1 - 10
of 103 users
</div>
<clr-dg-pagination _ngcontent-c25="" _nghost-c27="">
<ul _ngcontent-c27="" class="pagination">
...
</ul>
</clr-dg-pagination>
</clr-dg-footer>
To give a general explanation, the footer looks like this when rendered:
<clr-dg-footer>
<various-built-in-controls-from-clarity />
<div class="datagrid-foot-description">
<!-- Your content goes here -->
</div>
<clr-dg-pagination></clr-dg-pagination>
</clr-dg-footer>
The footer itself is a flexbox, so setting widths as percentage on your content will not do anything. Clarity doesn't have a great way for you to left-align your content right now, and you should definitely open a ticket for it on GitHub, but in the meantime you can add the style flex: 1 to .datagrid-foot-description in your CSS which will make it take the all the available space on the footer, and then add any styles you want to your own content to display it as you want. For instance, using more flex with the two spans from your example:
.datagrid-foot-description {
flex: 1;
display: flex;
}
.search-by-value {
flex: 1;
}
This will make the footer description "fill" the empty space in the footer, and the search by value "fill" the description.
The following left-aligns the content of the footer:
.datagrid-footer {
justify-content: left !important;
}

Align Text with Indent

Is it possible to align text with indent over multiple lines and responsible?
Like two Columns which breaks when the window ist too small.
For Example:
When Content fits in one Line:
Text Value
Longer Text Value
Text Longer Value
When Content does not fit in one Line:
Text
Value
Longer Text
Value
Text
Longer Value
The first text should so long it needs, so I don't wan't extra space behind it.
Here is a example where I have a fixed length of the text "column":
dt {
width: 6em; //I want a solution without a width
display: inline-grid;
}
dt,
dd {
float: left
}
dt {
clear: both
}
<dl>
<dt>Text</dt>
<dd>Value</dd>
<dt>Longer Text</dt>
<dd>Value</dd>
<dt>Text</dt>
<dd>Longer Value</dd>
</dl>
So I want the same result without setting the min-width or width of the text "column".
Misunderstood your first question. This styling would adjust based on screen-size. You'll want to assign your element style names as using just this would mess up your page.
.lineTitle{
width: 6em;
display:block;
font-weight:bold;
}
.yourList {margin-bottom:10px; }
#media (min-width:768px){
.lineTitle {display: inline;}
.yourList {margin-bottom:0px; }
}
UPDATED: You just need to wrap them in spans and name them.
<div>
<div class="yourList">
<span class="lineTitle">Text</span>
<span class="lineValue">Value</span>
</div>
<div class="yourList">
<span class="lineTitle">Text</span>
<span class="lineValue">Value</span>
</div>
<div class="yourList">
<span class="lineTitle">Text</span>
<span class="lineValue">Longer Value</span>
</div>
</div>
CSS "column-count" can achieve this, but if the text and value pairs are related, a definition list would be more semantic:
<dl>
<dt>Text</dt>
<dd>Value</dd>
<dt>Longer Text</dt>
<dd>Value</dd>
<dt>Text</dt>
<dd>Longer Value</dd>
</dl>
With a media query you can also change the layout for smaller vs larger screen sizes.
Working example here: https://codepen.io/code-and-pixels/pen/WZKKgE

On a web page, How can i create a horizontal scroll instead of having this wap to the next line?

I have a bunch of columns of info that look like this:
<span style="width:280px;float:left">
some stuff
<span>
<span style="width:280px;float:left">
some stuff
<span>
<span style="width:280px;float:left">
some stuff
<span>
<span style="width:280px;float:left">
some stuff
<span>
etc . .
given that people have different browser widths, if a person has a monitor with a small width, some of the columns wind up wrapping to the next line. In this case, i would want a horizontal scroll bar to show up and keep everything on the same line. What is the correct way of doing this?
Simply place your span elements in a container:
<div>
<span>...</span>
<span>...</span>
...
</div>
Then remove the float property from your span elements, and instead set them to display as inline-block and give your new containing element a white-space of nowrap to prevent them from falling onto a new line:
div {
white-space: nowrap;
}
div span {
display: inline-block;
width: 280px;
}
If you really insist on using the style property on each individual element (which is bad practice) instead of including CSS like I've used above, this would be equal to:
<div style="white-space: nowrap;">
<span style="display: inline-block; width: 280px">...</span>
<span style="display: inline-block; width: 280px">...</span>
...
</div>