HTML and CSS table/grid design - html

I was trying to design table below. I tried to use a HTML table but I couldn't get the box shadow to apply properly as I had to round the corners of the first and last td cells and not the tr (as it doesn't support a border radius) but then applying a box shadow to the row didn't go round the curved edges, rather it stayed square.
I also tried display:grid & flex, however, I could find a way to get the box-shadow/border-radius and centre align the text within columns, it was a trade off.
So any advice would be much appreciated.
This is what I was trying to convert to HTML and CSS.
This is the react code is use to render the HTML for the table:
<div className="policy-container">
<div className="policy-table">
<div className="headings">
<span className="heading">Name</span>
<span className="heading">Last Updated</span>
<span className="heading">Actions</span>
</div>
{data.map((row, ri) => (
<div key={ri} className="policy">
<span>{row.name}</span>
<span>{row.lastUpdated.format("Do MMM YYYY")}</span>
<span>
<a href={row.link}>view</a>
</span>
</div>
))}
</div>
</div>

I would do something like this, using flex:
body {
background-color: #eefbfb;
font-family: sans-serif;
font-size: 16px;
}
.policy-table {
color: grey;
text-align: center;
}
.headings, .policy {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
margin-bottom: 1em;
padding: 1em;
}
.heading {
flex-basis: 33.333%;
font-weight: bold;
}
.policy {
border-radius: 2em;
background-color: white;
margin-bottom: 20px;
-moz-box-shadow: 0 0 3px grey;
-webkit-box-shadow: 0 0 3px grey;
box-shadow: 0 0 5px grey;
}
span {
flex-basis: 33.333%;
}
a {
text-decoration: none;
color: #4c4c4c;
}
<div class="policy-container">
<div class="policy-table">
<div class="headings">
<span class="heading">Name</span>
<span class="heading">Last Updated</span>
<span class="heading">Actions</span>
</div>
<div class="policy">
<span>Name</span>
<span>DD MM YY</span>
<span>
<a href={row.link}>view</a>
</span>
</div>
<div class="policy">
<span>Name</span>
<span>DD MM YY</span>
<span>
<a href={row.link}>view</a>
</span>
</div>
</div>
</div>

Related

How to set element to the right in html?

I'm trying to set the toggle buttons to the right. float, right : 0, align-self is not working for me.
What am I doing wrong ?
The picture is at the end.
HTML:
<div if:true={showCards} class='main-container'>
<div class="main-container-top">
<p class="currs-available"> {trainingPlans.length} {headerLabel} </p>
<lightning-input
class="search slds-p-vertical_small"
type="search"
onchange={handleSearch}
variant="label-hidden"
placeholder="Search" >
</lightning-input>
<c-toggle-button
class="toggle"
buttons={toggleData}
ontoggleswitch={handleToggleSwitch}
default=1>
</c-toggle-button>
</div>
.............
......
.....
and relevant CSS:
.main-container{
background: #f5f5f5;
}
.main-container-top{
display: flex;
}
.currs-available{
width: 33%;
font-size: 20px;
font-weight: 700;
padding: 9px 0 0 20px;
}
.toggle{
width: 33%;
}
Image of element
You can use position: absolute; if you're using right: 0;
Although, the display: flex; will be ignored

How to fix mat-list-item not taking full space of row

