CSS circle with dynamic text inside - css

I need to build a circle shape (in css) which has 2 lines of text that could change in length based on translation selected and always centered.
So far I have this:
h3 {
background-color: #fcd141;
border-radius: 50%;
padding: 12px 5px 5px 5px;
margin-top: 30px;
width: 20%;
height: 20%;
}
<h3>
<span style="vertical-align: middle;">98%</span>
<span style="margin-top: -4px; display: block;">Ratingfasdasfasfsad</span>
</h3>
The circle needs to respond dynamically to the length of the text keeping the aspect ration intact.

You can have a look at the code as in your code it looks like an ellipse to me
.circle-text {
width: 50%;
padding 10px;
}
.circle-text:after {
content: "";
display: block;
width: 100%;
height: 0;
padding-bottom: 100%;
background: #4679BD;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
border-radius: 50%;
}
.circle-text div {
float: left;
width: 100%;
padding-top: 50%;
line-height: 1em;
margin-top: -0.5em;
text-align: center;
color: white;
}
<div class="circle-text">
<div>I'm asddddddssssssssssssssssssasdasdashd asfafjsldfashdfisdpf sdjf pe!</div>
</div>

You could use vw (view width units) for this:
note
transform is used for vertical alignment only.
h3 {
background-color: #fcd141;
border-radius: 50%;
padding: 20px;
margin-top: 30px;
width: 20vw;
height: 20vw;
text-align: center;
word-wrap: break-word;
position: relative;
}
h3 span {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h3>
<span> 98% <br />
Ratingfasdasfasfsad</span>
</h3>
I was also able to remove your inline styling, and combined your two spans into one.

Related

How to remove borders under play button and logo img in CSS?

How to remove borders under play button and around logo img in CSS?
How to remove borders under play button and around logo img in CSS?
How to remove borders under play button and around logo img in CSS?
How to remove borders under play button and around logo img in CSS?
How to remove borders under play button and around logo img in CSS?
.fullscreen {
height: 100%;
width: 100%;
background: no-repeat url('https://www.planetware.com/wpimages/2019/10/switzerland-in-pictures-most-beautiful-places-matterhorn.jpg') center / cover;
}
.line_horiz {
position: absolute;
width: 3px;
height: 100%;
background-color: rgba(255, 255, 255, 1);
top: 0;
left: 50%;
}
.line_vert {
position: absolute;
width: 100%;
height: 3px;
background-color: rgba(255, 255, 255, 1);
top: 20%;
left: 0;
}
.logo-img {
position: absolute;
width: 100px;
height: 100px;
border: 3px solid #ffffff;
background: #ffffff;
transform: translate(-50%, -50%);
top: 20%;
left: 50%;
z-index: 1;
display: flex;
align-items: center;
justify-content: center;
text-transform: uppercase;
}
.btn {
position: absolute;
width: 100px;
height: 100px;
border: 3px solid #ffffff;
transform: translate(-50%, -50%);
top: 50%;
left: 50%;
z-index: 1;
}
.btn::after {
content: '';
display: block;
width: 60px;
height: 60px;
background: #ffffff;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<div class="fullscreen">
<span class="line_vert"></span>
<span class="line_horiz"></span>
<div class="logo-img">Logo img</div>
<div class="btn"></div>
</div>
As the horizontal and vertical lines are styling rather than informational content one suggestion is to remove them from the body of the HTML and instead create them using linear gradients on the background of the fullscreen element. That way they don't for example get looked at by screen readers. Also, using linear gradients means we can have 'gaps' in the lines where we want them.
This snippet just does the calculation of the gap for the btn element as the logo element has background white so it doesn't matter that the 'line' goes right across. If this changes then put in a linear gradient with gap calculations in a similar way to that done for the btn.
Note, box-sizing with content has been used and explicitly stated (so borders are included in the calculations and padding is set to zero) in case it has been altered elsewhere in the code.
body {
width: 100vw;
height: 100vh;
}
.fullscreen {
/* set up some variables to make it easier to change things later if you want to */
--logoMid: calc(20% - var(--borderW));
--btnW: 100px;
--btnMid: 50%;
/* position from the top to the middle of the btn */
--borderW: 3px;
--btnTop: calc(var(--btnMid) - (var(--btnW) / 2) - (var(--borderW) / 2));
/* actual position of top of btn element */
--btnBottom: calc(var(--btnTop) + var(--btnW) + var(--borderW));
box-sizing: content-box;
height: 100%;
width: 100%;
background-image: linear-gradient(white 0%, white var(--btnTop), transparent var(--btnTop), transparent var(--btnBottom), white var(--btnBottom), white 100%), linear-gradient(to right, white 0, white 100%), url('https://www.planetware.com/wpimages/2019/10/switzerland-in-pictures-most-beautiful-places-matterhorn.jpg');
background-size: var(--borderW) 100%, 100% var(--borderW), cover;
background-position: calc(var(--btnMid) - (var(--borderW) / 2)) 0, 0 var(--logoMid), center top;
background-repeat: no-repeat no-repeat;
margin: 0;
padding: 0;
position: relative;
}
.logo-img {
box-sizing: content-box;
position: absolute;
width: 100px;
height: 100px;
border: 3px solid #ffffff;
background: #ffffff;
transform: translate(-50%, -50%);
top: 20%;
left: 50%;
z-index: 1;
display: flex;
align-items: center;
justify-content: center;
text-transform: uppercase;
margin: 0;
padding: 0;
}
.btn {
box-sizing: content-box;
margin: 0;
padding: 0;
position: absolute;
width: 100px;
height: 100px;
border: 3px solid #ffffff;
transform: translate(-50%, -50%);
top: 50%;
left: 50%;
z-index: 1;
}
.btn::after {
box-sizing: content-box;
content: '';
display: block;
width: 60px;
height: 60px;
background: #ffffff;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<div class="fullscreen">
<div class="logo-img">Logo img</div>
<div class="btn"></div>
</div>
Note: run the snippet in full screen as there won't be enough room to show the gap between the logo and btn on the small snippet viewport.
Here is my solution, Its not perfect, but it will give you a good starting points.
I have changes your HTML structure, by removing the divs that create the lines, Instead, I have used pseudo selectors to draw the lines.
Note that, you will have to tweak some of these numbers to properly fit your content.
Please run the example in full screen mode
.fullscreen {
height: 100vh;
width: 100%;
background: no-repeat url("https://www.planetware.com/wpimages/2019/10/switzerland-in-pictures-most-beautiful-places-matterhorn.jpg") center/cover;
}
.logo-img {
position: absolute;
width: 100px;
height: 100px;
border: 3px solid #ffffff;
background: #ffffff;
transform: translate(-50%, -50%);
top: 100px;
left: 50%;
z-index: 1;
display: flex;
align-items: center;
justify-content: center;
text-transform: uppercase;
}
.logo-img:before {
content: "";
position: absolute;
height: 3px;
width: calc(50vw - 90px);
background-color: #ffffff;
top: 50%;
left: 130px;
display: block;
}
.logo-img:after {
content: "";
position: absolute;
height: 3px;
width: calc(50vw - 90px);
background-color: #ffffff;
top: 50%;
right: 130px;
display: block;
}
.btn {
position: absolute;
width: 100px;
height: 100px;
border: 3px solid #ffffff;
transform: translate(-50%, -50%);
top: 50%;
left: 50%;
z-index: 1;
padding: 20px;
box-sizing: border-box;
}
.btn .inner {
width: 100%;
height: 100%;
background: white;
}
.btn:after {
content: "";
display: block;
width: 3px;
height: calc(50vh - 48px);
background: #ffffff;
position: absolute;
top: 100%;
left: 50%;
}
.btn:before {
content: "";
display: block;
width: 3px;
top: calc(-50vh + 220px);
background: #ffffff;
position: absolute;
bottom: 100%;
left: 50%;
}
<div class="fullscreen">
<div class="logo-img">Logo img</div>
<div class="btn">
<div class="inner"></div>
</div>
</div>

How to manage content dimension?

I need to create a circle with an image inside, so far I almost achieved this but I want set the content dimension too, this is my code:
.circle {
position: absolute;
z-index: 10;
top: -25%;
left: 50%;
border: 5px solid #a7151f;
margin: 0;
padding: 0;
height: 100%;
line-height: 0;
text-align: center;
text-transform: uppercase;
transform: translateX(-50%);
background-color: #a7151f;
width: 500px;
height: 400px;
border-radius: 50%;
content: url("logo");
}
<img class="img-responsive center-block circle">
this is a fiddle.
As you can see I have to display only half of the circle, but the problem is that the logo is not entire visible. How can I manage this?
To fix this you needed to give the img a z-index greater than the circles and then center it ontop of the circle.
Here's the code:
.circle{
background-color: red;
position: absolute;
top: -250px;
left: 50%;
border: 5px solid #a7151f;
margin: 0;
padding: 0;
height: 100%;
line-height: 0;
text-align:center;
text-transform: uppercase;
transform: translateX(-50%);
background-color: #a7151f;
width: 500px;
height: 400px;
border-radius: 50%;
}
.img {
content: url("https://www.google.it/logos/doodles/2019/rugby-world-cup-2019-opening-day-6753651837108235-l.png");
z-index: 10;
position: absolute;
left: 50%;
transform : translateX(-50%);
}
<div class="circle">
</div>
<div class="img">
</div>
here is the jsfiddle fix: http://jsfiddle.net/t5L49f7g/
Hope this helps!

How to centre a shape in css

I am creating a website screen as a temporary "coming soon page". I have a circle behind some text. The text always seems to be centred on the page no matter the size of the browser window but the circle seems to move locations on different sizes. Is there a way for me to have the circle be completely behind the text?
Being new to code I followed some tutorials but none seemed to work
Heres the website in question: http://unixcast.com/
body{
margin: 0px;
padding: 0px;
background-color: #19181D;
}
.circle{
height: 400px;
width: 400px;
border-radius: 50%;
background: linear-gradient(#313247 0%,#19181D 30%);
position: absolute;
top: 20%;
left: 35%;
}
.circle:before,
.cirlce:after{
content: '';
height: 400px;
width: 400px;
background: linear-gradient(#FF849D 0%,#FF849D 5%, #2D2133 25%);
border-radius: 50%;
position: absolute;
top: 42%;
left: 50%;
transform: translate(-50%, -50%);
-webkit-filter:blur(7px);
z-index: -1;
}
.cirlce:after{
width: 415px;
top: 35%;
-webkit-filter:blur(14px);
opacity: .3;
}
.unixcast{
font-family: sans-serif;
font-size: 40px;
color: white;
letter-spacing: 20px;
position: absolute;
top: 40%;
left: 50%;
transform: translate(-50%, -50%)
}
.msg{
font-family: sans-serif;
font-size: 20px;
color: white;
letter-spacing: 20px;
text-align: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<span class="circle"></span>
<span class="unixcast"> UNIXCAST </span>
<span class="msg">IS COMING SOON!</span>
<span class="notifymsg"> GET NOTIFIED WHEN IT'S READY</span>
<span class="field">
<input type="email" name="ENTER YOUR EMAIL"/>
<button>NOTIFY ME</button>
</span>
</body>
</html>>
I expected to see the circle directly behind the text but it seems to move with different size screens and windows
please write this css for you circle class
.circle {
height: 400px;
width: 400px;
border-radius: 50%;
background: linear-gradient(#313247 0%,#19181D 30%);
position: absolute;
left: 0px;
right: 0px;
margin: auto;
top: 0px;
bottom: 0px;
}

CSS Span forcing page to be wider it should be

The error specifically is that the span element has a width of 900 pixels and it forces the page to scroll horizontally due to it extending so far at smaller screen sizes. I tried using the overflow: hidden property but that does not stop the scrolling.
The reason why I need 900 pixels is so my text and borders are centered and my border doesn't split into two parts. In addition, this text is over a carousel slider of images. The error looks as such:
http://i.imgur.com/iAd16ml.png
My goal is to crop the page's width where the element overextends at. This is my code:
`
#title-display{
vertical-align: middle;
text-align: center;
justify-content: center;
position: absolute;
top: 50%;
left: 50%;
margin: -40px 0 0 -450px;
}
#title-display span{
width: 900px;
float: left;
position: absolute;
}
#title-display h1 {
display: inline;
text-transform: uppercase;
border-width: 8px;
border-style: solid;
border-color: white;
padding: 10px;
color: white;
font-size: 4vw;
}
`
I use margin: -40px 0 0 -450px; to center the text.
Here is some html in case:
<div id="title-display">
<span>
<h1><strong>Adrian's Workflow<strong></h1>
<p class="kicker">Designer // Programmer // Youtuber</p>
</span>
</div>
You could position the #title-display element at 50%, 50% then use transform: translate(-50%, -50%) to offset it by half its width and height regardless of its actual size. Like so.
body {background:#666;}
#title-display{
position: fixed;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align:center;
}
#title-display h1 {
text-transform: uppercase;
border-width: 8px;
border-style: solid;
border-color: white;
padding: 10px;
color: white;
font-size: 4vw;
white-space: nowrap;
}
<header id="title-display">
<h1><strong>Adrian's Workflow</strong></h1>
<p class="kicker">Designer // Programmer // Youtuber</p>
</header>

Popup window width resizing when not needed

So I have this thing popup-window on my homepage that I fill with some content. The problem I'm having with it is that it's resizeing way to early.
I don't want the popup to resize before getting to big for the window to handle.
How am I going to solve this? Been at it for some time, can't figure it out.
You can try it out in the jsiffle url, resize the width of the preview window and you'll see it shrinks before it's even needed.
http://jsfiddle.net/82gvnamL/
CSS:
#popup {
position: absolute;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.75);
z-index: 2;
}
#popup #loading {
height: 32px;
width: 32px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
background: url('../img/ajax-loading.gif') no-repeat;
background-size: 32px 32px;
display: inline-block;
}
#popup #container {
max-width: 95%;
max-height: 95%;
padding: 10px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
background: #111;
-moz-border-radius: 10px 10px 10px 10px;
-webkit-border-radius: 10px 10px 10px 10px;
border-radius: 10px 10px 10px 10px;
}
#popup #content {
width: 100%;
font-family: 'Oxygen', sans-serif;
font-size: 12px;
color: #ccc;
text-align: left;
line-height: 16px;
}
#popup #close {
width: 20px;
height: 16px;
padding: 4px 0 0 0;
border: 1px solid #333;
border-radius: 50%;
float: right;
background: #222;
position: absolute;
top: -7px;
right: -7px;
font-family: 'Nunito', sans-serif;
font-size: 12px;
text-align: center;
color: #fff;
line-height: 12px;
cursor: pointer;
}
#popup #close:before {
content: 'X';
}
HTML:
<div id="popup">
<div id="container">
<div id="close"></div>
<div id="content">
<p>Very long string in here that should not get cut off until window width is too small. If you understand what I'm saying.</p>
</div>
</div>
</div>
Try changing the container's width like so"
#popup #container {
max-width: 255px;
width: 75%;
}
So on larger screens it will be a fixed width of 255px and on smaller screens it will shrink to 75% width.

Resources