Completely Centering text in Circular link - html

I've read related answers on the site regarding this topic. I did end up being able to center it by decreasing the font size, however, it left me with small text and a large circle.
Here it is:
<nav>
<ul>
<li class="circle">About
</li>
<li class="circle">Coding
</li>
<li class="circle">Health
</li>
<li class="circle">Contact
</li>
</ul>
</nav>
CSS
.circle {
width: 25px;
height: 25px;
border-radius: 50%;
font-size: 7px;
line-height: 25px;
text-align: center;
}
http://jsfiddle.net/theskinnyreader/c3evfj5b/
I would like to know how I can center text of the size in my code below and keep the size of the circle to a minimum.
CSS
.circle {
width: 10px;
height: 10px;
border-radius: 50%;
font-size: 10px;
line-height: 10px;
text-align: center;
}
http://jsfiddle.net/theskinnyreader/fdu1dqko/

This code works:
What changed here is i made the .circle have a relative position so that the text in the tag can have an absolute position. Then pace the anchor at 50% of top and 50% of left and translate it back 50% and up 50%. I only added the -webkit-transform because my browser is chrome but you should add one with -moz-, -ms-, and -o- as well
nav {
text-align: center;
padding: 10px 0;
margin: 20px 0 0;
}
nav ul {
list-style: none;
margin: 0;
10px;
padding: 0;
}
nav li {
display: inline-block;
margin: 20px;
padding: 3%;
border: 1px solid black;
}
.circle {
position: relative;
width: 25px;
height: 25px;
border-radius: 50%;
line-height: 25px;
text-align: center;
}
.circle a {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}

Related

Having trouble resizing an image in an :after element