Hello guys I rendering an article.component.html inside my article-list-component.html in a list when I do it in plain HTML it renders just fine (see picture 1):
Title - author - Date
Here is my article-list.component.html
<ul>
<li *ngFor="let article of data_array">
<a [href]="article.url" class="undecorateda" target="_blank">
<app-article [data]='article'></app-article>
</a>
</li>
</ul>
but when I try to use angular-material list the component renders all to the left like this (see picture 2):
Title-author-Date
Here is my article-list.component html:
<mat-list>
<mat-list-item *ngFor="let article of data_array">
<a [href]="test">
<app-article [data]='article' (click)="printURL(article.url)"></app-article>
</a>
</mat-list-item>
</mat-list>
when I use the plain HTML in the article-list.component.html it renders as I want it to do, but if I use the material code inside article-list.component.html it doesn't render properly
this is the article.component.html
<div class='article-container'>
<div class='title-container'>
{{data.title}}
<div class='author-container'>
-{{data.author}}-
</div>
</div>
<div class='date-container'>
{{formatDay(data.created_at)}}
</div>
<div class="actions-container" id="deletebtn">
<button mat-icon-button color="warn" (click)="deleteArticle(data._id)">
<mat-icon>delete_forever</mat-icon>
</button>
</div>
</div>
this is the article.component.css file:
.article-container {
display: grid;
grid-auto-flow: column;
grid-template-columns: 10fr 2fr 1fr;
height: 50px;
background-color: #fff;
border-bottom: 1px solid #ccc;
align-items: center;
padding: 0 15px;
}
.article-container>* {
grid-row: 1/2;
}
.article-container #deletebtn {
display: none;
}
.article-container:hover {
background-color: #fafafa;
}
.article-container:hover #deletebtn {
display: block;
}
.title-container {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
color: #333;
font-size: 13pt;
}
.author-container {
color: #999;
font-size: 10pt;
margin-top: 3px;
}
.date-container {
color: #333;
font-size: 13pt;
}
.title-container div {
padding: 0 15px;
}
Basically what I want is to use material-angular list inside the article-list.component.html and that it render good like in picture 1
==========================================
If you add a width of 100% to the article component itself it should ensure the component takes the whole width and the list will the whole width as well.
:host {
width: 100%;
}
Take a look at this example here to see the list taking 100% of the width.

HTML items not getting positioned on the right using CSS

I am trying to align my items list to the right side of the web page. Also, I wanted to have a vertical thin separator between the left and center data structure (hierarchy) and my right list.
Right.component.html :
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="header-divider">
<ul class="selection-list">
<li *ngFor="let item of getSelections()">
<button class="btn" (click)="deselect(item)" *ngIf="item.selected">
<i class="fa fa-close"> {{ item.displayName }} </i>
</button>
</li>
</ul>
</div>
Right.component.css :
.selection-list {
list-style: none;
margin-top: 5px;
margin-bottom: 10px;
line-height: 15px;
font-size: 16px;
color: #555;
padding-left: 23px;
text-transform: capitalize;
right: 0;
}
.btn {
border: none;
padding: 0;
background: none;
}
.header-divider {
border-left:1px solid #38546d;
height:30px;
position:relative;
right:20px;
top:10px;
}
Right now, it just appears below my hierarchy structure. What should I do to fix this?
I always favor the use of flexbox which is a great simple way to use all available space inside a container. This is how I would do it:
-----(Edited)-----
.flex-container {
display: flex;
height: 50px;
border: solid 1px peru;
}
.sendToRight {
margin-left: auto;
}
<div class="flex-container">
<div class="PLCheck">
fortuneSelect
</div>
<div class="sendToRight"> <!-- add class to div for manipulation -->
rightSideComp
</div>
</div>
In this example, the margin-left:auto makes your .sendToRight div move all the way to the right. You could also use justify-content: space-between; in your container element to achieve the same result.

Center align two divs in the same row

