I have a background with an image, in this bakground I have 3 images with 3 numbers. I would like for each number, center the number with the image.
I am stuck with the property margin-left
.background-picture-red{
height: 130px;
width: 100%;
position: absolute;
background-image: url(https://i.ibb.co/jVWdfG4/bg-2.jpg);
}
.picture01{
border: 1px solid #fff;
padding: 10px;
border-radius: 50%;
background-color: rgba(224,0,0,0.30);
float:left;
margin-top: 10px;
margin-left: 50px;
z-index: 1;
position: relative;
}
.picture01-title{
font-family: 'Questrial', sans-serif;
font-size: 16px;
color: white;
margin-left: 50px;
margin-top: 100px;
position: absolute;
}
.picture02{
border: 1px solid #fff;
padding: 10px;
border-radius: 50%;
background-color: rgba(224,0,0,0.30);
float:left;
margin-top: 10px;
margin-left: 60px;
z-index: 1;
position: relative;
}
.picture02-title{
font-family: 'Questrial', sans-serif;
font-size: 16px;
color: white;
margin-left: 50px;
margin-top: 100px;
position: absolute;
}
.picture03{
border: 1px solid #fff;
padding: 10px;
border-radius: 50%;
background-color: rgba(224,0,0,0.30);
float:left;
margin-top: 10px;
margin-left: 70px;
z-index: 1;
position: relative;
}
.picture03-title{
font-family: 'Questrial', sans-serif;
font-size: 16px;
color: white;
margin-left: 10px;
margin-top: 100px;
position: absolute;
}
<div class="background-picture-red">
<img class="picture01" src="https://i.ibb.co/n3fv0YY/bitcoin34.png">
<span class="picture01-title">138</span>
<img class="picture02" src="https://i.ibb.co/qRSr1Wr/bitcoin46.png">
<span class="picture02-title">258</span>
<img class="picture03" src="https://i.ibb.co/BwT7gHz/bitcoin68.png">
<span class="picture03-title">303</span>
</div>
Here is a working example where I added to each title:
margin-left: -43px;
transform:translateX(-50%);
margin-left: -43px : because your image size is 86px so -43px will be placed in the middle of the image
translateX(-50%) : so the text will be centered depending of its own size
.background-picture-red{
height: 130px;
width: 100%;
position: absolute;
background-image: url(https://i.ibb.co/jVWdfG4/bg-2.jpg);
}
.picture01{
border: 1px solid #fff;
padding: 10px;
border-radius: 50%;
background-color: rgba(224,0,0,0.30);
float:left;
margin-top: 10px;
margin-left: 50px;
z-index: 1;
position: relative;
}
.picture01-title{
font-family: 'Questrial', sans-serif;
font-size: 16px;
color: white;
margin-left: -43px;
transform:translateX(-50%);
margin-top: 100px;
position: absolute;
}
.picture02{
border: 1px solid #fff;
padding: 10px;
border-radius: 50%;
background-color: rgba(224,0,0,0.30);
float:left;
margin-top: 10px;
margin-left: 60px;
z-index: 1;
position: relative;
}
.picture02-title{
font-family: 'Questrial', sans-serif;
font-size: 16px;
color: white;
margin-left: -43px;
transform:translateX(-50%);
margin-top: 100px;
position: absolute;
}
.picture03{
border: 1px solid #fff;
padding: 10px;
border-radius: 50%;
background-color: rgba(224,0,0,0.30);
float:left;
margin-top: 10px;
margin-left: 70px;
z-index: 1;
position: relative;
}
.picture03-title{
font-family: 'Questrial', sans-serif;
font-size: 16px;
color: white;
margin-left: -43px;
transform:translateX(-50%);
margin-top: 100px;
position: absolute;
}
<div class="background-picture-red">
<img class="picture01" src="https://i.ibb.co/n3fv0YY/bitcoin34.png">
<span class="picture01-title">138</span>
<img class="picture02" src="https://i.ibb.co/qRSr1Wr/bitcoin46.png">
<span class="picture02-title">258</span>
<img class="picture03" src="https://i.ibb.co/BwT7gHz/bitcoin68.png">
<span class="picture03-title">303</span>
</div>
But maybe you should use flexbox to do that kind of thing.
Related
Here, I'm making a food pyramid that has interactive buttons that allow you to add and take away the amount your of food your eating in each section of the pyramid. But, I'm not sure how to make the counter for each sector (the first triangle and then each trapezoid) overlap the circle its meant to be on. For example in the first sector (the triangle) there meant to be a circle in the middle of it that contains the counter on top of it and then a plus sign on the right, and a minus sign on the left.
.triangle {
border-bottom: 150px solid #FF6347;
border-left: 100px solid transparent;
border-right: 100px solid transparent;
height: 0;
width: 0;
margin-left: auto;
margin-right: auto;
white-space: nowrap;
display: block;
}
.trapezoid {
border-bottom: 100px solid #f58c57;
border-left: 60px solid transparent;
border-right: 60px solid transparent;
height: 0;
width: 220px;
margin-left: auto;
margin-right: auto;
padding-bottom: 20px;
}
.trapezoid1 {
border-bottom: 100px solid #fff894;
border-left: 60px solid transparent;
border-right: 60px solid transparent;
height: 0;
width: 360px;
margin-left: auto;
margin-right: auto;
padding-bottom: 20px;
}
.trapezoid2 {
border-bottom: 100px solid #83ccde;
border-left: 60px solid transparent;
border-right: 60px solid transparent;
height: 0;
width: 480px;
margin-left: auto;
margin-right: auto;
}
.trapezoid3 {
border-bottom: 100px solid #a87d5c;
border-left: 60px solid transparent;
border-right: 60px solid transparent;
height: 0;
width: 600px;
margin-left: auto;
margin-right: auto;
}
.trapezoid4 {
border-bottom: 100px solid #9effa6;
border-left: 60px solid transparent;
border-right: 60px solid transparent;
height: 0;
width: 720px;
margin-left: auto;
margin-right: auto;
}
.circle1{
height: 45px;
width: 45px;
background-color: #ffffff;
border-radius: 50%;
display: inline-block;
margin-top: 100px;
margin-left: -22px;
margin-right: auto;
opacity: 0.7;
}
.circle2{
height: 50px;
width: 50px;
background-color: #ffffff;
border-radius: 50%;
display: inline-block;
margin-top: 45px;
margin-left: 87px;
margin-right: auto;
opacity: 0.7;
}
.circle3{
height: 50px;
width: 50px;
background-color: #ffffff;
border-radius: 50%;
display: inline-block;
margin-top: 45px;
margin-left: 158px;
margin-right: auto;
opacity: 0.7;
}
.circle4{
height: 50px;
width: 50px;
background-color: #ffffff;
border-radius: 50%;
display: inline-block;
margin-top: 25px;
margin-left: 219px;
margin-right: auto;
opacity: 0.7;
}
.circle5{
height: 50px;
width: 50px;
background-color: #ffffff;
border-radius: 50%;
display: inline-block;
margin-top: 25px;
margin-left: 279px;
margin-right: auto;
opacity: 0.7;
}
.circle6{
height: 50px;
width: 50px;
background-color: #ffffff;
border-radius: 50%;
display: inline-block;
margin-top: 25px;
margin-left: 339px;
margin-right: auto;
opacity: 0.7;
}
.button1 {
background-color: white;
border: none;
padding: 20px;
height: 5px;
width: 5px;
display: none;
margin-left: 0px;
cursor: pointer;
border-radius: 50%;
position: relative;
left: 0px;
top: -18px;
opacity: 0.7;
text-align: center;
text-decoration: none;
line-height: 5px;
}
.button2{
background-color: white;
border: none;
padding: 20px;
height: 5px;
display: none;
width: 5px;
margin-left: 0px;
cursor: pointer;
border-radius: 50%;
position: relative;
left: -147px;
top: -18px;
opacity: 0.7;
text-align: center;
text-decoration: none;
line-height: 5px;
}
.button3 {
background-color: white;
border: none;
padding: 20px;
height: 10px;
width: 10px;
display: none;
margin-left: 0px;
cursor: pointer;
border-radius: 50%;
position: relative;
left: 3px;
top: -23px;
opacity: 0.7;
text-align: center;
text-decoration: none;
line-height: 5px;
}
.button4 {
background-color: white;
border: none;
padding: 20px;
height: 10px;
width: 10px;
display: none;
margin-left: 0px;
cursor: pointer;
border-radius: 50%;
position: relative;
left: 30px;
top: -73px;
opacity: 0.7;
text-align: center;
text-decoration: none;
line-height: 5px;
}
.button5 {
background-color: white;
border: none;
padding: 20px;
height: 10px;
width: 10px;
display: none;
margin-left: 0px;
cursor: pointer;
border-radius: 50%;
position: relative;
left: 5px;
top: -23px;
opacity: 0.7;
text-align: center;
text-decoration: none;
line-height: 5px;
}
.button6 {
background-color: white;
border: none;
padding: 20px;
height: 10px;
width: 10px;
display: none;
margin-left: 0px;
cursor: pointer;
border-radius: 50%;
position: relative;
left: -168px;
top: -23px;
opacity: 0.7;
text-align: center;
text-decoration: none;
line-height: 5px;
}
.button7 {
background-color: white;
border: none;
padding: 20px;
height: 10px;
width: 10px;
display: none;
margin-left: 0px;
cursor: pointer;
border-radius: 50%;
position: relative;
left: 5px;
top: -23px;
opacity: 0.7;
text-align: center;
text-decoration: none;
line-height: 5px;
}
.button8 {
background-color: white;
border: none;
padding: 20px;
height: 10px;
width: 10px;
display: none;
margin-left: 0px;
cursor: pointer;
border-radius: 50%;
position: relative;
left: -167px;
top: -23px;
opacity: 0.7;
text-align: center;
text-decoration: none;
line-height: 5px;
}
.button9 {
background-color: white;
border: none;
padding: 20px;
height: 10px;
width: 10px;
display: none;
margin-left: 0px;
cursor: pointer;
border-radius: 50%;
position: relative;
left: 6px;
top: -23px;
opacity: 0.7;
text-align: center;
text-decoration: none;
line-height: 5px;
}
.button10 {
background-color: white;
border: none;
padding: 20px;
height: 10px;
width: 10px;
display: none;
margin-left: 0px;
cursor: pointer;
border-radius: 50%;
position: relative;
left: -168px;
top: -23px;
opacity: 0.7;
text-align: center;
text-decoration: none;
line-height: 5px;
}
.button11 {
background-color: white;
border: none;
padding: 20px;
height: 10px;
width: 10px;
display: none;
margin-left: 0px;
cursor: pointer;
border-radius: 50%;
position: relative;
left: 6px;
top: -23px;
opacity: 0.7;
text-align: center;
text-decoration: none;
line-height: 5px;
}
.button12 {
background-color: white;
border: none;
padding: 20px;
height: 10px;
width: 10px;
display: none;
margin-left: 0px;
cursor: pointer;
border-radius: 50%;
position: relative;
left: -169px;
top: -23px;
opacity: 0.7;
text-align: center;
text-decoration: none;
line-height: 5px;
}
.piece:hover .button1, .piece:hover .button2, .piece:hover .button3, .piece:hover .button4, .piece:hover .button5, .piece:hover .button6, .piece:hover .button7, .piece:hover .button8, .piece:hover .button9, .piece:hover .button10, .piece:hover .button11, .piece:hover .button12{
display: inline-block;
opacity: 0.7;
}
.text1{
text-align: center;
line-height: 0px;
font-family: "helvetica",serif;
font-size: 20px;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="assignment01.css">
</head>
<body>
<h1 style = "font-family: helvetica"><center>Figure 1</center></h1>
<script type="text/javascript">
var clicks = 0;
function onClick() {
clicks += 1;
document.getElementById("clicks").innerHTML = clicks;
}
function onClickm() {
clicks -= 1;
document.getElementById("clicks").innerHTML = clicks;
}
</script>
<p class= "text1" id="clicks">0</p>
<div class="triangle piece">
<div class="circle1 "></div>
<div class="button1 " onClick="onClick()"><span>+</span></div>
<div class="button2" onClick="onClickm()"><span>-</span></div>
</div>
<div class="trapezoid piece">
<div class="circle2 "></div>
<div class="button3"><span>+</span></div>
<div class="button4"><span>-</span></div>
</div>
<div class="trapezoid1 piece">
<div class="circle3 "></div>
<div class="button5"><span>+</span></div>
<div class="button6"><span>-</span></div>
</div>
<div class="trapezoid2 piece">
<div class="circle4 "></div>
<div class="button7"><span>+</span></div>
<div class="button8"><span>-</span></div>
</div>
<div class="trapezoid3 piece">
<div class="circle5 "></div>
<div class="button9"><span>+</span></div>
<div class="button10"><span>-</span></div>
</div>
<div class="trapezoid4 piece">
<div class="circle6 "></div>
<div class="button11"><span>+</span></div>
<div class="button12"><span>-</span></div>
</div>
<h2 style = "font-family: helvetica"><center>My Food Pyramid</center></h2>
<label style = "font-family: helvetica" for="name"><center>Please Enter The Date:</center></label>
<center><input type="text" id="name" name="name" required maxlength="9" size="10"></center>
</body>
</html>
Why not place the counter directly in the circle in the HTML?
<div class="triangle piece">
<div class="circle1 "><p class= "text1" id="clicks">0</p></div>
<div class="button1 " onClick="onClick()"><span>+</span></div>
<div class="button2" onClick="onClickm()"><span>-</span></div>
</div>
Then you can use the .text1 css to position it exactly in the center.
.circle1{
height: 45px;
width: 45px;
background-color: #ffffff;
border-radius: 50%;
display: inline-block;
margin-top: 100px;
margin-left: -22px;
margin-right: auto;
opacity: 0.7;
position: relative;
}
.text1{
text-align: center;
line-height: 0px;
font-family: "helvetica",serif;
font-size: 20px;
position: absolute;
left: 18px;
top: 5px;
}
Because the counter is within the circle and the circle has position:relative the text will be positioned absolute with regards to the circle it's in.
I created an arrow in CSS. Everything is working as it should except the size of the arrow. I am not sure how I can make it smaller.
How can I make the arrow smaller?
#blue {
width: 100%;
height: 100vh;
background: blue;
}
#box2 {
position: absolute;
top: 25%;
right: 25%;
z-index: 1;
}
#box2Text {
color: #FFF;
font-family: 'Muli', sans-serif;
font-size: 2rem;
font-weight: 300;
line-height: 1.4em;
padding: 80px;
border: 6px solid #FFF;
border-radius: 2px;
display: block;
text-align: center;
}
#arrow {
margin-top: 10px;
border: solid #FFF;
border-width: 0 3px 3px 0;
display: block;
padding: 3px;
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
}
<section id="blue">
<div id="box2">
<span id="box2Text">View Services</span>
<div id="arrow"></div>
</div>
</section>
Desired output:
Use the arrow as a pseudo element of the text div and you can easily place it and adjust its size:
#blue {
width: 100%;
height: 100vh;
background: blue;
}
#box2 {
position: absolute;
top: 25%;
right: 25%;
z-index: 1;
}
#box2Text {
color: #FFF;
font-family: 'Muli', sans-serif;
font-size: 2rem;
font-weight: 300;
line-height: 1.4em;
padding: 80px;
border: 6px solid #FFF;
border-radius: 2px;
display: block;
text-align: center;
position:relative;
}
#box2Text:after {
content:"";
left:calc(50% - 5px);
margin-top:40px;
position:absolute;
border: solid #FFF;
border-width: 0 3px 3px 0;
width:10px;
height:10px;
transform: rotate(45deg);
}
<section id="blue">
<div id="box2">
<span id="box2Text">View Services</span>
</div>
</section>
You just need to specify CSS width and height attributes to #arrow. you might need to adjust the arrow position after that according to your needs
#blue {
width: 100%;
height: 100vh;
background: blue;
}
#box2 {
position: absolute;
top: 25%;
right: 25%;
z-index: 1;
}
#box2Text {
color: #FFF;
font-family: 'Muli', sans-serif;
font-size: 2rem;
font-weight: 300;
line-height: 1.4em;
padding: 80px;
border: 6px solid #FFF;
border-radius: 2px;
display: block;
text-align: center;
}
#arrow {
margin-top: 10px;
border: solid #FFF;
border-width: 0 3px 3px 0;
display: block;
padding: 3px;
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
width: 5px;
height: 5px;
}
<section id="blue">
<div id="box2">
<span id="box2Text">View Services</span>
<div id="arrow"></div>
</div>
</section>
Like this?
#blue {
width: 100%;
height: 100vh;
background: blue;
}
#box2 {
position: absolute;
top: 25%;
right: 25%;
z-index: 1;
}
#box2Text {
color: #FFF;
font-family: 'Muli', sans-serif;
font-size: 2rem;
font-weight: 300;
line-height: 1.4em;
padding: 80px;
border: 6px solid #FFF;
border-radius: 2px;
display: block;
text-align: center;
}
#arrow {
margin-right:15px;
margin-bottom:5px;
border: solid #FFF;
border-width: 0 3px 3px 0;
display: inline-block;
padding: 3px;
transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
width: 5px;
height: 5px;
}
<section id="blue">
<div id="box2">
<span id="box2Text"><div id="arrow"></div><span>View Services</span></span>
</div>
</section>
I'm trying to make it so that when I user resizes there window it wont move anything on the page, and it wont resize anything. But I still wont the site to look the same on different screen sizes. Because right now the website moves my image and my buttons. The buttons also change size.
* {
box-sizing: border-box; }
#wrapper {
margin-left:auto;
margin-right:auto;
width:100%;
height: 100%;
}
body {
background-color: black;
font-family: "Source Sans Pro", sans-serif;
text-align: center;
color: #ccc;
}
div {
height: 100%;
}
canvas {
position: absolute;
width: 100%;
height: 100%;
top: 0;
right: 0;
left: 0;
bottom: 0;
}
h3 {
position: absolute;
font-size: 100px;
font-weight: 100;
color: white;
margin-top: 70px;
margin-left: 80px;
}
img {
margin-top: 230px;
margin-right: 0px;
}
.home {
position: absolute;
border: 2px solid #CCCCCC;
text-align: center;
color: #ccc;
font-size: 26px;
line-height: 60px;
width: 10%;
height: 60px;
margin-top: 180px;
margin-left: 500px;
}
.about {
position: absolute;
border: 2px solid #CCCCCC;
text-align: center;
color: #ccc;
font-size: 26px;
line-height: 60px;
width: 10%;
height: 60px;
margin-top: 180px;
margin-left: 750px;
}
.projects {
position: absolute;
border: 2px solid #CCCCCC;
text-align: center;
color: #ccc;
line-height: 60px;
width: 10%;
height: 60px;
font-size: 26px;
margin-top: 180px;
margin-left: 1000px;
}
.contact {
position: absolute;
border: 2px solid #CCCCCC;
text-align: center;
color: #ccc;
line-height: 60px;
font-size: 26px;
width: 10%;
height: 60px;
margin-top: 180px;
margin-left: 1250px;
}
.home:hover{
border-color: #0091FF;
color: #0091FF;
}
.about:hover{
border-color: #0091FF;
color: #0091FF;
}
.projects:hover{
border-color: #0091FF;
color: #0091FF;
}
.contact:hover{
border-color: #0091FF;
color: #0091FF;
}
<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Play" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="styles.css" />
<script type="text/javascript" src="background.js"></script>
<title>Home</title>
</head>
<body>
<div id="wrapper">
<canvas class='connecting-dots'></canvas>
<h3>Title</h3>
<div class = "home">Home</div>
<div class = "about">About</div>
<div class = "projects">Projects</div>
<div class = "contact">Contact</div>
<img src="astronaut.png">
</div>
</body>
</html>
Set min-width: and min-height: on your elements. That will prevent them from getting any smaller and then you can do max-width and max-height to prevent them from growing. Also, change it from width:10%; to a solid/absolute number. This is saying 10% of whatever screen it is displayed on.
http://codepen.io/Squeakasaur/pen/OpwWqG
* {
box-sizing: border-box; }
#wrapper {
margin-left:auto;
margin-right:auto;
width:100%;
height: 100%;
}
body {
background-color: black;
font-family: "Source Sans Pro", sans-serif;
text-align: center;
color: #ccc;
}
div {
height: 100%;
}
canvas {
position: absolute;
width: 100%;
height: 100%;
top: 0;
right: 0;
left: 0;
bottom: 0;
}
canvas {
position: absolute;
width: 100%;
height: 100%;
top: 0;
right: 0;
left: 0;
bottom: 0;
}
h3 {
position: absolute;
font-size: 100px;
font-weight: 100;
color: white;
margin-top: 70px;
margin-left: 80px;
}
img {
margin-top: 230px;
margin-right: 0px;
}
.home {
position: absolute;
border: 2px solid #CCCCCC;
text-align: center;
color: #ccc;
font-size: 26px;
line-height: 60px;
width: 150px;
height: 60px;
margin-top: 180px;
margin-left: 500px;
}
.about {
position: absolute;
border: 2px solid #CCCCCC;
text-align: center;
color: #ccc;
font-size: 26px;
line-height: 60px;
width: 150px;
height: 60px;
margin-top: 180px;
margin-left: 750px;
}
.projects {
position: absolute;
border: 2px solid #CCCCCC;
min-width: ;
text-align: center;
color: #ccc;
line-height: 60px;
width: 150px;
height: 60px;
font-size: 26px;
margin-top: 180px;
margin-left: 1000px;
}
.contact {
position: absolute;
border: 2px solid #CCCCCC;
text-align: center;
color: #ccc;
line-height: 60px;
font-size: 26px;
width: 150px;
height: 60px;
margin-top: 180px;
margin-left: 1250px;
}
.home:hover{
border-color: #0091FF;
color: #0091FF;
}
.about:hover{
border-color: #0091FF;
color: #0091FF;
}
.projects:hover{
border-color: #0091FF;
color: #0091FF;
}
.contact:hover{
border-color: #0091FF;
color: #0091FF;
}
I am trying to emulate this nutrition label format in CSS, but I can't get the shapes right at all. The best I can come up with is fiddling with border-radius, but that gives me more of a pill shape, and still not way to get the black cut-out shape at the bottom. Has anyone replicated such a nutrition label in CSS? Would anyone be willing to try? Any help would be greatly appreciated.
Here is a link to what I have so far: jsfiddle.net/f5jczunf/
#block {
border-radius:50%/10px;
background: #ccc;
padding: 20px;
width: 50px;
height: 100px;
border: 1px solid #000;
background-color:#FFF;
text-align:center;
}
.number {
font-weight:bold;
font-size:18pt;
text-align:center;
}
<div id="block">
<span class="number">150</span>
<br/>Calories
</div>
Maybe this small example can help.
.label {
position: relative;
width: 100px;
height: 140px;
text-align: center;
border: 1px solid #000;
border-radius: 100px/50px;
overflow: hidden;
}
.title {
display: inline-block;
margin-top: 30px;
}
.bottom {
position: absolute;
bottom: -10px;
left: 0;
right: 0;
height: 50px;
color: #fff;
line-height: 40px;
border-top: 1px solid #000;
border-radius: 100px/50px;
background-color: #000;
}
<div class="label">
<span class="title">Title</span>
<span class="bottom">Bottom</span>
</div>
https://jsfiddle.net/9xs2wcbL/1/
Here's my take on it. It does require some advanced, bleeding edge CSS, however.
#import url('https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300');
body {
padding: 3em;
font-size: 16px;
font-family: 'Open Sans Condensed', sans-serif;
}
.label-list {
display: -webkit-inline-box;
display: -ms-inline-flexbox;
display: inline-flex;
}
.label-list .label-item {
text-align: center;
border: 1px solid;
position: relative;
border-radius: 2em / 0.65em;
padding: 0.2em 0.25em 1.5em;
min-width: 3.5em;
overflow: hidden;
margin: 0.1em;
z-index: 1;
background: white;
color: black;
}
.label-list .label-item h1 {
font-size: 3em;
line-height: 1em;
font-weight: 900;
margin: 0;
}
.label-list .label-item h1.smaller {
font-size: 1.75em;
margin-top: 0.5em;
}
.label-list .label-item h1 small {
font-size: 0.4em;
text-transform: none;
}
.label-list .label-item small {
font-size: 1em;
line-height: 1em;
font-weight: 900;
text-transform: uppercase;
}
.label-list .label-item span {
position: absolute;
bottom: 0.5em;
left: 0;
right: 0;
color: white;
font-size: 0.8em;
line-height: 1em;
}
.label-list .label-item span:before {
content: '';
position: absolute;
bottom: 0;
left: 0;
right: 0;
top: 0;
background: black;
z-index: -1;
border-radius: 40%;
transform-origin: center;
width: 100%;
height: 0;
padding-top: 100%;
margin: auto;
transform: rotate(45deg) translate(20%, 20%);
}
<div class="label-list">
<div class="label-item">
<h1>140</h1>
<small>Calories</small>
</div>
<div class="label-item">
<h1 class="smaller">1<small>g</small></h1>
<small>Sat Fat</small>
<span>5% DV</span>
</div>
</div>
I believe the only way to have this sort of shape in pure CSS is with a few overlapping shapes, something similar to the code below:
.wrapper {
position: relative;
height: 112px;
width: 80px;
overflow: hidden;
}
.rectangle,
.circle {
position: absolute;
box-sizing: border-box;
}
.rectangle {
height: 96px;
width: 80px;
top: 8px;
border-left: 1px solid black;
border-right: 1px solid black;
}
.circle {
width: 200px;
height: 200px;
left: -60px;
border-radius: 200px;
border: 1px solid black;
}
.top {
top: 0;
}
.bottom {
bottom: 0;
}
<div class="wrapper">
<div class="circle top"></div>
<div class="rectangle"></div>
<div class="circle bottom"></div>
</div>
https://jsfiddle.net/dylanstark/01hck5dv/
here my approach for that. I'm using before and after pseudo-elements.
before contains black bg with border-radius and it is overflowing the main #block which has overflow: hidden;.
aftercontains text that is coming from data-text attribute of #block
#block {
border-radius: 50%/10px;
background: #ccc;
padding: 20px;
width: 50px;
height: 100px;
border: 1px solid #000;
background-color: #FFF;
text-align: center;
position: relative;
overflow: hidden;
}
#block:before {
display: block;
content: " ";
position: absolute;
bottom: -15px;
left: 0;
width: 100%;
height: 50px;
border-radius: 50%;
background: black;
z-index: 0;
}
#block:after {
display: block;
content: attr(data-label);
position: absolute;
bottom: 5px;
color: white;
text-align: center;
z-index: 1;
}
.number {
font-weight: bold;
font-size: 18pt;
text-align: center;
}
<div id="block" data-label="5% DY">
<span class="number">150</span>
<br/>Calories
</div>
I'm trying to create a button that looks like this:
The tricky part is getting the number to 'fit' inside of the button. This is how I have my button set up:
<button type="text" class="textclass"><span class="numberclass">33</span>Text</button>
This is my CSS:
.textclass {
width: 90px;
height: 30px;
background-color: #FFF;
border: 1px solid blue;
color: blue;
font-size: 10px;
line-height: 12px;
font-weight: 600;
text-transform: uppercase;
border-radius: 2px;
padding-left: 20px;
}
.numberclass {
background-color: blue;
color: #FFF;
position: absolute;
left: 0;
top: 0;
height:30px;
width: 30px;
border-radius: 2px 0 0 2px;
}
Setting the height and width of the number seems unnecessary, and I can't get the number to line up properly unless I get into extremely specific positioning which is not ideal. Where am I going wrong here?
Plunk:
http://plnkr.co/edit/0WUs3Y2axmOvfB7TswCb?p=preview
Try to this Define your .textclass position:relative;overflow:hidden; and .numberclass line-height:30px; as like this
/* Styles go here */
.textclass {
width: 90px;
position:relative;
overflow:hidden;
height: 30px;
background-color: #FFF;
border: 1px solid blue;
color: blue;
font-size: 10px;
line-height: 12px;
font-weight: 600;
text-transform: uppercase;
border-radius: 2px;
padding-left: 20px;
}
.numberclass {
background-color: blue;
color: #FFF;
position: absolute;
left: 0;
top: 0;
height:30px;
width: 30px;
line-height:30px;
border-radius: 2px 0 0 2px;
}
<div>
<button type="text" class="textclass"><span class="numberclass">33</span>Text</button>
</div>
or you just define button into span tag as like this
.textclass {
width: 90px;
position:relative;
overflow:hidden;
display:inline-block;vertical-align:top;text-align:center;
height: 30px;
background-color: #FFF;
border: 1px solid blue;
color: blue;
font-size: 10px;
line-height: 30px;
font-weight: 600;
text-transform: uppercase;
border-radius: 2px;
padding-left: 20px;
}
.numberclass {
background-color: blue;
color: #FFF;
position: absolute;
left: 0;
top: 0;
height:30px;
width: 30px;
line-height:30px;
border-radius: 2px 0 0 2px;
}
<div>
<span class="textclass"><span class="numberclass">33</span>Text</span></div>
Just give position: relative; to .textclass and line-height: 30px; to .numberclass
Updated Plunker
try this (replace it)
.numberclass {
background-color: blue;
color: #FFF;
position: absolute;
left: 9px;
top: 8px;
height: 20px;
padding-top: 9px;
width: 30px;
border-radius: 2px 0 0 2px;
}
you can try this one:
.textclass {
width: 140px;
position:relative;
overflow:hidden;
height: 40px;
background-color: #FFF;
border: 1px solid blue;
color: blue;
font-size: 15px;
line-height: 12px;
font-weight: 600;
text-transform: uppercase;
border-radius: 2px;
padding-left: 30px;
}
.numberclass {
background-color: blue;
color: #FFF;
position: absolute;
left: 0;
top: 0;
height:40px;
width: 40px;
line-height:35px;
border-radius: 2px 0 0 2px;
}
DEMO HERE
Please, see the working plunker with completely auto adjusting height of the number part. You do not even need to apply the line-height.
HTML
<button type="text" class="textclass">
<span class="numberclass">
<span class="container"><span class="inner">33</span></span>
</span>
Text
</button>
CSS
.textclass {
width: 90px;
height: 30px;
position: relative;
background-color: #FFF;
border: 1px solid blue;
color: blue;
font-size: 10px;
line-height: 12px;
font-weight: 600;
text-transform: uppercase;
border-radius: 2px;
padding-left: 20px;
}
.numberclass {
background-color: blue;
color: #FFF;
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 30px;
border-radius: 2px 0 0 2px;
display: block;
}
.container {
display: table;
height: 100%;
text-align: center;
width: 100%;
}
.inner {
display: table-cell;
height: 100%;
vertical-align: middle;
}
change in .numberclass class
/* Styles go here */
.textclass {
width: 90px;
height: 30px;
background-color: #FFF;
border: 1px solid blue;
color: blue;
font-size: 10px;
line-height: 12px;
font-weight: 600;
text-transform: uppercase;
border-radius: 2px;
padding-left: 20px;
}
.numberclass {
background-color: blue;
border-radius: 1px 0 0 1px;
color: #fff;
left: 8px;
padding: 8px;
position: absolute;
top: 9px;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body>
<div>
<button type="text" class="textclass"><span class="numberclass">33</span>Text</button>
</div>
</body>
</html>