Numbers centered in a circle - html

.circle{
width: 20px;
height: 20px;
border: 1px solid #2d2d2d;
color: #2d2d2d;
border-radius: 50%;
cursor: pointer;
display: inline-block;
padding: 10px;
margin: 0 3px;
vertical-align: middle;}
.choice .circle{
position: relative;
top: 50%;
transform: translateY(-50%);
text-align: center;
}
<div class="choice">
<div class="circle" data-attr-val="2000" data-attr-price="59">2000</div>
<div class="circle" data-attr-val="20" data-attr-price="59">20</div>
</div>
In the example you can see my problem, 4 or more numbers looks bad, 1-3 numbers looks good.
How can I center 4 or more numbers?
Thanks for help :)

Have a look at this
HTML
<div class="choice">
<div class="circle" data-attr-val="2000" data-attr-price="59">2000</div>
<div class="circle" data-attr-val="20" data-attr-price="59">20</div>
CSS
.circle {
width:50px;
height:50px;
border:1px solid black;
border-radius:250px;
line-height:50px;
text-align:center;
display:inline-block;
}
Fiddle here

Remove the left and right padding, and increase the width instead by an equal amount – then you can get four digits centered in there via text-align. (More digits might still be problematic though.)
.circle{
width: 40px;
height: 20px;
border: 1px solid #2d2d2d;
color: #2d2d2d;
border-radius: 50%;
cursor: pointer;
display: inline-block;
padding: 10px 0;
margin: 0 3px;
vertical-align: middle;
text-align:center;
}
.choice .circle{
position: relative;
top: 50%;
transform: translateY(-50%);
text-align: center;
}
<div class="choice">
<div class="circle" data-attr-val="2000" data-attr-price="59">2000</div>
<div class="circle" data-attr-val="20" data-attr-price="59">20</div>
</div>

Here is a version using display: inline-table and a pseudo element.
These circle:before rule's properties will keep the numbers centered what ever size you set for the circle (though too small will look odd), even with two lines of numbers.
vertical-align: middle;
text-align: center;
I also used css attr() to set the numbers from your "data-attr-val" instead of adding them manually.
.circle {
display: inline-table;
width: 40px;
height: 40px;
border: 1px solid #2d2d2d;
color: #2d2d2d;
border-radius: 50%;
cursor: pointer;
}
.circle:before {
content: attr(data-attr-val);
display: table-cell;
vertical-align: middle;
text-align: center;
}
.circle.big {
width: 80px;
height: 80px;
}
.circle.big:before {
content: attr(data-attr-val);
}
<div class="choice">
<div class="circle" data-attr-val="2000" data-attr-price="59"></div>
<div class="circle" data-attr-val="20" data-attr-price="59"></div>
</div>
<br />2 lines, still centered<br /><br />
<div class="circle big" data-attr-val="10000 20000" data-attr-price="59"></div>

Related

Child-element in inline-block div changes the parents siblings position

