First, it is a loop in React and assumed as a mobile version.
Within each loop of DIV, it will have a photo(150*150px) on the left-hand side.
On the photo's right-hand side, it will have 3 div and each of the div will have a p (name, car and salary). At the bottom, it will have a line and its length will be the same as the parent div.
One special is that the pof car will have many words, when the width of the phone is not enough, it will go to the next line. If it is still not enough, it will become Tesla, Honda, BMW,...
it is the Sample Image
I really try many methods(float, position,...), but I still cant deal with it,
Here is the HTML part (using React)
<div className='loop'>
<img className='image' src={value.image}></img>
<div>
<p className='title'>{value.name}</p>
</div>
<div class>
<p className='car'>Tesla, Honda, BMW, Porsch,Mitsubishi, Mazda, Toyota, Jaguar, KIA </p>
</div>
<div>
<p>{value.salary}</p>
</div>
<div className='linebreak'></div>
</div>
Try with grid :
.loop {
display: grid;
grid-template-columns: auto 1fr;
align-items: center;
column-gap: .5em;
width: 400px
}
.image {
grid-row: span 3;
}
.linebreak {
margin-top: .5em;
grid-column: span 2;
border: 2px solid #4f86f7;
}
.loop p, img {
border: 2px solid #777696;
margin: 0;
}
.title {
align-self: start;
}
.salary {
align-self: end;
}
<div class='loop'>
<img class='image' src="https://picsum.photos/100" />
<p class='title'>name</p>
<p class='car'>Tesla, Honda, BMW, Porsch,Mitsubishi, Mazda, Toyota, Jaguar, KIA </p>
<p class='salary'>salary</p>
<div class='linebreak'></div>
</div>
Related
I'm trying to recreate this design from frontendmentor.com.
My initial thought when I saw the design was to split the card section of the page into a 6x4 grid but so far it hasn't really worked. The grid isn't displaying the columns and rows the way I'd like. I tried building some placeholder rows in the areas where there's no content but that didn't work either.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Four Card Feature Section</title>
<link rel="stylesheet" href="styles.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<main role="landing-page">
<section class="heading">
<header class="text">
<h1 class="title-text">Reliable, efficient delivery <br> Powered by technology </h1>
<p class="subtitle-text">Our Artificial Intelligence powered tools use millions of project data <br> points to ensure that your project is successful </p>
</header>
</section>
<div class="grid-container">
<!--Column 1 -->
<div class="column column-left">
<h2 class="title-card">Supervisor</h2>
<p class="subtitle-card">Monitors activity to identify project <br> roadblocks </p>
<img src="icon-supervisor.svg" class="icon" alt="supervisor-icon" /></img>
</div>
<!--Column 2 -->
<div class="column column-middle-a">
<h2 class="title-card">Team Builder</h2>
<p class="subtitle-card">Scans our talent network to create the <br> optimal team for your project </p>
<img src="icon-team-builder.svg" class="icon" alt="teambuilder-icon" /></img>
</div>
<div class="column column-middle-b">
<h2 class="title-card">Karma</h2>
<p class="subtitle-card">Regularly evaluates our talent to ensure <br> quality </p>
<img src="icon-karma.svg" class="icon" alt="karma-icon" /></img>
</div>
<!--Column 3-->
<div class="column column-right">
<h2 class="title-card">Calculator</h2>
<p class="subtitle-card">Uses data from past projects to provide <br> better delivery estimates </p>
<img src="icon-calculator.svg" class="icon" alt="calculator-icon" /></img>
</div>
</div>
</main>
</body>
</html>
CSS
* {
border: 1px solid black;
}
:root {
--gray-text: #696969;
--dark-text: #171717;
}
.column .icon {
right: -15em;
position: relative;
}
.heading {
text-align: center;
align-content: auto;
font-family: David;
}
.title-text {
color: var(--dark-text);
}
.subtitle-text {
color: var(--gray-text);
}
.column .subtitle-card {
color: var(--gray-text);
}
.grid-container {
display: grid;
grid-template-columns: auto auto auto auto auto auto;
grid-gap: 10px;
padding: 20em;
}
/*
.empty-row-1 {
grid-column: 1 / 2;
grid-row: 1;
}
.empty-row-2 {
grid-column: 1 / 2;
grid-row: 4;
}
.empty-row-3 {
grid-column: 5 / 6;
grid-row: 1;
}
.empty-row-4 {
grid-column: 5 / 6;
grid-row: 4;
}
*/
.column-left {
grid-column: 1 / 2;
grid-row: 2 / 3;
text-align: left;
}
.column-middle-a {
grid-column: 3 / 4;
grid-row: 1 / 2;
text-align: left;
}
.column-middle-b {
grid-column: 3 / 4;
grid-row: 3 / 4;
text-align: left;
}
.column-right {
grid-column: 5 / 6;
grid-row: 2 / 3;
text-align: left;
}
I commented out the placeholder rows since they didn't work. I removed them from the html file for clutter purposes, but they were just: <div class="empty-row-x"></div>
I have 1px border on all elements just so I can better see what I'm doing. Of course that isn't meant to stick around forever.
I have a feeling that my "grid approach" is just not the easiest or "correct" way to build this design. Having the "floating" rows in columns 1 and 3 seems awkward and I haven't been able to find any such examples on the usual websites.
Thanks for any help!
Here, you have grid-template-columns: auto auto auto auto auto auto;. You also need grid-template-area property as well where you will describe how you want your grid to look like and then you apply that into elements in which you've applied grid.
For instance if I have three columns and I want it to be like:
Column1 Column2
Column1 Column3
then I have to apply grid-template-area where I will describe it as:
grid-template-areas: "item1 item2,
item1 item3"
then,I will put it in columns as well
column1 {
grid-area: item1;
}
column2 {
grid-area: item2;
}
column3 {
grid-area: item3;
}
What I want to do is make my sidebar cards be on the right and not the left. I've tried to use the display: grid; and that didn't work. I've tried to use the left: 0; and right: 0; in css. Nothing is working for me. My full code is at github.com.
Please ingnore the colors, I tried to draw it in google drawings so it's not good.
This is how it is:
And this is how I want it to look:
You could use a grid like this. For detail explanations check here
*,
:before,
:after {
box-sizing: border-box;
}
body {
display: grid;
grid-gap: 10px;
grid-template-columns: 60% 40%;
grid-template-areas: "header header" "content cards";
width: 100%;
}
#header {
grid-area: header;
}
#content {
grid-area: content;
}
#cards {
grid-area: cards;
}
<h3 id="header">Welcome to my GitHub Pages website this is where you can learn about me, find my games, and suggest ideas for anything!</h3>
<div id="content">
</div>
<div id="cards" class="cards">
<div id="project1" class="project-card">
<h1>
Web Designer Tycoon
</h1>
<p>This is a idle tycoon like game where you have to make money by making web programs. People buy your web programs for money. If you get better at coding (in the game) then you will get more money for each program you make. Itis currently in the BETA
stage and it will get released after lots of testing and a couple more changes. Thank you for your patience. <span onclick="window.location.href = 'https://codepen.io/hacker19374/project/full/Zyraey/'">Click me to go to Web Designer Tycoon</span></p>
</div>
<div id="project2" class="project-card">
<h1>
Burger Clicker
</h1>
<p>This game is a little bit different. It is a clicker game where you clic and click and click over and over to try to get the most money you can and you can use that money to buy</p>
</div>
</div>
There are multiple ways to achieve this. But since you are using css grid do the following:
Add an extra class of project-card__1 and project-card__2 to the cards and then specify the grid-template-columns in your css.
See the demo below
p {
background-color: #179595;
width: auto;
}
.project-card {
margin: 5px;
width: 25%;
border: 4px solid #00688b;
background-color: #008b8b;
height: 354.33px;
margin-bottom: 50px;
margin-right: 50px;
}
h1 {
text-align: center;
padding-top: 5px;
}
body {
background-image: linear-gradient(270deg, #8b0046, #8b008b);
height: 100vh;
}
span {
cursor: ;
}
.cards {
display: grid;
grid-template-columns: repeat(6, 1fr);
right: 0;
}
.project-card__1 {
grid-column: 5 / 7;
grid-row: 1;
width: 100%;
}
.project-card__2 {
grid-column: 5 / 7;
grid-row: 2;
width: 100%;
}
<h3>
Welcome to my GitHub Pages website this is where you can learn about me,
find my games, and suggest ideas for anything!
</h3>
<div id="cards" class="cards">
<div id="project1" class="project-card project-card__1">
<h1>Web Designer Tycoon</h1>
<p>
This is a idle tycoon like game where you have to make money by making
web programs. People buy your web programs for money. If you get
better at coding (in the game) then you will get more money for each
program you make. Itis currently in the BETA stage and it will get
released after lots of testing and a couple more changes. Thank you
for your patience.
<span
onclick="window.location.href = 'https://codepen.io/hacker19374/project/full/Zyraey/'"
>Click me to go to Web Designer Tycoon</span
>
</p>
</div>
<div id="project2" class="project-card project-card__2">
<h1>Burger Clicker</h1>
<p>
This game is a little bit different. It is a clicker game where you
clic and click and click over and over to try to get the most money
you can and you can use that money to buy
</p>
</div>
</div>
I want to display the first item of the <aside> tag centered at the left.
All other items should be displayed on the right.
I'm using a tool (asciidoctor-html5s) to convert asciidoc to html5.
Therefore I cannot change the HTML.
This is the generated HTML:
<aside class="admonition-block tip" role="doc-tip">
<h6 class="block-title">
<span class="title-label">Tip: </span>
Info
</h6>
<p>Go to this URL to learn more about it:</p>
<div class="ulist">
<ul>
<li><a class="bare" href="http://asciidoc.org">http://asciidoc.org</a></li>
</ul>
</div>
<p>Or you could return to the First Steps or Purpose.</p>
</aside>
And this is an example how it should look like:
Is this possible and if yes, how?
Please do not focus on the Info text inside the h6. I know this is not possible. The question is centered around having the first item on the left an all n other items on the right.
You can make use of the float: left and a bit styling to the height and margin-right
.admonition-block .block-title {
float: left;
margin-right: 2rem;
height: 4rem;
}
<aside class="admonition-block tip" role="doc-tip">
<h6 class="block-title">
<span class="title-label">Tip: </span>
Info
</h6>
<p>Go to this URL to learn more about it:</p>
<div class="ulist">
<ul>
<li><a class="bare" href="http://asciidoc.org">http://asciidoc.org</a></li>
</ul>
</div>
<p>Or you could return to the First Steps or Purpose.</p>
</aside>
If your HTML is going to be exactly like that (e.g. an h6, a p, a div, and then another p), then you can hard code it like this using a combination of CSS Grid and CSS Flexbox styles:
aside {
display: grid;
grid-template-columns: 50px 320px; /* picked these sizes at random; feel free to change */
grid-gap: 5px; /* picked these sizes at random; feel free to change */
}
aside > * {
grid-column: 2;
}
h6 {
grid-column: 1;
grid-row: 1 / 5;
display: flex;
visibility: hidden;
align-items: center;
justify-content: center;
}
h6 span {
visibility: visible;
}
p::before {
content:"Info";
position: absolute;
top: 5px;
font-style: italic;
}
aside p:first-of-type {
grid-row: 1;
}
aside div {
grid-row: 2;
}
aside p:last-of-type {
grid-row: 3;
}
<aside class="admonition-block tip" role="doc-tip">
<h6 class="block-title">
<span class="title-label">Tip: </span>
Info
</h6>
<p>Go to this URL to learn more about it:</p>
<div class="ulist">
<ul>
<li><a class="bare" href="http://asciidoc.org">http://asciidoc.org</a></li>
</ul>
</div>
<p>Or you could return to the First Steps or Purpose.</p>
</aside>
I hid the "Info" text node in markup and added it in CSS as a pseudo-element. It's not selectable that way, but the trade of is it can be positioned the way you want it to.
Maybe there is a way in your converter software to disallow naked text nodes like that (it's considered bad practice to have atomic text not wrapped in an element if you want to style/select it).
I'm trying to assemble this webpage with the format of
name picture info
name picture info
name picture info
name picture info
Within the main part of the code.
When ever i activate the grid it automatically places the element in
Name 4 times side by side
pic
info
And I'm unable to change the position.
Here is the HTML code:
.head {
font-size: 100px;
font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
font-weight: bold;
padding: 25px 50px 25px;
background-color: orange;
color: blue;
text-shadow: white 5px 5px 5px;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: blue;
}
li {
float: left;
}
li a {
display: block;
color: orange;
text-align: center;
padding: 14px 20px;
}
li a:hover:not(.active) {
background-color: rgb(255, 255, 255);
}
.active {
background-color: white;
}
img {
border: 1px solid rgb(105, 105, 105);
height: 200px;
padding: 10px;
width: 300px;
}
img:hover {
box-shadow: 0 0 2px 1px rgba(186, 0, 177, 0.5);
}
.mainweb {
display: grid;
grid-template-columns: auto auto auto;
grid-template-rows: auto auto auto auto;
grid-gap: 10px;
padding: 10px;
background-color: orange;
}
.mainweb .name {
font-weight: bold;
font-size: 25px;
}
.footer {
text-align: center;
background-color: blue;
color: white;
}
#Sasuke.name {
grid-column: 1 / 2;
grid-row: 2 / 3;
}
#Sasuke .pic {
grid-row: 2 / 3;
grid-column: 2 / 3;
}
#Sasuke .info {
grid-row: 2 / 3;
grid-column: 3 / 4;
}
.Kakashi .name {
grid-column: ;
grid-row: 3 / 4;
}
.Kakashi .pic {
grid-row: 3 / 4;
grid-column: ;
}
.Kakashi .info {
grid-row: 3 / 4;
grid-column: ;
}
.Gaara .name {
grid-column: ;
grid-row: 4 / 5;
}
.Gaara .pic {
grid-row: 4 / 5;
grid-column: ;
}
.footer {
text-align: center;
}
<link rel="stylesheet" type="text/css" href="css.css">
<div class="head">
<header>Naruto Wiki</header>
</div>
<div class="menu">
<ul>
<li><a class="active" href="#home">Home</a></li>
<li>About</li>
<li>Donate</li>
<li>Contact Us</li>
</ul>
</div>
<div class="container">
<div class="mainweb">
<div id="Naruto">
<p class="name">Naruto Uzamaki</p>
<a href="/Graphics/Naruto.png">
<img class="pic" src="/Graphics/Naruto.png" alt="Naruto">
</a>
<p class="info">
Naruto Uzumaki (うずまきナルト, Uzumaki Naruto) is a shinobi of Konohagakure's Uzumaki clan. He became the jinchūriki of the Nine-Tails on the day of his birth — a fate that caused him to be shunned by most of Konoha throughout his childhood. After joining Team
Kakashi, Naruto worked hard to gain the village's acknowledgement all the while chasing his dream to become Hokage. In the following years, through many hardships and ordeals, he became a capable ninja regarded as a hero both by the villagers,
and soon after, the rest of the world, becoming known as the Hero of the Hidden Leaf (木ノ葉隠れの英雄, Konohagakure no Eiyū, Literally meaning: Hero of the Hidden Tree Leaves). He soon proved to be one of the main factors in winning the Fourth Shinobi
World War, leading him to achieve his dream and become the village's Seventh Hokage (七代目火影, Nanadaime Hokage, Literally meaning: Seventh Fire Shadow).
</p>
</div>
<div id="Sasuke">
<p class="name">Sasuke Uchiha</p>
<a href="/Graphics/Sasuke.png">
<img id src="/Graphics/Sasuke.png" alt="Sasuke">
</a>
<p class="info">
Sasuke Uchiha (うちはサスケ, Uchiha Sasuke) is one of the last surviving members of Konohagakure's Uchiha clan. After his older brother, Itachi, slaughtered their clan, Sasuke made it his mission in life to avenge them by killing Itachi. He is added to Team
7 upon becoming a ninja and, through competition with his rival and best friend, Naruto Uzumaki, Sasuke starts developing his skills. Dissatisfied with his progress, he defects from Konoha so that he can acquire the strength needed to exact his
revenge. His years of seeking vengeance and his actions that followed become increasingly demanding, irrational and isolates him from others, leading him to be branded as an international criminal. After learning the truth of his brother's sacrifice,
later proving instrumental in ending the Fourth Shinobi World War, and being happily redeemed by Naruto, Sasuke decides to return to Konoha and dedicate his life to help protect the village and its inhabitants, becoming referred to as the "Supporting
Kage" (支う影, Sasaukage, Literally meaning: Supporting Shadow).
</p>
</div>
<div id="Kakashi">
<p class="name">Kakashi Hatake</p>
<a href="/Graphics/Kakashi.jpg">
<img src="/Graphics/Kakashi.jpg" alt="Kakashi">
</a>
<p class="info">
Kakashi Hatake (はたけカカシ, Hatake Kakashi) is a shinobi of Konohagakure's Hatake clan. Famed as Kakashi of the Sharingan (写輪眼のカカシ, Sharingan no Kakashi), he is one of Konoha's most talented ninja; regularly looked to for advice and leadership despite his
personal dislike of responsibility. To his students on Team 7, Kakashi teaches the importance of teamwork, a lesson he received, along with the Sharingan, from his childhood friend, Obito Uchiha. After the Fourth Shinobi World War, Kakashi becomes
Konoha's Sixth Hokage (六代目火影, Rokudaime Hokage, Literally meaning: Sixth Fire Shadow).
</p>
</div>
<div id="Gaara">
<p class="name">Gaara</p>
<a href="/Graphics/Gaara.png">
<img src="/Graphics/Gaara.png" alt="Gaara">
</a>
<p class="info">
Gaara (我愛羅) is a shinobi of Sunagakure. He was made the jinchūriki of the One-Tailed Shukaku before he was born, causing the villagers of Suna to fear him as a monster. With nobody to connect to, Gaara grew up hating the world and looking out only for
himself, giving his life meaning by killing anyone he came across. After being defeated by Naruto Uzumaki — a jinchūriki like himself who found strength in his friendships — Gaara starts emulating him. He becomes Suna's Fifth Kazekage (五代目風影,
Godaime Kazekage, Literally meaning: Fifth Wind Shadow) so that he can protect the village and all those who live there, dispelling the fears he cast on the villagers.
</p>
</div>
</div>
</div>
<div class="footer">
All information has been provided by https://naruto.fandom.com/wiki/Narutopedia Naruto Wiki | 2020
</div>
Right now, your grid only apply on the child elements of your .mainweb class.
So only
<div id="naruto">..</div>
<div id="Sasuke">..</div>
<div id="Kakashi">..</div>
<div id="Gaara">..</div>
what you can do is to apply your grid on each inner children and making each children just display: block if you want them one below the other.
If you want to keep the display: grid
then you can make you css like
Change your .mainweb by .mainweb>div to apply to all children
.mainweb>div {
display: grid;
grid-template-columns: auto auto auto;
grid-template-rows: auto;
grid-gap: 10px;
padding: 10px;
background-color: orange;
}
Or other solution is simply by using display: flex
it will keep your content more responsive.
.mainweb>div {
display: flex;
align-items: center;
justify-content: center;
padding: 10px;
background-color: orange;
}
Change html like this:
<div id="Naruto">
<div class="leftSection">
<p class="name">Naruto Uzamaki</p>
<a href="/Graphics/Naruto.png">
<img class="pic" src="/Graphics/Naruto.png" alt="Naruto">
</a>
</div>
<p class="info">
Naruto Uzumaki (うずまきナルト, Uzumaki Naruto) is a shinobi of Konohagakure's Uzumaki clan. He became the jinchūriki of the Nine-Tails
on the day of his birth — a fate that caused him to be shunned by most of Konoha throughout his childhood. After
joining Team Kakashi, Naruto worked hard to gain the village's acknowledgement all the while chasing his dream
to become Hokage. In the following years, through many hardships and ordeals, he became a capable ninja regarded
as a hero both by the villagers, and soon after, the rest of the world, becoming known as the Hero of the Hidden
Leaf (木ノ葉隠れの英雄, Konohagakure no Eiyū, Literally meaning: Hero of the Hidden Tree Leaves). He soon proved to be
one of the main factors in winning the Fourth Shinobi World War, leading him to achieve his dream and become
the village's Seventh Hokage (七代目火影, Nanadaime Hokage, Literally meaning: Seventh Fire Shadow).
</p>
</div>
And add css :
.leftSection{
width: 25%;
float: left;
}
.mainweb .name {
font-weight: bold;
font-size: 25px;
display: inline;
}
p.info{
width: 70%;
float: right;
}
I'm trying to create the following header using CSS:
This is my attempt so far using CSS grid:
HTML:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="jumbotron">
<div class="grid">
<div class="a">
28
</div>
<div class="b">
clubs
</div>
<div class="c">
/
</div>
<div class="d">
48
</div>
<div class="e">
virtual
</div>
<div class="f">
gyms
</div>
</div>
CSS:
.jumbotron {
background: linear-gradient(141deg, rgb(0,223,179), rgb(34,198,252));
}
.grid {
display:grid;
grid-template-columns: 50px 50px 50px 50px;
color:white;
}
.a{
grid-column: 1;
grid-row: 1/span 2;
font-size:35px;
}
.b{
grid-column: 2;
grid-row: 2;
}
.c{
grid-column: 3;
grid-row: 1/span 2;
font-size:35px;
}
.d {
grid-column: 4;
grid-row:1/span 2;
font-size:35px;
}
.e {
grid-column:5;
grid-row:1;
}
.f {
grid-column:5;
grid-row:2;
}
https://codepen.io/anon/pen/jGKwEL
I don't know if I'm overthinking it but this is the best solution I can come up with to make the stacked text somewhat align. It's very tedicous however to make look exactly like the picture and it includes a lot of CSS classes. Any other way to approach this or am I on the right track?
Edit: this what I ended up doing with help of the answers to this question: https://codepen.io/anon/pen/jGKwEL
You don't have to use CSS grid: just because it is available does not mean that you have to use it, or that it is relevant for your usecase. In your layout requirement, it is more suitable to use a mix of display: flex and some simple relative positioning to get the baseline of the text to line up.
First, with the markup, you can simply use a <ul>:
<ul>
<li>
<span class="count">28</span>
<span class="text">clubs</span>
</li>
<li>
<span class="count">48</span>
<span class="text">virtual<br />gyms</span>
</li>
</ul>
With regards to styling:
use display: flex on the <ul> parent so that the child elements will be arranged horizontally
the slanted border can simply be emulated using border-right, and we disable it on the last child using the li:last-child selector
the baseline alignment of the text/description next to the number requires manual adjustment, just play around with some values with bottom offset
use transform: skew(...) to slant your text uniformly, instead of relying on italics. This will lead to uniform slanting of the text and the separators :)
The outcome will look something like this:
Here is a quick proof-of-concept I have whipped up, based on the suggested changes listed above:
.jumbotron {
background: linear-gradient(141deg, rgb(0, 223, 179), rgb(34, 198, 252));
}
ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
justify-content: flex-end; /* Align to right */
}
ul li {
transform: skew(-10deg);
border-right: 3px solid #fff;
padding: 0 20px;
display: flex;
align-items: flex-end; /* Align to bottom */
}
ul li:last-child {
border: none;
}
ul li span {
color: white;
line-height: 1em;
font-weight: bold;
}
ul li span.count {
font-size: 45px;
margin-right: 10px;
}
ul li span.text {
text-transform: uppercase;
position: relative;
bottom: .35em; /* Adjust this value manually */
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="jumbotron">
<ul>
<li>
<span class="count">28</span>
<span class="text">clubs</span>
</li>
<li>
<span class="count">48</span>
<span class="text">virtual<br />gyms</span>
</li>
<li>
<span class="count">33</span>
<span class="text">active<br />players</span>
</li>
<li>
<span class="count">15</span>
<span class="text">inactive<br />players</span>
</li>
</ul>
</div>
Here's an example using a list, :after for styling the slashes, and spans for the different parts of one item. You can just duplicate the <li>'s to add more items, without the need for futher classes. I hope it's the way you need it :)
You could use flexbox as an alternative, but I personally think there is no need for it in this case.
https://codepen.io/anon/pen/YrvQMp