Is it possible to use flexbox to do something like in this example? Basically Id like to flip elements which are in a column to be in a row when viewed in mobile. How would you do this?
<p> Desktop:</p>
<table style="height: 52px;" width="331">
<tbody>
<tr>
<td style="width: 103.533px;">image-icon1</td>
<td style="width: 103.533px;">image-icon2</td>
<td style="width: 103.533px;">image-icon3</td>
</tr>
<tr>
<td style="width: 103.533px;">Text1</td>
<td style="width: 103.533px;">Text2</td>
<td style="width: 103.533px;">Text3</td>
</tr>
</tbody>
</table>
<p> Mobile:</p>
<table style="height: 71px;" width="189">
<tbody>
<tr>
<td style="width: 87.1px;">image-icon1</td>
<td style="width: 87.1px;">Text1</td>
</tr>
<tr>
<td style="width: 87.1px;">image-icon2</td>
<td style="width: 87.1px;">Text2</td>
</tr>
<tr>
<td style="width: 87.1px;">image-icon3</td>
<td style="width: 87.1px;">Text3</td>
</tr>
</tbody>
</table>
Yes, its possible
Check below example.
I am using CSS media query #media(max-width:768px) to check whether the width of screen is less than 768px(can be any value less than this).
Depending on that, I am setting the direction of flex children to column, so that the children can stack on top of each other.
Along with that, on mobile screen, I am also setting, the display of inner containers(.sec class) to flex,
<div class="sec">
<div class="img">Image</div>
<div class="text">
Text
</div>
</div>
So that, its children will align itself in row.
.container {
display: flex;
flex-direction: row;/* default value*/
}
.text,.img{
padding:10px;
}
.sec {
flex: 1;
background-color: wheat;
padding: 5px;
border: 1px solid black;
text-align: center;
}
#media(max-width:768px) { /* can be anything less than this*/
.container {
flex-direction: column;
}
.sec {
display: flex;
flex-direction: row;/* default value*/
}
}
<div class="container">
<div class="sec">
<div class="img">Image</div>
<div class="text">
Text
</div>
</div>
<div class="sec">
<div class="img">Image</div>
<div class="text">
Text
</div>
</div> <div class="sec">
<div class="img">Image</div>
<div class="text">
Text
</div>
</div> <div class="sec">
<div class="img">Image</div>
<div class="text">
Text
</div>
</div> <div class="sec">
<div class="img">Image</div>
<div class="text">
Text
</div>
</div> <div class="sec">
<div class="img">Image</div>
<div class="text">
Text
</div>
</div> <div class="sec">
<div class="img">Image</div>
<div class="text">
Text
</div>
</div>
</div>
Related
I am new to HTML/CSS/Bootstrap, so hopefully the solution of my problem is obvious to one of you.
I am creating a flip card that contains a coloured table on the front and on the back (different information will be displayed on front and back).
To provide "axis labeling" to this table I add one extra column on the left side and below the colored table entries. I have this table + axis labeling on the front and back side of the flip card. When the card is fliped parts of the front + the axis labeling are visible to the right of the backside-card . How can I put the cards on top of each other so no part of the front side is visible when the back is up? (Actually there should be axis labeling as well, but somehow it does not show correctly in the code snippet so I commented it out.
.table#risikomatrix{
width: 90%;
height: 90%;
}
.table td{
border-top: 0px solid #121416;
}
#left_axis_front{
background-color: white;
border-right: 3px solid black;
width: 0%;
vertical-align: middle;
}
#left_axis_label{
background-color: white;
transform: rotate(-90deg) translateY(-18px) translateX(-110px);
width: 0%;
height: 0%;
position: absolute;
white-space: nowrap;
font-size: 14pt;
}
#lower_axis{
border-top:3px solid black; ;
}
#lower_axis_label{
background-color: white;
transform:translateY(-12px) translateX(50%);
width: 50%;
height: 0%;
white-space: nowrap;
font-size: 14pt;
}
.cell{
width: 33.33%;
position: relative;
}
.cell::after {
content: '';
display: block;
margin-top: 100%;
}
.card {
background-color: white;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
border: 1px solid #f1f1f1;
/* Centered alignment in card */
text-align: center;
display: flex;
justify-content: center;
}
.card#yellow{
background-color: gold;
}
.card#red{
background-color: red;
}
.card#green{
background-color: green;
}
.flip-card-big {
background-color: white;
width: 40%;
height: 40%;
/* perspective: 1000px; Remove this if you don't want the 3D effect */
}
/* This container is needed to position the front and back side */
.flip-card-big-inner {
background-color: white;
position: relative;
width: 100%;
height: 100%;
text-align: center;
transition: transform 0.8s;
transform-style: preserve-3d;
/* align-self: center; */
}
/* Do an horizontal flip when you move the mouse over the flip box container */
.flip-card-big:hover .flip-card-big-inner{
background-color: white;
transform: rotateY(-180deg);
}
/* Position the front and back side */
.flip-card-big-front {
background-color: white;
position: absolute;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden; /* Safari */
backface-visibility: hidden;
}
.flip-card-big-back {
background-color: white;
position: absolute;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden; /* Safari */
backface-visibility: hidden;
}
/* Style the front side (fallback if image is missing) */
.flip-card-big-front {
background-color: white;
color: rgb(255, 255, 255);
text-align: middle;
}
/* Style the back side */
.flip-card-big-back{
background-color: white;
color: rgb(255, 255, 255);
transform: rotateY(180deg);
}
<div class="container" style="height: 300px;">
<div class="row">
<div class="col-sm d-flex justify-content-sm-center" >
<div class="flip-card-big">
<div class="flip-card-big-inner">
<div class="flip-card-big-front">
<table class="table" id="risikomatrix">
<tr>
<td rowspan="3" id="left_axis_front">
<!-- <div id="left_axis_label">Instabilität</div> -->
</td>
<td class="cell">
<div class="card" id="yellow">
<div style="font-size: 40pt;" id="fm1">
</div>
</div>
</td>
<td class="cell">
<div class="card" id="red">
<div style="font-size: 40pt;" id="fm2">
</div>
</div>
</td>
<td class="cell">
<div class="card" id="red">
<div style="font-size: 40pt;" id="fm3">
</div>
</div>
</td>
</tr>
<tr>
<td class="cell">
<div class="card" id="green">
<div style="font-size: 40pt;" id="fm1">
</div>
</div>
</td>
<td class="cell">
<div class="card" id="yellow">
<div style="font-size: 40pt;" id="fm2">
</div>
</div>
</td>
<td class="cell">
<div class="card" id="red">
<div style="font-size: 40pt;" id="fm3">
</div>
</div>
</td>
</tr>
<tr>
<td class="cell">
<div class="card" id="green">
<div style="font-size: 40pt;" id="fm1">
</div>
</div>
</td>
<td class="cell">
<div class="card" id="green">
<div style="font-size: 40pt;" id="fm2">
</div>
</div>
</td>
<td class="cell">
<div class="card" id="yellow">
<div style="font-size: 40pt;" id="fm3">
</div>
</div>
</td>
</tr>
<tr>
<td></td>
<td colspan="3" id="lower_axis">
<!-- <div id="lower_axis_label">Auslauflänge</div> -->
</td>
</tr>
</table>
</div>
<div class="flip-card-big-back">
<table class="table" id="risikomatrix">
<tr>
<td rowspan="3" id="left_axis_front">
<!-- <div id="left_axis_label">Instabilität</div> -->
</td>
<td class="cell">
<div class="card" id="yellow">
<div style="font-size: 40pt;" id="fm1">
</div>
</div>
</td>
<td class="cell">
<div class="card" id="red">
<div style="font-size: 40pt;" id="fm2">
</div>
</div>
</td>
<td class="cell">
<div class="card" id="red">
<div style="font-size: 40pt;" id="fm3">
</div>
</div>
</td>
</tr>
<tr>
<td class="cell">
<div class="card" id="green">
<div style="font-size: 40pt;" id="fm1">
</div>
</div>
</td>
<td class="cell">
<div class="card" id="yellow">
<div style="font-size: 40pt;" id="fm2">
</div>
</div>
</td>
<td class="cell">
<div class="card" id="red">
<div style="font-size: 40pt;" id="fm3">
</div>
</div>
</td>
</tr>
<tr>
<td class="cell">
<div class="card" id="green">
<div style="font-size: 40pt;" id="fm1">
</div>
</div>
</td>
<td class="cell">
<div class="card" id="green">
<div style="font-size: 40pt;" id="fm2">
</div>
</div>
</td>
<td class="cell">
<div class="card" id="yellow">
<div style="font-size: 40pt;" id="fm3">
</div>
</div>
</td>
</tr>
<tr>
<td></td>
<td colspan="3" id="lower_axis">
<!-- <div id="lower_axis_label">Auslauflänge</div> -->
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
First off, don't give multiple elements the same ID, keep them unique, plain bad practice and will cause issues when JS gets involved.
Answer:
.table#risikomatrix {
width: 90%;
height: 90%;
margin: auto;
}
The <table> is a block level element, which means you can center them if you have margin: auto on the left and right if they're not 100% width of the parent.
In your case you needed to center them because the back table was aligned to the right when flipped while the front was to the left.
I've got the following structure:
.pinyined-char {
display: inline-block;
}
.unpinyined-char {
display: inline-block;
}
.pinyin {
font-size: 10 px;
text-align: center;
}
.char {
text-align: center;
}
<div class="pinyined-char">
<div class="pinyin">duō</div>
<div class="char">多</div>
</div>
<div class="unpinyined-char">
<div class="pinyin"></div>
<div class="char">,</div>
</div>
<div class="pinyined-char">
<div class="pinyin">qǐng</div>
<div class="char">請</div>
</div>
<div class="pinyined-char">
<div class="pinyin">fǎng wèn</div>
<div class="char">訪問</div>
</div>
<div class="unpinyined-char">
<div class="pinyin"></div>
<div class="char">http://www.Caringo.com 。
</div>
</div>
<div class="pinyined-char">
<div class="pinyin">àn zhào</div>
<div class="char">按照</div>
</div>
<div class="unpinyined-char">
<div class="pinyin"></div>
<div class="char">Caringo LinkedIn: https : //www.linkedin.com/company/caringo-inc- Twitter: https : //twitter.com/CaringoStorage
</div>
</div>
<div class="pinyined-char">
<div class="pinyin">guān yú</div>
<div class="char">關於</div>
</div>
<div class="unpinyined-char">
<div class="pinyin"></div>
<div class="char">Caringo Caringo</div>
</div>
<div class="pinyined-char">
<div class="pinyin">shè bèi</div>
<div class="char">設備</div>
</div>
<div class="pinyined-char">
<div class="pinyin">hé</div>
<div class="char">咊</div>
</div>
<div class="unpinyined-char">
<div class="pinyin"></div>
<div class="char">Caringo LinkedIn</div>
</div>
</div>
Ultimately, I want all of the .pinyined-char and .unpinyined-char .char divs to line up next to each other, with the .pinyin divs on top
I can sorta get this working by putting display: inline-block on .pinyined-char and .unpinyined-char, but I find that it doesn't wrap well
How do I make this wrap properly and put everything inline, while keeping pinyin on top of the respective characters in .char?
Example:
NOTE: I have edited the example to be much closer to what I am experiencing. The problem I am trying to solve is between the
àn zhào
按 照
line and the Caringo Linkedin. I would like that Caringo Linkedin to appear on the same line and wrap.
https://jsfiddle.net/70kbtLru/11/
This is specifically what the HTML5 <ruby> element was introduced for. In a <ruby> element you can add ruby annotations with the <rt> tag, while using <rp> for backwards compatibility.
Something like
duō
多
can be rendered by this code:
<ruby>
多 <rp>(</rp><rt>duō</rt><rp>)</rp>
</ruby>
Browsers that don’t support <ruby> will render it like this, depending on the choice of <rp> parentheses:
多 (duō)
Taking your current example of annotated text, the HTML would look something like this:
<ruby>
多 <rp>(</rp><rt>duō</rt><rp>)</rp>
</ruby>
,
<ruby>
請 <rp>(</rp><rt>qǐng</rt><rp>)</rp>
訪 <rp>(</rp><rt>fǎng</rt><rp>)</rp>
問 <rp>(</rp><rt>wèn</rt><rp>)</rp>
</ruby>
https://www.Caringo.com 。
<ruby>
按 <rp>(</rp><rt>àn</rt><rp>)</rp>
照 <rp>(</rp><rt>zhào</rt><rp>)</rp>
</ruby>
Caringo LinkedIn: https://www.linkedin.com/company/caringo-inc- Twitter: https://twitter.com/CaringoStorage
<ruby>
關 <rp>(</rp><rt>guān</rt><rp>)</rp>
於 <rp>(</rp><rt>yú</rt><rp>)</rp>
</ruby>
Caringo Caringo
<ruby>
設 <rp>(</rp><rt>shè</rt><rp>)</rp>
備 <rp>(</rp><rt>bèi</rt><rp>)</rp>
咊 <rp>(</rp><rt>hé</rt><rp>)</rp>
</ruby>
Caringo LinkedIn
How about this?
.pinyined-char, .unpinyined-char {
display: inline-block;
}
.pinyin {
font-size: 10px;
}
.char, .pinyin {
text-align: center;
width: 100%
}
<div>
<div class="pinyined-char">
<div class="pinyin">shè bèi</div>
<div class="char">設備</div>
</div>
<div class="pinyined-char">
<div class="pinyin">hé</div>
<div class="char">咊</div>
</div>
<div class="unpinyined-char">
<div class="pinyin"></div>
<div class="char">Caringo LinkedIn</div>
</div>
</div>
<div>
<div class="pinyined-char">
<div class="pinyin">shè bèi</div>
<div class="char">設備</div>
</div>
<div class="pinyined-char">
<div class="pinyin">hé</div>
<div class="char">咊</div>
</div>
<div class="unpinyined-char">
<div class="pinyin"></div>
<div class="char">Caringo LinkedIn</div>
</div>
</div>
Otherwise, here it is with a table.. and each word vertically aligned to each character.
<table>
<tr>
<td>shè</td>
<td>bèi</td>
<td>hé</td>
<td></td>
</tr>
<tr>
<td>設</td>
<td>備</td>
<td>咊</td>
<td>Caringo LinkedIn</td>
</tr>
<tr>
<td>shè</td>
<td>bèi</td>
<td>hé</td>
<td></td>
</tr>
<tr>
<td>設</td>
<td>備</td>
<td>咊</td>
<td>Caringo LinkedIn</td>
</tr>
</table>
This here was with the code exactly like you showed (ie, two different sets of texts / with matching translations)
This snippet can easily be extended to add more text in the table, if needed
#wrapper {
display: flex;
flex-wrap: wrap;
}
td {
text-align: center;
}
.char,span {
text-align: center;
align-self: flex-end;
padding-bottom: .3em;
padding-left: .5em;
}
<div id="wrapper">
<table>
<tr>
<td>duō</td>
</tr>
<tr>
<td>多</td>
</tr>
</table>
<span>,</span>
<table>
<tr>
<td>qǐng</td>
<td>fǎng wèn</td>
</tr>
<tr>
<td>請</td>
<td>訪問</td>
</tr>
</table>
<div class="char">
http://www.Caringo.com
</div>
<table>
<tr>
<td>àn zhào</td>
</tr>
<tr>
<td>按照</td>
</tr>
</table>
<div class="char">
Caringo LinkedIn
Twitter
</div>
<table>
<tr>
<td>guān yú</td>
</tr>
<tr>
<td>關於</td>
</tr>
</table>
<div class="char">Caringo Caringo</div>
<table>
<tr>
<td>shè bèi</td>
<td>hé</td>
</tr>
<tr>
<td>設備</td>
<td>咊</td>
</tr>
</table>
<div class="char">Caringo LinkedIn</div>
</div>
For some reason the cells in my second row in my table are changing the width of the cells in the row above. I have no idea why this is the cause. I don't want the width of the first cell in the first row to be changed. I have reproduced the problem in jsfiddle to make it clear what I mean.
FiddleJS link:
https://jsfiddle.net/bpyrgsvc/1/
HTML:
<div class="table">
<div class="row">
<div class="cell">test</div>
<div class="cell">test</div>
<div class="cell">test</div>
<div class="cell">test</div>
<div class="cell">test</div>
</div>
<div class="row">
<div class="cell">this changes the width of the cell above</div>
</div>
</div>
CSS:
.table {
display:table;
}
.row {
display: table-row;
}
.cell {
display: table-cell;
padding: 5px;
border: 1px solid black;
}
With CSS you can build a table using a table element and then style how you want using display: block and inline-block. Though if your need really is as simple as it appears to be then a simple colspan will do the jobs.
<table>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="4"></td>
</tr>
</table>
Appending table within the cell should clarify your issue. Refer the snippet below
.table {
display:table;
table-layout: fixed;
width: 100%;
border-collapse:collapse
}
.row {
display: table-row;
}
.cell.p0{
padding:0;
border:none
}
.cell {
display: table-cell;
padding: 5px;
border: 1px solid black;
}
.cell-full {
// full width of table
}
<div class="table">
<div class="row">
<div class="cell p0">
<div class="table">
<div class="row">
<div class="cell">test</div>
<div class="cell">test</div>
<div class="cell">test</div>
<div class="cell">test</div>
<div class="cell">test</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="cell cell-full">this changes the width of the cell above</div>
</div>
</div>
I don't see anything wrong with the results. In a div set to be displayed as table and table-row, it is behaving as tables.
To get the result you want, close the first table and start another.
<div class="table">
<div class="row">
<div class="cell">test</div>
<div class="cell">test</div>
<div class="cell">test</div>
<div class="cell">test</div>
<div class="cell">test</div>
</div>
</div>
<div class="table">
<div class="row">
<div class="cell cell-full">this changes the width of the cell above</div>
</div>
</div>
https://jsfiddle.net/bpyrgsvc/4/
Flexbox can do that:
.row {
display: flex;
}
.cell {
flex: 1;
padding: 5px;
border: 1px solid black;
}
<div class="table">
<div class="row">
<div class="cell">test</div>
<div class="cell">test</div>
<div class="cell">test</div>
<div class="cell">test</div>
<div class="cell">test</div>
</div>
<div class="row">
<div class="cell">this NO LONGER changes the width of the cell above</div>
</div>
</div>
Another way is to set no wrap for whitespaces in css.
<div class="no-wrap-cell">This goes in a single line</div>
.no-wrap-cell{
white-space: nowrap !important;
}
Image of the problem:
How do I go from the one on the left, to the one on the right, using CSS?
You can use a table:
<table>
<tr>
<td>You own</td>
<td>20</td>
</tr>
<tr>
<td>Price</td>
<td>20</td>
</tr>
<tr>
<td>BPS</td>
<td>0.50</td>
</tr>
</table>
or floating divs:
<div style="display:inline-block;">
<div style="float:left; width:150px;">You own</div>
<div style="float:left;">20</div>
</div>
<div style="display:inline-block;">
<div style="float:left; width:150px;">Price</div>
<div style="float:left;">20</div>
</div>
<div style="display:inline-block;">
<div style="float:left; width:150px;">BPS</div>
<div style="float:left;">0.50</div>
</div>
<div>
<div id="left"> <!-- float left -->
<p>You Own></p>
<p>Price</p>
<p>BPS</p>
</div>
<div id="right">
<p>20</p>
<p>20</p>
<p>0.50</p>
</div>
</div>
Two divs
<div class="box">
Your own:<br />
Price:<br />
PBS
</div>
<div class="box">
20<br />
20<br />
50
</div>
CSS
.box {
float:left;
padding-right:40px;
}
While I am in agreement that this can be a table, you can easily do this with floats.
.container {
padding: 0.5em;
width: 200px;
background: #333;
color: #fff;
}
.button {
background: #efefef;
padding: 5px;
color: #000;
margin-bottom: 0.5em;
}
.item-header {
font-weight:bold;
float:left;
width: 45%;
clear:both;
}
<div class="container">
<div class="button">Buy Foreign Worker</div>
<div class="items">
<div class="item-header">You Own:</div>
<div class="item-value">20</div>
<div class="item-header">Price:</div>
<div class="item-value">20</div>
<div class="item-header">BPS:</div>
<div class="item-value">0.5</div>
</div>
</div>
All you are doing is making the header values float to the left, and the clear ensures that it starts on a new row.
How to create table layout in HTML only by using by passing both width & height parameters as percentages, not pixels so that it works as the same in all the browsers ?Also pls suggest some good material or link where I can find the format for required attributes & their values used to accomplish this task.Early replies are appreciated.
Check this http://jsfiddle.net/nalaka526/hUFh4/6/
CSS
.divTable
{
width: 50%;
height: 50%;
display: table;
}
.divTableRow
{
width: 100%;
height: 100%;
display: table-row;
}
.divTableCell
{
width: 25%;
height: 100%;
display: table-cell;
}
HTML
<div class="divTable">
<div class="divTableRow">
<div class="divTableCell">
H1
</div>
<div class="divTableCell ">
H2
</div>
<div class="divTableCell ">
H3
</div>
<div class="divTableCell ">
H4
</div>
</div>
<div class="divTableRow">
<div class="divTableCell">
a
</div>
<div class="divTableCell ">
b
</div>
<div class="divTableCell ">
c
</div>
<div class="divTableCell ">
d
</div>
</div>
</div>
I'm not entirely sure what you're asking. Do you just want a fluid <table> layout? Below is a very basic example of a fluid layout. Keep in mind, the table will only be as wide as the container it's in.
<table width="100%" height="100%">
<tr width="25%" height="100%">
<td></td>
</tr>
<tr width="75%" height="100%">
<td></td>
</tr>
</table>