I have a couple of divs with some content (another div inside). I want the parent divs to be positioned in a nice line and I want the child div to be relative to its parent.
I've made a JSFiddle To illustrate. Right now the divs are all nicely placed, but if you remove the '.btn' div in the last one, everything gets messed up.
To see what I mean, change the HTML in the JSFiddle to:
<div id="expand1" class="expand">
<div id="btn1" class="btn">>></div>
</div>
<div id="expand2" class="expand">
<div id="btn2" class="btn">>></div>
</div>
<div id="expand3" class="expand"></div>
What's going on here? How can I get the desired result?
You should use floats for a better layout:
.expand{
border:1px solid black;
width:400px;
height:400px;
display:inline-block;
float: left;
}
.btn{
cursor:pointer;
position:relative;
top:150px;
left: 150px;
border: 1px solid black;
width:40px;
height:40px;
vertical-align:middle;
text-align:center;
line-height:40px;
}
<div id="expand1" class="expand">
<div id="btn1" class="btn">>></div>
</div>
<div id="expand2" class="expand">
<div id="btn2" class="btn">>></div>
</div>
<div id="expand3" class="expand"></div>
.expand {
border: 1px solid black;
width: 400px;
height: 400px;
display: inline-block;
vertical-align: top;
}
.btn{
margin: -20px 0 0 -20px;
cursor: pointer;
position: relative;
top: 50%;
left: 50%;
border: 1px solid black;
width: 40px;
height: 40px;
vertical-align: middle;
text-align: center;
line-height: 40px;
}
<div id="expand1" class="expand">
<div id="btn1" class="btn">>></div>
</div>
<div id="expand2" class="expand">
<div id="btn2" class="btn">>></div>
</div>
<div id="expand3" class="expand"></div>
You can simply play with the position property to get the desired result.
just add position:relative to your .expand class
.expand {
position:relative;
border: 1px solid black;
width: 400px;
height: 400px;
display: inline-block;
}
and update the position to absolute to your .btn class
.btn {
cursor: pointer;
position: absolute;
top: 150px;
left: 150px;
border: 1px solid black;
width: 40px;
height: 40px;
vertical-align: middle;
text-align: center;
line-height: 40px;
}

div buttons are overlapping HTML

