Change width of a card in HTML - html

I'm a beginner to HTML and I'm making my first website.
.header {
text-align: center;
color: #ffffff;
font-family: tahoma;
}
body {
background: linear-gradient(to top right, #39B59D, #139BDA, #0066FF, #061CFF);
background-attachment: fixed;
}
.img {
text-align: center;
}
.card {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
transition: 0.3s;
border-radius: 10px;
color: #ffffff;
width: 500;
}
.card:hover {
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
}
.container {
padding: 2px 16px;
color: #ffffff width=500;
}
<div class="card">
<p style="text-align:center;"><img src="https://image.ibb.co/nAaqJG/rappatic.png" alt="rappatic"></p>
<div class="container">
<h2 class="header">Hi, I'm rappatic.</h2>
<p class="header">I code when I feel like it.</p>
<p> </p>
</div>
</div>
As you can see, when it is run, the code shows a card that goes across almost the full width of the page. I think this is kind of ugly, though. Is there a way to make the card only stretch across, say, 50 or 60 percent of the page? Or, if that's not possible, make a set amount of pixels?
Thanks in advance.

You are simpy missing the unit in the value of the width so you have to do this :
width: 500px;
.header {
text-align: center;
color: #ffffff;
font-family: tahoma;
}
body {
background: linear-gradient(to top right, #39B59D, #139BDA, #0066FF, #061CFF);
background-attachment: fixed;
}
.img {
text-align: center;
}
.card {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
transition: 0.3s;
border-radius: 10px;
color: #ffffff;
width: 500px;
margin: auto;
}
.card:hover {
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
}
.container {
padding: 2px 16px;
color: #ffffff;
}
<div class="card">
<p style="text-align:center;"><img src="https://image.ibb.co/nAaqJG/rappatic.png" alt="rappatic"></p>
<div class="container">
<h2 class="header">Hi, I'm rappatic.</h2>
<p class="header">I code when I feel like it.</p>
<p> </p>
</div>
</div>
And if you want 50% you have to simply make it width:50% and you may add margin:auto for centering
.header {
text-align: center;
color: #ffffff;
font-family: tahoma;
}
body {
background: linear-gradient(to top right, #39B59D, #139BDA, #0066FF, #061CFF);
background-attachment: fixed;
}
.img {
text-align: center;
}
.card {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
transition: 0.3s;
border-radius: 10px;
color: #ffffff;
width: 50%;
margin: auto;
}
.card:hover {
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
}
.container {
padding: 2px 16px;
color: #ffffff;
}
<div class="card">
<p style="text-align:center;"><img src="https://image.ibb.co/nAaqJG/rappatic.png" alt="rappatic"></p>
<div class="container">
<h2 class="header">Hi, I'm rappatic.</h2>
<p class="header">I code when I feel like it.</p>
<p>&nbsp</p>
</div>
</div>

for center this card use this code in your .card section:
margin-left:auto;
margin-right:auto;

To set the width of something, you can use the width property:
width: 500px;
width: 50%;
width: 50vw;
There are different units you can use, such as px (pixels) % (percentage of page width) and vw (percentage of window width). There may also be others, but those are the ones I know of.

Related

How can I build this badge with CSS?

I would like to add a badge to my navbar. It should look like the one in the image below.
My current Approach
I use two divs for this. One above and one below. The lower one should do the rounding.
My approach works not so good and I find it more hacky as good.
Question
I wonder if there is a better, cleaner way? Can somebody help me?
Thanks in advance, Max
* {
margin: 0;
padding: 0;
font-family: Verdana,Geneva,sans-serif;
}
body {
background-color: #f1f1f1;
}
nav {
height: 80px;
background-color: white;
padding:10px 80px;
box-sizing: border-box;
display: flex;
justify-content: space-between;
}
.badge-top {
background: #ccc;
margin-top:-10px;
height:25px;
padding-top:20px;
padding-left:5px;
padding-right:5px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
font-size:0.8rem;
font-weight:bold;
width:30px;
text-align: center;
}
.badge-bottom {
background: #ccc;
color:#ccc;
border-radius:50px;
margin-top:-10px;
}
.badge-bottom:after {
content: '.';
}
<nav>
<div>logo</div>
<div>
<button class="btn nav-btn">SUBMIT</button>
</div>
<div>
<div class="badge-top">123</div>
<div class="badge-bottom"></div>
</div>
</nav>
Really no reason for multiple elements. Note that I've put box-sizing: border-box on your stylesheet. This makes sizing calculations much easier by including padding, etc. Most layout libraries do this.
* {
margin: 0;
padding: 0;
font-family: Verdana, Geneva, sans-serif;
box-sizing: border-box;
}
body {
background-color: #f1f1f1;
}
nav {
height: 80px;
background-color: white;
padding: 10px 80px;
box-sizing: border-box;
display: flex;
justify-content: space-between;
}
.badge {
background: #ccc;
width: 40px;
height: 60px;
padding-top: 26px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
font-size: 0.8rem;
font-weight: bold;
text-align: center;
border-radius: 0 0 20px 20px;
}
<nav>
<div>logo</div>
<div>
<button class="btn nav-btn">SUBMIT</button>
</div>
<div class="badge">
123
</div>
</nav>
div {
position: relative;
width: 2.5rem;
height: 4.5rem;
border-bottom-left-radius: 1.25rem;
border-bottom-right-radius: 1.25rem;
box-shadow: 0px 3px 5px rgba(0, 0, 0, 0.4);
background-color: #bfbfbf;
}
span {
position: absolute;
bottom: 1rem;
left: 50%;
transform: translate(-50%);
color: #222;
font-weight: bold;
}
<div>
<span>420</span>
</div>

HTML/CSS Make a Progress Bar

I am trying to make a progress bar as is shown here in the about section however I am just lost.
I can make a bar and a box but neither look anywhere near as good as that and I cannot for the life of me get them to be beside each other with equal height. I just keep getting something along the lines of
What I am trying to achieve in case website goes down:
.myskills {
width: 45vw;
height: 100%;
background: red;
margin: 1em;
}
.skillbarContainer {
display: flex;
justify-content: center;
height: 2vh;
}
.skillName {
background-color: blue;
width: 5vw;
float: left;
height: 100%;
font-size: 2em;
}
.meter {
float: left;
width: 80%;
height: 100%;
/* Can be anything */
position: relative;
background: #555;
padding: 3px;
}
.meter>span {
display: block;
height: 100%;
background-color: hotpink;
box-shadow: inset 0 2px 9px rgba(255, 255, 255, 0.3), inset 0 -2px 6px rgba(0, 0, 0, 0.4);
position: relative;
overflow: hidden;
}
<div class="myskills">
<div class="skillbarContainer">
<div class="skillName">HTML</div>
<div class="meter">
<span style="width: 80%"></span>
</div>
</div>
</div>
This code below will give you the percentage sign on the right of the percentage bar. A lot of this is purely layering with hmtl/css.
Here are some links for layering and z-index:
https://www.tutorialspoint.com/css/css_layers.htm#:~:text=The%20CSS%20layers%20refer%20to,element%20should%20come%20at%20bottom.
https://www.w3schools.com/cssref/pr_pos_z-index.asp
https://css-tricks.com/almanac/properties/z/z-index/
.myskills {
width: 90%%;
background: red;
margin: 1em;
}
.skillbarContainer {
display: flex;
}
.skillLevel{
right: 0;
font-size: 1.7em;
position: absolute;
}
.skillName {
background-color: rgb(77, 252, 208);
float: left;
font-size: 2em;
}
.meter {
float: left;
width: 100%;
/* Can be anything */
position: relative;
background: rgb(218, 217, 217);
padding: 3px;
}
.meter>span {
display: block;
height: 100%;
background-color: rgb(31, 134, 117);
box-shadow: inset 0 2px 9px rgba(255, 255, 255, 0.3), inset 0 -2px 6px rgba(0, 0, 0, 0.4);
}
<div class="myskills">
<div class="skillbarContainer">
<div class="skillName">HTML</div>
<div class="meter">
<span style="width: 80%"><span class="skillLevel">90%</span></span>
</div>
</div>
</div>
Well, IMO you should use less vh and vw. Your font simply defines the height and the width of the text part. By removing them, you get something as you want as I understood (I also removed useless properties) :
.myskills {
width: 45vw;
background: red;
margin: 1em;
}
.skillbarContainer {
display: flex;
}
.skillName {
background-color: blue;
font-size: 2em;
}
.meter {
float: left;
width: 100%;
/* Can be anything */
position: relative;
background: #555;
padding: 3px;
}
.meter>span {
display: block;
height: 100%;
background-color: hotpink;
box-shadow: inset 0 2px 9px rgba(255, 255, 255, 0.3), inset 0 -2px 6px rgba(0, 0, 0, 0.4);
}
<div class="myskills">
<div class="skillbarContainer">
<div class="skillName">HTML</div>
<div class="meter">
<span style="width: 80%"></span>
</div>
</div>
</div>
Now, if it was my progress bar I'd use flex instead of width for .meter, I'd take a smaller font size and put padding to the text :
.myskills {
width: 45vw;
background: red;
margin: 1em;
}
.skillbarContainer {
display: flex;
}
.skillName {
background-color: blue;
font-size: 18px;
padding: 3px 10px;
}
.meter {
float: left;
flex: 1;
/* Can be anything */
position: relative;
background: #555;
padding: 3px;
}
.meter>span {
display: block;
height: 100%;
background-color: hotpink;
box-shadow: inset 0 2px 9px rgba(255, 255, 255, 0.3), inset 0 -2px 6px rgba(0, 0, 0, 0.4);
}
<div class="myskills">
<div class="skillbarContainer">
<div class="skillName">HTML</div>
<div class="meter">
<span style="width: 80%"></span>
</div>
</div>
</div>

How to create a card with image as background in CSS diagonally sliced

I am trying to create a Card in HTML/CSS, that looks like:
BUT, what I want exactly is that the background, instead of being just grey like it is, is an image instead.
Here is what I've tried: JsFiddle
HTML:
<div class="card">
<img src="https://www.washingtonpost.com/resizer/9YWv-qOa9uW7CQZ9UGiW23eTZzU=/1484x0/arc-anglerfish-washpost-prod-washpost.s3.amazonaws.com/public/BTCNJJN2Y43KPHPXPQWPASXRKM.jpg" alt="Avatar" class='image'>
<div class="container">
<h3>John Doe</h3>
<p>Architect & Engineer</p>
</div>
</div>
CSS:
.card {
border: 1px solid #dadada;
box-shadow: 4px 4px 8px 0 rgba(0, 0, 0, 0.2);
transition: 0.2s;
width: 50%;
}
.card h3 {
padding: 2px;
margin: 8px 0;
}
.image {
width:100%;
clip-path: polygon(0 0, 100% 0, 100% 42%, 0 23%);
}
As you can see it works, but the problem is that there's space in between the image and the 'John Doe'.
I would like to know how to remove the space between the image and the John Doe.
Thanks
Here is a simple solution with css transform.
.wrapper {
position: relative;
width: 280px;
height: 350px;
background: url('https://upload.wikimedia.org/wikipedia/commons/e/e1/FullMoon2010.jpg') 0 0 no-repeat;
background-size: cover;
overflow: hidden;
}
.box {
position: absolute;
bottom: 0;
width: 100%;
height: 50%;
background: #cdcdcd;
}
.content {
position: absolute;
z-index: 10;
padding: 15px;
box-sizing: border-box;
}
.folder {
position: absolute;
top: -20px;
left: -10px;
width: 120%;
height: 60px;
background: #cdcdcd;
transform: rotate(8deg);
}
<div class="wrapper">
<div class="box">
<div class="content">Here is my content.</div>
<div class="folder"></div>
</div>
</div>
You can add the following to your css:
.container {
position: absolute;
top: 150px;
}
You will see that your card's height is influenced. You can the just give your card a height that you desire, like this:
.card {
height: 300px //this is your prefered height
}
.card {
border: 1px solid #dadada;
box-shadow: 4px 4px 8px 0 rgba(0, 0, 0, 0.2);
transition: 0.2s;
width: 50%;
height:200px;
position:relative;
}
.card h3 {
padding: 2px;
margin: 8px 0;
/* line-height: 20px !important;
font-size: 18px !important;
font-weight: 500 !important; */
}
.card:hover {
box-shadow: 8px 8px 16px 0 rgba(0, 0, 0, 0.2);
}
.card .container {
padding: 2px 14px;
position: absolute;
top: 45%;
}
.card p {
margin: 14px 0;
}
.card img {
position:absolute
}
//that's all..
Rely on background and you will have better support and less code:
.card {
border: 1px solid #dadada;
box-shadow: 4px 4px 8px 0 rgba(0, 0, 0, 0.2);
transition: 0.2s;
padding:100px 10px 5px;
width: 50%;
background:
linear-gradient(to bottom left,transparent 49.5%,#fff 50%) 0 50px/100% 100px,
linear-gradient(#fff,#fff) bottom/100% calc(100% - 150px),
url(https://www.washingtonpost.com/resizer/9YWv-qOa9uW7CQZ9UGiW23eTZzU=/1484x0/arc-anglerfish-washpost-prod-washpost.s3.amazonaws.com/public/BTCNJJN2Y43KPHPXPQWPASXRKM.jpg) top/100% auto no-repeat;
background-repeat:no-repeat;
}
.card h3 {
padding: 2px;
margin: 8px 0;
}
<div class="card">
<h3>John Doe</h3>
<p>Architect & Engineer</p>
</div>

Height: 100%; not working with Flex Box

Problem :
To make a vertical line which separates two objects but it won't appear because it doesn't have height although I added height: 100%.
Why isn't it filling up the space from the top to the bottom of my
div? Is it because .card-body has height: auto?
Tried Cases :
I already tried adding width, disabling flex-box but nothing of that worked, but if I add a specific height to my .card-body it works.
Do you
know a solution how it could work without adding a specific height?
.card {
margin-bottom: 30px;
}
.card > .card-header {
font-weight: 500;
text-transform: uppercase;
font-size: 15px;
margin-bottom: 6px;
}
.card > .card-header.light {
color: #fff;
}
.card > .card-body {
background-color: #fff;
border-radius: 12px;
padding: 24px;
-webkit-box-shadow: -2px 4px 34px 1px rgba(0, 0, 0, 0.15);
-moz-box-shadow: -2px 4px 34px 1px rgba(0, 0, 0, 0.15);
box-shadow: -2px 4px 34px 1px rgba(0, 0, 0, 0.15);
}
.card > .card-body.server-status {
display: flex;
align-items: center;
}
.card > .card-body.server-status > .counter {
width: 50%;
font-weight: 500;
color: #95a0b7;
font-size: 32px;
display: flex;
flex-direction: column;
align-items: center;
}
.card > .card-body.server-status > .counter > span {
font-size: 15px!important;
color: #0d2c4a!important;
text-transform: capitalize;
}
<div class="card">
<div class="card-header light">
Active Services
</div>
<div class="card-body server-status">
<div class="counter">
7/9
<span>
Servers running
</span>
</div>
<div style="border-left:1px solid #0d2c4a;height:100%;"></div>
<div class="chart">
</div>
</div>
</div>
You need to make it stretch since your flex container is align-items: center
You can remove the height 100%, I added a class to the divider, it comes down to this
.divider {
align-self: stretch;
}
If you did not have the align center, it would of worked by default because the align items defaults to stretch but since you changed it to center and your divider has no content so the line does not show. Setting the divider itself to stretch again solves the problem and no need for the extra css
.card {
margin-bottom: 30px;
}
.card>.card-header {
font-weight: 500;
text-transform: uppercase;
font-size: 15px;
margin-bottom: 6px;
}
.card>.card-header.light {
color: #fff;
}
.card>.card-body {
background-color: #fff;
border-radius: 12px;
padding: 24px;
-webkit-box-shadow: -2px 4px 34px 1px rgba(0, 0, 0, 0.15);
-moz-box-shadow: -2px 4px 34px 1px rgba(0, 0, 0, 0.15);
box-shadow: -2px 4px 34px 1px rgba(0, 0, 0, 0.15);
}
.card>.card-body.server-status {
display: flex;
align-items: center;
}
.card>.card-body.server-status>.counter {
width: 50%;
font-weight: 500;
color: #95a0b7;
font-size: 32px;
display: flex;
flex-direction: column;
align-items: center;
}
.card>.card-body.server-status>.counter>span {
font-size: 15px!important;
color: #0d2c4a!important;
text-transform: capitalize;
}
.divider {
align-self: stretch;
}
<div class="card">
<div class="card-header light">
Active Services
</div>
<div class="card-body server-status">
<div class="counter">
7/9
<span>
Servers running
</span>
</div>
<div class="divider" style="border-left:1px solid #0d2c4a;"></div>
<div class="chart"></div>
</div>
</div>
Also you can add this css property to your css ...
.counter{
border-right: 1px solid black;
}
Instead of using a <div>, try using an <hr> and rotating it with css. Something along the lines of:
hr {
display: block;
margin-top: 0.5em;
margin-bottom: 0.5em;
margin-left: auto;
margin-right: auto;
border-style: inset;
border-width: 1px;
transform: rotate(90deg);
}
See this documentation for help: https://www.w3schools.com/tags/tag_hr.asp

Border radius circle

I've this code :
span p {
margin: 0;
}
span {
background-color: red;
display: inline-block;
border-radius: 50%;
}
<span>
<p>25</p>
<p>08</p>
</span>
I want to make a perfect circle on my span. I try a border-radius: 50%; but it does not work.
Thanks for the help !
You can do this by giving the span a fixed width and height:
span p {
margin: 0;
}
span {
background-color: red;
display: inline-block;
border-radius: 50%;
width: 50px;
height: 50px;
text-align: center;
}
<span>
<p>25</p>
<p>08</p>
</span>
You need a predefined width and height on the span to be able to make it round.
span p {
margin: 0;
}
span {
background-color: red;
display: inline-block;
border-radius: 50%;
width:40px;
height:40px;
padding-left:10px;
box-sizing: border-box;
}
<span>
<p>25</p>
<p>08</p>
</span>
add line-height and width:
span {
background-color: #F00;
display: inline-block;
border-radius: 50%;
width: 50px;
line-height: 25px;
text-align: center;
}
Use this code.
HTML:
<span>
<p>25</p>
</span>
<span>
<p>08</p>
</span>
CSS:
span {
background-color: red;
display: inline-block;
border-radius: 50%;
width: 50px;
height: 50px;
text-align: center;
}
border-radius: 50% and padding
document.addEventListener('DOMContentLoaded', () => {
let el = document.querySelector('#wrapper .container');
setTimeout(() => (el.style.marginTop = '20px'), 500);
}, false);
#wrapper {
display: flex;
justify-content: center;
}
#wrapper .container {
display: flex;
flex-direction: column;
align-items: center;
padding: 6px 16px;
font-family: sans-serif;
font-size: 15px;
font-weight: 500;
border-radius: 50%;
box-shadow: 0 5px 5px -3px rgba(0, 0, 0, 0.2),
0 8px 10px 1px rgba(0, 0, 0, 0.14),
0 3px 14px 2px rgba(0, 0, 0, 0.12);
transition: margin-top 650ms ease-out, box-shadow 120ms, transform 120ms;
will-change: margin-top, box-shadow, transform;
user-select: none;
cursor: pointer;
}
#wrapper .container:hover:not(:active) {
box-shadow: 0 5px 4px -4px rgba(0, 0, 0, 0.1),
0 2px 10px 0px rgba(0, 0, 0, 0.08),
0 0px 10px 0px rgba(0, 0, 0, 0.08);
}
#wrapper .container:active {
transform: scale(1.4) translateY(5px);
box-shadow: 0 9px 11px -5px rgba(0, 0, 0, 0.2),
0 18px 28px 2px rgba(0, 0,0 , 0.14),
0 7px 34px 6px rgba(0, 0, 0, 0.12);
}
<div id="wrapper">
<div class="container">
<span>10</span>
<span>3</span>
</div>
</div>
It looks like you incorrectly nested paragraph elements inside of span, which is against HTML5 spec, as span is being defined there as an element, which Content Model is described as Phrasing Content, and that:
Most elements that are categorized as Phrasing Content can only contain elements that are themselves categorized as phrasing content, not any flow content.
And because paragraph element doesn't belong to Phrasing Content list, you can use div instead of span for this purpose, only if you care to be semantically correct.
So coming back to your problem, it can be rewritten as so:
HTML:
<div>
<p>25</p>
<p>08</p>
</div>
CSS:
p {
margin: 0;
text-align:center;
}
div {
background-color: red;
display: inline-block;
border-radius: 50%;
width:50px;
height:50px;
line-height:25px;
}
Where general rule for achieving the circle by using border radius set to 50%, is that you need to make sure that content of such element has the same width and height. You can get that by fixing these values in your css.
Here is JsFiddle presenting that.