I want to resize the image in an :after element but nothing seems to work, I finally managed to resize it and style it the way I want it using the display:flex but it only works on FireFox. Also whenever I try to put the image in a background or background-image it doesn't display the image at all, no idea what's wrong here.
Here you can see what the website https://tradeideasfx.com/2021/05/16/btc-usd-trade-idea/ it's the "long/short" button at the top of the post. If you view the website on FireFox the buttons look exactly as they should be, but on any other wbsite its all over the place. I appreciate any help in advance.
.post-tags {
float: left;
font-weight: bold;
list-style: none;
padding: 0;
margin: 0;
}
.post-tags>.Long {
color: #FFF;
background-color: #03cd08;
padding: 1px 10px 2px 10px;
border-radius: 10px;
display: inline-block;
}
.post-tags>.Short {
color: #FFF;
background-color: #fc0000;
padding: 1px 10px 2px 10px;
border-radius: 10px;
display: inline-block;
}
.post-tags>.Short:after {
content: url(https://tradeideasfx.com/wp-content/uploads/2021/07/arrow-icon.png);
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-o-transform: rotate(90deg);
-ms-transform: rotate(90deg);
transform: rotate(90deg);
display: inline-flex;
height: 25px;
width: 20px;
padding: 5px;
margin-top: -2px;
}
.post-tags>.Long:after {
content: url(https://tradeideasfx.com/wp-content/uploads/2021/07/arrow-icon.png);
display: inline-flex;
height: 25px;
width: 20px;
padding: 5px;
margin-top: -2px;
}
<span class="post-tags">
<a rel="tag" href="" class="Long">Long</a>
<a rel="tag" href="" class="Short">Short</a> </span>

Create Button with toggle and text with a single element

I'm trying to create a button out of a single html element. The button needs to have a toggle slider and the text needs to be aligned vertically and horizontally. So I thought I can make use of :before element to help me make that happen. Here is what I have tried:
div {
width: 140px;
height: 40px;
background-color: #B3B3B3;
color: #FFF;
float: left;
clear: both;
border-radius: 5px;
font-size: 12px;
}
div:before {
content: '';
display: block;
width: 20px;
height: 36px;
background-color: #4D4D4D;
position: relative;
left: 2px;
top: 2px;
float: left;
border-radius: 5px;
}
<div>Text Value</div>
I have 2 problems with the above code:
I can't position the text how I want and I have tried using text-align and position to move it around.
I am using a float, which means that it will affect behavior of other elements around it, and I really don't want that.
Is what I want possible with a single element?
Here is the JS Fiddle: https://jsfiddle.net/m3q5Lcjy/
EDIT: The centered text should not be centered on the whole element, but on the light gray area.
This is how I would do this:
Array.from(document.querySelectorAll('.toggler')).forEach((item) => {
item.addEventListener('click', e => {
item.classList.toggle('active');
})
});
.toggler {
display: flex;
align-items: center;
justify-content: center;
position: relative;
box-sizing: border-box;
padding-left: 24px;
width: 140px;
min-height: 40px;
background-color: #B3B3B3;
color: #FFF;
border-radius: 5px;
font-size: 12px;
text-align: center;
cursor: pointer;
transition: padding .25s ease;
}
.toggler.active {
padding: 0 24px 0 0;
}
.toggler:before {
content: '';
display: block;
width: 20px;
background-color: #4D4D4D;
position: absolute;
bottom: 2px;
left: 2px;
top: 2px;
border-radius: 5px;
/* transition to make it look smoother */
transition: left .4s ease;
z-index: 1;
}
.toggler.active:before {
left: calc(100% - 22px);
}
<div class="toggler">Text Value</div>
<hr />
<div class="toggler active">Text Value realllllyy long</div>
<hr />
<div class="toggler">Text Value really far too long for this tiny, tiny, ohhh so tiny button. I recommend using shorter text though, but it won't break not even if you have like 10 or more lines.</div>
If anything about this implementation is unclear, feel free to ask.
Use flexbox to center your text vertically and horizontally. Then use absolute positioning on your pseudo element. Make sure parent element has relative positioning applied so absolute positioned pseudo stays within the parent.
div {
display: flex;
align-items: center;
justify-content: center;
position: relative;
box-sizing: border-box;
padding-left: 24px; /* 20px for :before width, 4px for :before offset */
width: 140px;
height: 40px;
background-color: #B3B3B3;
color: #FFF;
border-radius: 5px;
font-size: 12px;
}
div:before {
content: '';
display: block;
width: 20px;
height: 36px;
background-color: #4D4D4D;
position: absolute;
left: 2px;
top: 2px;
border-radius: 5px;
}
<div>Text Value</div>
You could place the text in a paragraph.
<div class="thediv">
<p class="theText">
enter text here
</p>
</div>
.thediv{
Your own style.
}
.theText{
position: absolute;
transform: translate(-50%, -50%);
top: 50%;
left: 50%;
}
I don't see why you would want it be in one element.
If you do want that, you should give the div a padding.
div{
background-color: #B3B3B3;
color: #FFF;
float: left;
border-radius: 5px;
font-size: 12px;
padding: 20px 70px;
}

Create angled elements using html and css only

How to create the offer div with a background color using html and css only ?
What I'm asking is width and height of the offer div should be same as in picture.
I created this using html and CSS. However part of div is hidden in my solution because offer div has a larger width and height.
Code I have written :
.offer-text-wrapper {
display: inline-block;
position: absolute;
top: -39px;
left: -36px;
color: #FFF;
height: 72px;
width: 75px;
background: #f44336;
transform: rotate(-43deg);
}
.offer-text {
-moz-transform: rotate(-40deg);
-o-transform: rotate(-40deg);
display: inline-block;
margin-left: 21px;
line-height: 124px;
}
<div class="offer-text-wrapper">
<span class="offer-text"> Offer </span>
</div>
Edit :
Because width and height of offer-text-wrapper is larger, I'm having below issue when I added that to the bootstrap grid.
Have a look at the code snippet, it's basically just changing dimensions and position until you're happy with it.
Is this what you mean?
.offer-container { /* added container to show effect better */
width: 200px;
height: 100px;
overflow: hidden;
position: relative;
border: 1px solid #ccc;
border-radius: 12px;
margin: 40px;
}
.offer-text-wrapper {
display: inline-block;
position: absolute;
top: -29px;
left: -40px;
color: #FFF;
height: 72px;
width: 95px;
background: #f44336;
transform: rotate(-45deg);
text-align: center;
}
.offer-text {
display: inline-block;
line-height: 114px;
}
<div class="offer-container">
<div class="offer-text-wrapper">
<span class="offer-text">Offer</span>
</div>
</div>

Move mobile nav from left to right

I am trying to move mobile navigation from top left corner and slide in from left side to the right side. I've tried to change position settings from left to right, but it didn't work.
I will really appreciate any help!
Code below, thank you!
#wrapper {
position: absolute;
width: auto;
min-width: 60px;
height: 100%;
overflow: hidden;
margin: 0 auto;
padding: 0;
}
label {
cursor: pointer;
}
&:focus {
outline: none;
}
.menu {
position: absolute;
top: 0;
left: 0;
background: #fff;
width: 240px;
height: 100%;
transform: translate3d(-240px, 0, 0);
transition: transform 0.35s;
}
label.menu-toggle {
position: absolute;
right: -60px;
width: 60px;
height: 60px;
line-height: 0px;
display: block;
padding: 0;
text-indent: -9999px;
background: transparent url(https://cdn4.iconfinder.com/data/icons/wirecons-free-vector-icons/32/menu-alt-512.png) 50% 50% / 25px 25px no-repeat;
}
label.active {
background: transparent url(menu-cross.png) 50% 50% / 25px 25px no-repeat;
}
ul li>label {
background: url(https://cdn4.iconfinder.com/data/icons/ionicons/512/icon-arrow-right-b-128.png) 95% 50% / 16px 16px no-repeat;
}
a,
label {
display: block;
text-align: left;
padding: 0 30px;
line-height: 60px;
text-decoration: none;
margin: 0 auto;
color: #000;
}
&:hover {
color: #666;
}
.menu-checkbox{
display: none;
}
.menu .menu label.menu-toggle {
background: none;
}
.menu-checkbox:checked + .menu {
transform: translate3d(0, 0, 0);
}
<div id="wrapper">
<input type="checkbox" id="menub" name="menu" class="menu-checkbox">
<div class="menu">
<label class="menu-toggle" for="menub"><span>Toggle</span></label>
<ul>
<li>
link
</li>
<li>
link
</li>
<li>
link
</li>
</ul>
</div>
</div>
<!-- #wrapper -->
I believe you have overcomplicated your task. You could simply open new project on visual studio and go from there. This would be the best option, since the result you want to achieve is most likely the same.
Now if you do want to stick to this, you must go carefully through your style code and what could be preventing the item to align on the right side.

Create three vertical dots (ellipsis) inside a circle

I want to make a circle <div>, like this image:
I have tried this code.
.discussion:after {
content: '\2807';
font-size: 1em;
background: #2d3446;
width: 20px;
height: 20px;
border-radius: 100px;
color:white;
}
<div class="discussion"></div>
How can I do this correctly?
You could just use :after pseudo-element with content: '•••' and transform: rotate. Note that this is the bullet HTML special character •, or \u2022.
div {
position: relative;
background: #3F3C53;
width: 50px;
height: 50px;
color: white;
border-radius: 50%;
box-shadow: 0px 0px 15px 1px #4185BC;
margin: 50px;
}
div:after {
content: '•••';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) rotate(90deg);
font-size: 15px;
letter-spacing: 4px;
margin-top: 2px;
}
<div></div>
Improving on Nenad Vracar's answer, here's one that doesn't use text (so it's font-independent) and everything is centered nicely:
div {
position: relative;
background: #3F3C53;
width: 50px;
height: 50px;
border-radius: 50%;
box-shadow: 0px 0px 15px 1px #4185BC;
margin: 50px;
}
div:after {
content: '';
position: absolute;
left: 50%;
top: 50%;
width: 2px;
height: 2px;
margin-left: -1px;
margin-top: -1px;
background-color: white;
border-radius: 50%;
box-shadow: 0 0 0 2px white, 0 11px 0 2px white, 0 -11px 0 2px white;
}
<div></div>
Yet another answer, same as others except:
it uses the vertical ellipsis character (U+22EE)
text-align and line-height to center the content
does not use any pixel value
.discussion:after {
content: "\22EE";
/* box model */
display: inline-block;
width: 1em;
height: 1em;
/* decoration */
color: #FFFFFF;
background-color: #000000;
border-radius: 50%;
/* center align */
line-height: 1;
text-align: center;
}
<div class="discussion"></div>
<div class="discussion" style="font-size: 2em;"></div>
<div class="discussion" style="font-size: 3em;"></div>
<div class="discussion" style="font-size: 4em;"></div>
Note that U+2807 is actually a Braille pattern and the dots are not supposed to be centered.
Use this code.
.discussion {
width: 20px;
height: 20px;
border-radius: 50%;
position: relative;
background: #2d3446;
}
.discussion:after {
content: '\22EE';
font-size: 1em;
font-weight: 800;
color: white;
position: absolute;
left: 7px;
top: 1px;
}
<div class="discussion"></div>
Hope this helps!
I hope this is what you wanted! Otherwise feel free to ask.
.discussion{
display: block; /* needed to make width and height work */
background: #2d3446;
width: 25px;
height: 25px;
border-radius: 100px;
display: flex;
align-items: center;
justify-content: center;
}
.discussion:after {
content: '\2807';
font-size: 1em;
color: white;
margin-left: 15%;
}
<div class="discussion"></div>
Using text dots
.discussion{
width:50px;
height:50px;
text-align:center;
background-color:black;
border: 2px solid red;
border-radius: 100%;
}
.discussion text{
writing-mode: tb-rl;
margin-top:0.4em;
margin-left:0.45em;
font-weight:bold;
font-size:2em;
color:white;
}
<div class="discussion"><text>...</text></div>
.discussion:after {
content: '\2807';
font-size: 1em;
display: inline-block;
text-align: center;
background: #2d3446;
width: 20px;
height: 20px;
border-radius: 50%;
color: white;
padding:3px;
}
<div class="discussion"></div>
I have deleted (i found how to do it) all my post, the following code works for 3 vertical dot into a black circle
.discussion:after{
display:inline-block;
content:'\22EE';
line-height:100%;
border-radius: 50%;
margin-left:10px;
/********/
font-size: 1em;
background: #2d3446;
width: 20px;
height: 20px;
color:white;
}
<div class="discussion"></div>