I am trying to make an online portfolio for myself and I have a bottom container for the bottom half of the screen and I would like to place 3 buttons at the top of the container. I have got it to work except when you resize the page. When you shrink the page's width the buttons will overlap. How can I stop them from overlapping? I want them to go close together side by side but not overlap.
h1 {
margin-left: 33%;
margin-right: 33%;
text-align: center;
}
img {
width: 15%;
height: auto;
display: block;
margin-left: auto;
margin-right: auto;
}
#top,
#bottom {
position: fixed;
left: 0;
right: 0;
height: 50%;
}
#bottom {
border-top: 2px solid black;
margin-left: auto;
margin-right: auto;
display: block;
float: center;
position: fixed;
border: 2px solid black;
padding: 15px;
padding-bottom: 17px;
}
#navbuttons {
border-top: 2px solid black;
margin-left: auto;
margin-right: auto;
display: block;
float: center;
position: relative;
border: 2px solid black;
padding: 15px;
padding-bottom: 10px;
}
#resumebutton {
display: inline-block;
position: absolute;
top: 0%;
left: 33%;
-moz-border-radius: 20px;
-webkit-border-radius: 20px;
border: 2px solid black;
border-radius: 20px;
padding: 5px;
background-color: #7dd7f5;
text-align: center;
}
#coverletterbutton {
display: inline-block;
position: absolute;
top: 0%;
left: 46.5%;
-moz-border-radius: 20px;
-webkit-border-radius: 20px;
border: 2px solid black;
border-radius: 20px;
padding: 5px;
background-color: #7dd7f5;
text-align: center;
}
#portfoliobutton {
display: inline-block;
position: absolute;
top: 0%;
left: 62.5%;
-moz-border-radius: 20px;
-webkit-border-radius: 20px;
border: 2px solid black;
border-radius: 20px;
padding: 5px;
background-color: #7dd7f5;
text-align: center;
}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<title>--Name Here-- Resume and Portfolio</title>
</head>
<body>
<div style="height: 100%"></div>
<div id="top"></div>
<h1>--Name Here--</h1>
<img src="http://science-all.com/images/wallpapers/cat-pictures/cat-pictures-20.jpg"/>
<h1>Resume and Portfolio</h1>
<div id="bottom">
<div id="navbuttons">
<div id="resumebutton">Resume</div>
<div id="coverletterbutton">Cover Letter</div>
<div id="portfoliobutton">Portfolio</div>
</div>
</div>
</body>
</html>
I would provide an example if I knew how.
Thank you
you don't need to absolute position the buttons if you have the container fixed. you can use inline-block and just text-align: center on your container. Also there are errors in your css, like there is no float: center;, you can also skip the # and use class as they share css properties. But I agree that Bootstrap is the way to go for responsive, and especially if you are new.
#bottom {
border-top: 2px solid black;
text-align: center;
margin-left: auto;
margin-right: auto;
display: block;
position: fixed;
border: 2px solid black;
padding: 15px;
padding-bottom: 17px;
}
.nav-button {
display: inline-block;
-moz-border-radius: 20px;
-webkit-border-radius: 20px;
border: 2px solid black;
border-radius: 20px;
padding: 5px;
background-color: #7dd7f5;
text-align: center;
}
<div id="bottom">
<div class="nav-button">Resume</div>
<div class="nav-button">Cover Letter</div>
<div class="nav-button">Portfolio</div>
</div>
The bootstrap grid system is great at this. I recommend using it in combination with some of your custom styles to produce a bottom section split into equally sized columns.
Grids are split into 12 columns, so columns of 4 (e.g. col-md-4) will split into evenly spaced vertically.
For the bottom, that would look something like:
<div id="bottom">
<div id="navbuttons" class="row">
<div id="resumebutton" class="col-md-4">Resume</div>
<div id="coverletterbutton" class="col-md-4">Cover Letter</div>
<div id="portfoliobutton" class="col-md-4">Portfolio</div>
</div>
</div>
You can make these columns wrapper divs if you want to center smaller buttons inside those columns, but the grid structure is a good place to start.
You can just delete attribute position: absolute; from all buttons ( resumebutton, coverletterbutton and portfoliobutton) and add text-align: center to navbuttons selector.
Consider removing the absolutepositioning to replace the elements in question back into the flow of the document. They'll have relation to each other now, so you won't need to rely on positioning rules like left and right.
The elements are already displayed inline-block so just declare a text-align: center rule to the parent and the nested elements will align accordingly.
In the snippet example below, margins have been added around each button for spacing, repetitive rules have been replaced with one instance using a class selector applied to all button elements, note that float: center; is not a valid rule.
Snippet Example
h1 {
margin-left: 33%;
margin-right: 33%;
text-align: center;
}
img {
width: 15%;
height: auto;
display: block;
margin-left: auto;
margin-right: auto;
}
#top,
#bottom {
position: fixed;
left: 0;
right: 0;
height: 50%;
}
#bottom {
border-top: 2px solid black;
margin-left: auto;
margin-right: auto;
display: block;
float: center;
position: fixed;
border: 2px solid black;
padding: 15px;
padding-bottom: 17px;
}
#navbuttons {
border-top: 2px solid black;
margin-left: auto;
margin-right: auto;
display: block;
float: center;
/* invalid rule */
position: relative;
border: 2px solid black;
padding: 15px;
padding-bottom: 10px;
text-align: center;
}
#navbuttons .button {
display: inline-block;
-moz-border-radius: 20px;
-webkit-border-radius: 20px;
border: 2px solid black;
border-radius: 20px;
padding: 5px;
background-color: #7dd7f5;
text-align: center;
margin: 0px 20px;
}
<div style="height: 100%"></div>
<div id="top"></div>
<h1>--Name Here--</h1>
<img src="http://science-all.com/images/wallpapers/cat-pictures/cat-pictures-20.jpg" />
<h1>Resume and Portfolio</h1>
<div id="bottom">
<div id="navbuttons">
<div id="resumebutton" class="button">Resume</div>
<div id="coverletterbutton" class="button">Cover Letter</div>
<div id="portfoliobutton" class="button">Portfolio</div>
</div>
</div>

Bottom to top, right to left position small rectangles inside a bigger one (calendar)