I have a JavaScript script that basically hides a box upon clicking the top two boxes. Upon clicking one of the boxes on top, one of the boxes on the bottom hides. How do I make the two boxes on the bottom stay centered?
Here is the landing page:
I want the divs on the bottom centered, once a box is hidden. I want the SharePoint and Teams boxes centered after the other box is hidden.
Center the bottom two div's after change ^
Code:
.margin-bottom-20 {
margin-bottom: 20px;
}
.collabProjects:hover, .collabFiles:hover, .collabSocially:hover {
box-shadow: 0 0 15px rgba(33,3,3,.2);
}
.decisionTreeBox {
background-color: #4B92DB;
color: white;
width: 300px;
height: 140px;
display: flex;
justify-content: center;
align-items: center;
transition: box-shadow .3s;
}
#decisionTreeOneDrive {
background-color: #094AB2;
color: white;
width: 300px;
height: 140px;
display: flex;
justify-content: center;
align-items: center;
}
#decisionTreeSharePoint {
background-color: #008CE7;
color: white;
width: 300px;
height: 140px;
display: flex;
justify-content: center;
align-items: center;
}
#decisionTreeTeams {
background-color: #4A1EBD;
color: white;
width: 300px;
height: 140px;
display: flex;
justify-content: center;
align-items: center;
}
#innerBoxHeadings {
color: white!important;
text-align: center;
padding-top: 5px;
}
#columnMiddleBorderLeft, #pageTitle {
display:none!important;
}
<div class="outer-container">
<div class="row">
<div class="col-md-6" style="text-align: center;">
<div data-collaborate="shareCollab" class="decisionTreeBox" style="font-size: x-large; float: right;">
Share and Collaborate</div>
</div>
<div class="col-md-6" style="text-align: center;">
<div data-collaborate="shareExternally" class="decisionTreeBox" style="font-size: x-large;">
Share Externally</div>
</div>
</div>
<hr />
<div class="container" style="padding: 0px;">
<div class="row">
<a href="/TrainingResourceCenter/O365Training/Pages/OneDrive.aspx">
<div class="col-md-4 margin-bottom-20" style="text-align: center;">
<div data-decision="shareExternally" id="decisionTreeOneDrive">
<h3 id="innerBoxHeadings"><img src="/TrainingResourceCenter/O365Training/PublishingImages/onedrive-logo.png" style="width: 65px; height: 65px; padding-bottom: 5px; padding-right: 10px; vertical-align: middle;" />OneDrive</h3>
</div>
</div>
</a>
<a href="/TrainingResourceCenter/O365Training/Pages/SharePointOnline.aspx">
<div class="col-md-4 margin-bottom-20" style="text-align: center;">
<div data-decision="shareCollab shareExternally" id="decisionTreeSharePoint">
<h3 id="innerBoxHeadings"><img src="/TrainingResourceCenter/O365Training/PublishingImages/SharePointDecisionTree.png" style="padding-bottom: 5px; padding-right: 10px; vertical-align: middle;" />SharePoint</h3>
</div>
</div>
</a>
<a href="/TrainingResourceCenter/O365Training/Pages/Teams.aspx">
<div class="col-md-4 margin-bottom-20" style="text-align: center;">
<div data-decision="shareCollab" id="decisionTreeTeams">
<h3 id="innerBoxHeadings"><img src="/TrainingResourceCenter/O365Training/PublishingImages/TeamsDecisionTree.png" style="padding-bottom: 5px; padding-right: 10px; vertical-align: middle;" />Teams</h3>
</div>
</div>
</a>
</div>
</div>
</div>
<script>
function projectCollab() {
var divsToCange = document.querySelectorAll('[data-decision]'),
attr = this.getAttribute('data-collaborate');
for (var i = 0; i < divsToCange.length; i++) {
var d = divsToCange[i];
if (d.getAttribute('data-decision').includes(attr)) { /* Had: == attr) { */
d.parentNode.style.display = 'block';
} else {
d.parentNode.style.display = 'none';
}
}
return false;
}
var divButtons = document.querySelectorAll('[data-collaborate]');
for (var i = 0; i < divButtons.length; i++) {
divButtons[i].addEventListener('click', projectCollab);
}
</script>
There's an old technique of centering the content of the parent, then making the children display: inline-block;. You will have to account for the visibility of the white-space " " character — but that is pretty well documented (e.g. Remove Whitespace Between Inline-Block Elements). You'll have to play with margin to restore your spacing, AND remember to change the JS to reflect inline-block instead of block when restoring the elements.
In the interest of selector sanity, I added an example class to the containing row element in the code demo.
HTML
<div class="row centered-buttons">
CSS
.centered-buttons {
text-align: center;
}
.centered-buttons a {
display: inline-block;
vertical-align: middle;
}
.margin-bottom-20 {
margin-bottom: 20px;
}
.collabProjects:hover,
.collabFiles:hover,
.collabSocially:hover {
box-shadow: 0 0 15px rgba(33, 3, 3, .2);
}
.decisionTreeBox {
background-color: #4B92DB;
color: white;
width: 300px;
height: 140px;
display: flex;
justify-content: center;
align-items: center;
transition: box-shadow .3s;
}
#decisionTreeOneDrive {
background-color: #094AB2;
color: white;
width: 300px;
height: 140px;
display: flex;
justify-content: center;
align-items: center;
}
#decisionTreeSharePoint {
background-color: #008CE7;
color: white;
width: 300px;
height: 140px;
display: flex;
justify-content: center;
align-items: center;
}
#decisionTreeTeams {
background-color: #4A1EBD;
color: white;
width: 300px;
height: 140px;
display: flex;
justify-content: center;
align-items: center;
}
#innerBoxHeadings {
color: white!important;
text-align: center;
padding-top: 5px;
}
#columnMiddleBorderLeft,
#pageTitle {
display: none!important;
}
.centered-buttons {
text-align: center;
}
.centered-buttons a {
display: inline-block;
vertical-align: middle;
}
<div class="outer-container">
<div class="row">
<div class="col-md-6" style="text-align: center;">
<div data-collaborate="shareCollab" class="decisionTreeBox" style="font-size: x-large; float: right;">
Share and Collaborate</div>
</div>
<div class="col-md-6" style="text-align: center;">
<div data-collaborate="shareExternally" class="decisionTreeBox" style="font-size: x-large;">
Share Externally</div>
</div>
</div>
<hr />
<div class="container" style="padding: 0px;">
<div class="row centered-buttons">
<a href="/TrainingResourceCenter/O365Training/Pages/OneDrive.aspx">
<div class="col-md-4 margin-bottom-20" style="text-align: center;">
<div data-decision="shareExternally" id="decisionTreeOneDrive">
<h3 id="innerBoxHeadings"><img src="/TrainingResourceCenter/O365Training/PublishingImages/onedrive-logo.png" style="width: 65px; height: 65px; padding-bottom: 5px; padding-right: 10px; vertical-align: middle;" />OneDrive</h3>
</div>
</div>
</a>
<a href="/TrainingResourceCenter/O365Training/Pages/SharePointOnline.aspx">
<div class="col-md-4 margin-bottom-20" style="text-align: center;">
<div data-decision="shareCollab shareExternally" id="decisionTreeSharePoint">
<h3 id="innerBoxHeadings"><img src="/TrainingResourceCenter/O365Training/PublishingImages/SharePointDecisionTree.png" style="padding-bottom: 5px; padding-right: 10px; vertical-align: middle;" />SharePoint</h3>
</div>
</div>
</a>
<a href="/TrainingResourceCenter/O365Training/Pages/Teams.aspx">
<div class="col-md-4 margin-bottom-20" style="text-align: center;">
<div data-decision="shareCollab" id="decisionTreeTeams">
<h3 id="innerBoxHeadings"><img src="/TrainingResourceCenter/O365Training/PublishingImages/TeamsDecisionTree.png" style="padding-bottom: 5px; padding-right: 10px; vertical-align: middle;" />Teams</h3>
</div>
</div>
</a>
</div>
</div>
</div>
<script>
function projectCollab() {
var divsToCange = document.querySelectorAll('[data-decision]'),
attr = this.getAttribute('data-collaborate');
for (var i = 0; i < divsToCange.length; i++) {
var d = divsToCange[i];
if (d.getAttribute('data-decision').includes(attr)) { /* Had: == attr) { */
d.parentNode.style.display = 'block';
} else {
d.parentNode.style.display = 'none';
}
}
return false;
}
var divButtons = document.querySelectorAll('[data-collaborate]');
for (var i = 0; i < divButtons.length; i++) {
divButtons[i].addEventListener('click', projectCollab);
}
</script>
In cases like this, I usually conditionally set the class of the content that changes depending on how many items are present. For example, imagine you're checking an array called items that is either 2 or 3 items long. Here is some pseudocode that shows you what I'm thinking.
let itemsClass;
if (items.length === 2) {
itemsClass = 'col-md-6';
} else {
itemsClass = 'col-md-4';
}
myElement.setClass(itemsClass);
You could set a click handler that would check after you click a button or whatever. In react, that could be part of your component render() method.
I don't know what you're using for JS so I won't try to write your code for you. But the gist of it is, decide the class name on the fly with JS and apply it to your elements.
edit: Sorry, I didn't read your entire code snippet. This is something you could add to the handler you already have. You'd just have to grab the elements and alter the classes at that time.
Add the following CSS to the row class:
<div class="container" style="padding: 0px;">
<div class="row" style="justify-content: center">
Since bootstrap uses flexbox system, this should work for you.
What you are asking for is built into BS. But you've muddied the framework by adding html where it ought not be. specifically wrapping BS cols with an anchor tag which breaks the BS grid system, specifically the rule that states only cols can be children of rows.
I've made your html substantially shorter for simplicity and altered your js somewhat to showcase the hiding part. I hope this a decent example that you can expand upon.
FIXES:
I've moved the anchor tab inside the col. This was breaking the alignment of the BS Grid And is also incorrect markup per the BS grid system.
I altered your JS to hide the col, not the anchor. This allows the BS flex grid to properly do it's alignment
In the javascript, consider adding a attribute to your markup such that you don't have to navigate the right number of parent levels. As it stands, if you add more layers to the col html, your JS will break.
function projectCollab() {
var divsToChange = document.querySelectorAll('[data-decision]'),
attr = this.getAttribute('data-collaborate');
for (var i = 0; i < divsToChange.length; i++) {
var d = divsToChange[i];
d.parentNode.parentNode.hidden = ! d.getAttribute('data-decision').includes(attr);
}
return false;
}
var divButtons = document.querySelectorAll('[data-collaborate]');
for (var i = 0; i < divButtons.length; i++) {
divButtons[i].addEventListener('click', projectCollab);
}
.collabProjects:hover,
.collabFiles:hover,
.collabSocially:hover {
box-shadow: 0 0 15px rgba(33, 3, 3, .2);
}
div[data-decision],
div[data-collaborate]{
color: white;
width: 200px;
height: 100px;
}
.decisionTreeBox {
background-color: #4B92DB;
}
#decisionTreeOneDrive {
background-color: #094AB2;
}
#decisionTreeSharePoint {
background-color: #008CE7;
}
#decisionTreeTeams {
background-color: #4A1EBD;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<div class="outer-container">
<div class="container-fluid">
<div class="row justify-content-center">
<div class="col-4">
<div data-collaborate="shareCollab" class="decisionTreeBox">
Share and Collaborate</div>
</div>
<div class="col-4">
<div data-collaborate="shareExternally" class="decisionTreeBox">
Share Externally</div>
</div>
</div>
<hr />
<div class="row justify-content-center">
<div class="col-4">
<a href="#">
<div data-decision="shareExternally" id="decisionTreeOneDrive">
<h3 id="innerBoxHeadings">OneDrive</h3>
</div>
</a>
</div>
<div class="col-4">
<a href="#">
<div data-decision="shareCollab shareExternally" id="decisionTreeSharePoint">
<h3 id="innerBoxHeadings">SharePoint</h3>
</div>
</a>
</div>
<div class="col-4">
<a href="#">
<div data-decision="shareCollab" id="decisionTreeTeams">
<h3 id="innerBoxHeadings">Teams</h3>
</div>
</a>
</div>
</div>
</div>
</div>

