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.
Related
I'm trying to remove the ring around a material icon that I'm using as a close icon on a draggable element.
Here's a picture of the element (I've changed the background to red for you to highlight the problem), I want to remove the red outer circle so the nice border of the element goes all the way to the edge of the grey circle:
Here's the HTML and CSS for the element and the icon:
HTML:
<div class="print-element">
Tag Number
<mat-icon class="resize-circle">highlight_off</mat-icon>
</div>
CSS:
.print-element {
min-width: 175px;
min-height: 45px;
border: solid 1px #ccc;
color: rgba(0, 0, 0, 0.87);
display: inline-flex;
justify-content: center;
align-items: center;
text-align: center;
background: #fff;
border-radius: 4px;
margin-right: 25px 25px 15px 0px;
cursor: move;
position: relative;
z-index: 1;
box-sizing: border-box;
padding: 10px 50px 10px 10px;
transition: box-shadow 200ms cubic-bezier(0, 0, 0.2, 1);
box-shadow: 0 3px 1px -2px rgba(0, 0, 0, 0.2),
0 2px 2px 0 rgba(0, 0, 0, 0.14),
0 1px 5px 0 rgba(0, 0, 0, 0.12);
}
.resize-circle{
position: absolute;
top: -10px;
right: -10px;
background-color: white;
border: .1px solid white;
border-radius: 50%;
color: #aaa;
cursor: pointer;
}
.mat-icon {
background-repeat: no-repeat;
display: inline-block;
fill: currentColor;
height: 24px;
width: 24px;
}
Now I can change the size of the mat-icon, but that results in the below:
using:
.mat-icon {
background-repeat: no-repeat;
display: inline-block;
fill: currentColor;
height: 20px;
width: 20px;
}
yields:
Here's a stackblitz all set up and ready to go: https://stackblitz.com/edit/angular-m7wwvr?file=src%2Fstyles.scss
Here's what I want it to look like:
Even pointers in the right direction would help.
Check edited URL for the changes in HTML and CSS
https://stackblitz.com/edit/angular-m7wwvr-xrmyje?file=src/styles.scss
Ok here is an answer. I used #Srinivas Bendkhale answer to reach this result.
what I did was wrapping the icon with a span and give it a fix hight and width then all I had to do was to hide the overflow .
That's how it looks in my browser.
.print-element {
min-width: 175px;
min-height: 45px;
border: solid 1px #ccc;
color: rgba(0, 0, 0, 0.87);
display: inline-flex;
justify-content: center;
align-items: center;
text-align: center;
background: #fff;
border-radius: 4px;
margin-right: 25px 25px 15px 0px;
cursor: move;
position: relative;
z-index: 1;
box-sizing: border-box;
padding: 10px 50px 10px 10px;
transition: box-shadow 200ms cubic-bezier(0, 0, 0.2, 1);
box-shadow: 0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12);
}
.resize-circle {
position: relative;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: white;
border: .1px solid white;
color: #aaa;
cursor: pointer;
}
span {
width: 20px;
height: 20px;
background: white;
position: absolute;
top: -7px;
border-radius: 50%;
right: -7px;
overflow: hidden;
}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<div class="print-element">
Tag Number
<span><i class="material-icons resize-circle">highlight_off</i></span>
</div>
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
I'm trying to position some text in the middle of a CSS box. i tired using top:20px; but this moved the whole but rather than the text. any idea how can i do this?
here is my code: jsfiddle
div {
background: #ff9600;
background: rgba(255, 150, 0, 0.95);
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
-moz-box-shadow: inset 0 0 0 1px rgba(255, 182, 78, 1), 0 0 20px rgba(0, 0, 0, 0.6);
-webkit-box-shadow: inset 0 0 0 1px rgba(255, 182, 78, 1), 0 0 20px rgba(0, 0, 0, 0.6);
box-shadow: inset 0 0 0 1px rgba(255, 182, 78, 1), 0 0 20px rgba(0, 0, 0, 0.6);
text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.1);
text-align: center;
z-index: 10;
}
<body>
<div>text</div>
</body>
Example 1
something like: this fiddle.
It uses the css of:
div {
height: 100%;
width: 100%;
background: #000;
font-size: 12px;
font-style: oblique;
color: #FFF;
text-align: center;
margin-top: 20px;
margin-left: 5px;
line-height: 80px;
}
which could be quite beneficial for you. :)
Example 2
A more versatile way would be to use span like this demo
which uses:
div {
width: 250px;
height: 100px;
line-height: 100px;
text-align: center;
border: 1px solid #123456;
}
span {
display: inline-block;
vertical-align: middle;
line-height: normal;
}
Possible Alternative to (2)
A slight variation of the second example would be to treat the div like a table cell, so altering the above css to:
div {
display: table;
width: 250px;
height: 100px;
text-align: center;
border: 1px solid red;
}
span {
display: table-cell;
vertical-align: middle;
}
And so this should also work for you.
Try to this
Remove this css in
width:100%;
height:100%;
add this css
left:0;
right:0;
top:0;
bottom:0;
padding-top:20px;
Demo
You could use padding to move the text inside the box.
However, I think that you should create a tag (a box) especially for the text, and give it some css property to center this box in the center of the main div (the main box).
Try this my code:
<div>
<span class="vertical-text">
TEXT
</span>
</div>
$('.vertical-text').each(function()
{
parent_height = $(this).parent().height();
$(this).parent().css(
{
'height': parent_height + 'px',
'line-height': parent_height + 'px',
});
$(this).css(
{
'line-height': 'normal',
'display': 'inline-block',
});
});
Demo: http://jsfiddle.net/Silon/caonccjx/
I'm wanting to align the text in my blog posts with the edges of my images. Right now the body of text is slightly skewed to the left. And also, what code do I need to enter so that the text is justified and where exactly do I enter it?
The site is: http://www.studywithstyleblog.com
And below is some of the code:
.post {
margin: 0 0 $(post.margin.bottom) 0;
}
h3.post-title, .comments h4 {
font: $(post.title.font);
margin: 0em 0 0;
}
.post-body {
font-size: 110%;
line-height: 1.4;
position: relative;
width: 700px;
}
.post-body img, .post-body .tr-caption-container, .Profile img, .Image img,
.BlogList .item-thumbnail img {
padding: $(image.border.small.size);
background: $(image.background.color);
border: 1px solid $(image.border.color);
-moz-box-shadow: 1px 1px 5px rgba(0, 0, 0, .1);
-webkit-box-shadow: 1px 1px 5px rgba(0, 0, 0, .1);
box-shadow: 1px 1px 5px rgba(0, 0, 0, .1);
}
.post-body img, .post-body .tr-caption-container {
padding: 3px;
}
.post-body .tr-caption-container {
color: $(image.text.color);
}
.post-body .tr-caption-container img {
padding: 0;
background: transparent;
border: none;
-moz-box-shadow: 0 0 0 rgba(0, 0, 0, .1);
-webkit-box-shadow: 0 0 0 rgba(0, 0, 0, .1);
box-shadow: 0 0 0 rgba(0, 0, 0, .1);
}
.post-header {
line-height: 1.6;
font-size: 90%;
}
.post-footer {
margin: 20px -2px 0;
padding: 5px 10px;
float: none;
width: 700px;
color: $(post.footer.text.color);
background-color: $(post.footer.background.color);
border-bottom: 1px solid $(post.footer.border.color);
line-height: 1.6;
font-size: 90%;
}
Thanks for your help!
The problem is in your code on your page.
You have <div> tags around your paragraphs instead of <p> tags.
The beginning of your faux-paragraphs are:
<div class="separator" style="clear: both; text-align: left;">
If you can change that "text-align" to justify instead of left, you'll be golden.
If you can get away from the inline CSS, you'll be better for it in the long run too.
The following line will justify your text:
text-align: justify;
I was trying to move the text slightly to the right. But it is impossible to implement in your code. You must have to change your code.There is 1 way to do it
1) Change the class of your paragraphs/text divs to "separator2" instead of "separator" and modify your CSS file like below:
.separator2
{
margin-left:20px
}
Adjust the margin-left accordingly. I have just added dummy value.
I'd like to know why my class .top does not work for my second DIV wrapper top? I would expect to have 200px between the bottom of the picture on the right and the top of the red DIV but it's not working. See JSFIddle
HTML
<div class="wrapper top">
<div class="block-1">
<p><span>ddfsfsdsfds</p>
<p>fdsfsdfs.</p>
<p>dfsdfdsfds.</p>
</div>
<div class="block-2"><img src="images/136147555-e1329752650296-287x300.jpg" alt="136147555-e1329752650296-287x300" width="287" height="300"></div>
</div><!-- End wrapper -->
<div class="wrapper top">
<div class="block-100pc">
block-100pc
</div>
</div>
CSS
body {
background: #F2F2F2;
}
.top {
margin-top: 200px;
}
.wrapper {
position: relative;
display: block;
margin-right: auto;
margin-left: auto;
width: 980px;
}
.block-1 {
float: left;
box-sizing: border-box;
padding: 20px;
width: 60%;
text-align: justify;
background-clip: border-box;
background: #fff;
-webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
-moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}
.block-1 span {
color: #124191;
font-weight: bold;
}
.block-2 {
float: right;
overflow: hidden;
box-sizing: border-box;
width: 35%;
padding: 20px;
background-clip: border-box;
background: #fff;
-webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
-moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
text-align: justify;
}
.block-100pc {
overflow: hidden;
box-sizing: border-box;
width: 100%;
padding: 20px;
background-clip: border-box;
background: #fff;
-webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
-moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
text-align: justify;
clear: both;
background: red;
}
That is because of the floated elements. They do not "count into" the height of their container, unless they are cleared.
There are several clearing techniques you can use, for example setting overflow: hidden on the container:
.wrapper {
overflow: hidden;
}
jsFiddle Demo
.block-1 {
margin-top: 200px;
}
or
.top {
margin-bottom: 200px;
}
either one should work
The margin-top doesn't work in your case because the two block that are above it are floated. the margin-top property applies to the top of the parent.
In order to see a top margin, you will have to apply a margin-top= height of the hieghest floated div + the margin you want.
You have some broken code in your fiddle, I've updated it with some fixes. Another thing is that you are not taking into account your padding when you've set the width of block-1 and block-2, therefor they are overlapping. Fix your block-1 width down to a lower percent to allow for the padding on the blocks. Here is an updated fiddle: http://jsfiddle.net/pB5kq/5/
<div class="wrapper top">
<div class="block-1">
<p><span>ddfsfsdsfds</span></p>
<p>fdsfsdfs.</p>
<p>dfsdfdsfds.</p>
</div>
<div class="block-2">
<img src="images/136147555-e1329752650296-287x300.jpg" alt="136147555-e1329752650296-287x300" width="287" height="300"></img>
</div>
<div class="wrapper top">
<div class="block-100pc">
block-100pc
</div>
</div>
Along with the other answers regarding floating divs and clearing, this should help.