I'm building a calendar, and this is what I'm after:
http://postimg.org/image/vpd10bkqt/
So basically I want to show all the events as a small rectangle inside the
appropriate day's big rectangle.
The difficulty is the first element should be shown at the bottom right corner,
and should be filling form right to left and bottom to top.
I think the simplest solution would be if a rectangle would be a
span element with a solid border around it, and it contains a dot as text.
Here is a jsfiddle demo:
http://jsfiddle.net/jv392gmv/
CSS:
section#calendar {
width: 970px;
}
time {
display: inline-block;
width: 120px;
height: 120px;
margin: 4px;
text-align: right;
font-size: x-large;
font-weight: 900;
border: 1px solid #c3c7c7;
border-radius: 5px;
background: #fff;
}
time.notmonth {
background: #777;
}
section#calendar h1 {
text-align: center;
}
section#calendar time a {
display: inline-block;
width: 110px;
height: 110px;
margin: 5px 5px 0 0;
padding: 3px 3px 0 0;
color: #f55b2c;
text-decoration: none;
}
section#calendar time a:hover {
color: #000;
}
span.event {
top: 10%;
left: 7px;
position: relative;
border-color: #222;
border-style: solid;
border-radius: 5px;
border-width: 5px;
}
HTML:
<section id="calendar">
<h1>
←
July 2015
→
</h1>
<time datetime="2011-05-29">
29
<!-- <span class="event">.</span> -->
</time>
</section>
Anyone has any idea how to achieve it?
The original time tag idea came from here:
http://thenewcode.com/355/HTML5-Calendar-With-CSS3-and-Microdata
In the container, set a rotation of 180 deg.
In the children, rotate again to get them upright
.base {
width: 140px;
height: 140px;
border: solid 1px black;
position: relative;
}
.test {
position: absolute;
top: 0px;
left: 0px;
right: 0px;
bottom: 0px;
transform: rotate(180deg);
}
.children {
width: 40px;
height: 40px;
background-color: lightblue;
transform: rotate(180deg);
display: inline-block;
margin: 2px;
}
<div class="base">
<div >123</div>
<div class="test">
<div class="children">1</div>
<div class="children">2</div>
<div class="children">3</div>
<div class="children">4</div>
<div class="children">5</div>
<div class="children">6</div>
<div class="children">7</div>
</div>
</div>

How can I draw such 2 lines in this shape using CSS HTML

I want to draw this shape using HTML and CSS:
My problem is how to draw the 2 lines in left and in the right of green rectangle.
This is my attempt:
.c{
width: 225px;
float: left;
padding: 13px;
margin: 5px;
border-width:2px;
border-color:#777;
border-style:solid;
text-align: center;
border-radius: 30px;
}
.c .cadre{
background: #60b000;
width: 20px;
height: 20px;
border-radius: 3px;
margin: 10px auto 0px;
}
.c .cadre .num{
font-size: 17px;
margin-right: 2px;
color: white;
}
<h3> Commment ça marche</h3>
<div class="c">
<h3> titre1 </h3>
The element selector selects elements based on the element name.
<div class="cadre"><span class="num">1</span></div>
</div>
Thank you for help in advance.
Use a pseudo-element like :before, also move the styles from cadre to style the span num.
Try this:
.c {
width: 225px;
float: left;
padding: 13px;
margin: 5px;
border-width: 2px;
border-color: #777;
border-style: solid;
text-align: center;
border-radius: 30px;
}
.c .cadre {
position:relative;
}
.c .cadre .num {
background: #60b000;
border-radius: 3px;
margin: 10px auto 0px;
width: 20px;
height: 20px;
display:block;
font-size: 17px;
color: white;
position:relative;
z-index:10;
}
.c .cadre:before {
content:" ";
width:80%;
position:absolute;
height:5px;
left:50%;
top:50%;
transform:translate(-50%, -50%);
background:orange;
}
<h3> Commment ça marche</h3>
<div class="c">
<h3> titre1 </h3>
The element selector selects elements based on the element name.
<div class="cadre"><span class="num">1</span>
</div>
</div>

Add vertical line between the vertical divs