Styling list elements with Flexbox

Please help me. I need 3 li element like in image those I downloaded (icon+text), but they have wrong behavior.
I need like this
.icon-equipment {
background-image: url('http://infocem.info/wp-content/uploads/2017/05/1.png');
background-position: left center;
background-repeat: no-repeat;
padding-left: 20px; /* Adjust according to image size to push text across. */
}
ul {
list-style: none;
}
.advantages {
display: flex;
flex-flow: row wrap;
border: 1px solid purple;
height: 123px;
margin: 0;
padding: 0;
}
.advantages > * {
margin-left: 92px;
}
<ul class="advantages">
<li class="icon-equipment">Поставка оборудования<br> и запчастей<br><span>От 11 ведущих производителей</span><li>
<li class="icon-payment">Рассрочка платежа<br><span>До 45 дней с оформления заказа</span></li>
<li class="icon-delivery">Доставка товаров<br><span>Международная и междугородняя<br>в срок до 10 дней</span></li>
</ul>
The main thing to understand here is how to set-up a good hierarchy, so that you may have control over it. What I mean is, you have to separate your item into sections, which can be arranged easily using your model of choice (flexbox in this case).
Just take a look at the html that I have provided, see how it is structured. You have a container, within that container you have two elements, a left-side element (icon) and a right-side element (texts).
Styles are also a thing to notice, you will need some prefixing as well.
Since this is your first time on stackoverflow, I will give you this code ready for use. Usually you have to provide some code that you have been working on, and then seek assisstance for it. Whatever you do, please DO NOT expect this for future problems that you post here on Stack. Read the rules, follow the rules.
html {
font-family: 'Helvetica Neue', Arial, sans-serif;
}
.icon-equipment {
background-image: url('http://infocem.info/wp-content/uploads/2017/05/1.png');
background-position: left center;
background-repeat: no-repeat;
/* Adjust according to image size to push text across. */
}
ul {
list-style: none;
}
.advantages {
display: flex;
flex-flow: row wrap;
margin: 0;
padding: 0;
}
.advantages .advantages-item {
display: flex;
align-items: flex-start;
background: #000;
color: #fff;
padding: 1rem;
max-width: 300px;
margin-right: 1rem;
margin-bottom: 1rem;
}
.advantages .advantages-item:last-of-type {
margin-right: 0;
}
.advantages .advantages-item .item-right {
display: flex;
flex-direction: column;
padding-left: 1rem;
}
.advantages .advantages-item .item-right .right-text {
font-weight: bold;
text-transform: uppercase;
margin: 0;
margin-bottom: 1rem;
}
<ul class="advantages">
<li class="advantages-item">
<div class="item-left">
<div class="top-icon">
<img src="http://infocem.info/wp-content/uploads/2017/05/1.png" alt="" class="icon">
</div>
</div>
<div class="item-right">
<p class="right-text">Поставка оборудования и запчастей</p>
<span>От 11 ведущих производителей</span>
</div>
<li>
<li class="advantages-item">
<div class="item-left">
<div class="top-icon">
<img src="http://infocem.info/wp-content/uploads/2017/05/1.png" alt="" class="icon">
</div>
</div>
<div class="item-right">
<p class="right-text">Поставка оборудования и запчастей</p>
<span>От 11 ведущих производителей</span>
</div>
<li>
<li class="advantages-item">
<div class="item-left">
<div class="top-icon">
<img src="http://infocem.info/wp-content/uploads/2017/05/1.png" alt="" class="icon">
</div>
</div>
<div class="item-right">
<p class="right-text">Поставка оборудования и запчастей</p>
<span>От 11 ведущих производителей</span>
</div>
<li>
</ul>