I want to add a vertical line between the multiple divs so that it looks like the attached image:
I'm trying to achieve that by adding a div .border and setting its position absolute. However I want to add some margin between the border and make the border appear behind the boxes as in above image.
Here's the code I'm trying:
HTML:
<div class="wrap">
<div class="box">
<div class="border"></div>
<div class="figure"></div>
<div class="right"> right</div>
</div>
<div class="box">
<div class="border"></div>
<div class="figure"></div>
<div class="right"> right</div>
</div>
<div class="box">
<div class="border"></div>
<div class="figure"></div>
<div class="right"> right</div>
</div>
</div>
CSS:
.wrap{
position: relative;
overflow: hidden;
}
.box{
overflow: hidden;
margin-top: 50px;
}
.box:first-child{
margin-top: 0;
}
.figure{
width: 50px;
height: 50px;
background: yellow;
display: inline-block;
margin-right: 10px;
}
.right{
display: inline-block;
}
.border{
border-right: 3px solid red;
height: 100%;
left: 24px;
position: absolute;
top: 0;
width: 1px;
}
.box:last-child .border{
display: none;
}
JSFiddle:
http://jsfiddle.net/w5TY9/
Here you go.
WORKING DEMO
The HTML:
<div class="wrap">
<div class="box">
<div class="border"></div>
<div class="figure"></div>
<div class="right"> </div>
</div>
<div class="box">
<div class="border"></div>
<div class="figure"></div>
<div class="right"> </div>
</div>
<div class="box">
<div class="border"></div>
<div class="figure"></div>
<div class="right"> </div>
</div>
</div>
The CSS:
.wrap{
position: relative;
overflow: hidden;
}
.box{
overflow: hidden;
margin-top: 50px;
}
.box:first-child{
margin-top: 0;
}
.figure{
width: 50px;
height: 50px;
background: yellow;
display: inline-block;
margin-right: 10px;
}
.right{
display: inline-block;
}
.border {
border-right: 3px solid #FF0000;
height: 98%;
left: 24px;
position: absolute;
top: 0;
width: 1px;
z-index: -1;
}
.box:last-child .border{
display: none;
}
.figure {
background: none repeat scroll 0 0 #FFFF00;
border-bottom: 12px solid #FFFFFF;
border-top: 12px solid #FFFFFF;
display: inline-block;
height: 50px;
margin-right: 10px;
width: 50px;
}
The CSS Changes:
.border {
border-right: 3px solid #FF0000;
height: 98%;
left: 24px;
position: absolute;
top: 0;
width: 1px;
z-index: -1;
}
.figure {
background: none repeat scroll 0 0 #FFFF00;
border-bottom: 12px solid #FFFFFF;
border-top: 12px solid #FFFFFF;
display: inline-block;
height: 50px;
margin-right: 10px;
width: 50px;
}
Hope this helps.
.border{z-index: -1;} use this
And see link http://jsfiddle.net/bipin_kumar/w5TY9/2/
.figure{
width: 50px;
height: 50px;
background: yellow;
display: inline-block;
margin-right: 10px;
z-index:1;
border:3px solid white;
}
.border{
border-right: 3px solid red;
height: 100%;
left: 24px;
position: absolute;
top: 0;
width: 1px;
z-index:-1;
}
replace your classes with mine, you will get both effects
.border{
border-right: 3px solid red;
height: 100%;
left: 24px;
position: absolute;
top: 0;
width: 1px;
}
Class need to be added the following property and value
z-index: -1;
In your css you need to add the following two rules for the .border class:
z-index: -1;
margin-left: -1px
The first line puts the line behind the boxes. So in the vertical space without boxes the line shows up.
One small improvement for centering the border perfectly under the boxes:
Your border is 3px width so the border should be moved at least 1px to the left in order to stay centered. With margin-left: -1px you get the correct result. If you want the border to be completely perfect centered you should either use a border with of 4px and a margin-left of -1px or a border with of 2px and a margin-left of 1px;
see http://jsfiddle.net/w5TY9/1/
Add z-index=-1 to border class.
check this fiddle
What you want is very easy. The short version is like this:
<div style="background-color:yellow; height:30px;width:30px;"> </div>
<div style="background-color:red; height:30px; width:5px; margin-left:10px;"> </div>
In this way you have a square with background yellow and below that you have a red line
with 5px width or whatever you want.