I'm trying to create a circle border around a number like so:
But so far all my attempts have resulted in an oval:
Codepen to see it live
SCSS code so far
$browser-context: 16;
#function em($pixels, $context: $browser-context) {
#return #{$pixels/$context}em;
}
body {
line-height: 1.6;
display: flex;
flex-direction: column;
min-height: 100vh;
font-family: 'PT Sans', sans-serif;
background: #e5dde1;
}
ul {
margin: 0;
padding: 0;
list-style: none;
}
.header-nav {
background-color: #ff4c61;
color: white;
font-family: 'Oswald', sans-serif;
}
.category-nav ul {
background-color: #212d5b;
color: #ff4c61;
display: flex;
justify-content: space-evenly;
}
.category-nav a {
font-size: em(34);
text-decoration: none;
}
.category-nav .circled {
border-radius: 50%;
width: em(12);
height: em(12);
padding: em(4);
border: em(1) solid #ff4c61;
}
HTML:
<header class="header-nav">
<h1> APP</h1>
</header>
<nav class="category-nav">
<ul>
<li>A</li>
<li>B</li>
<li>C <span class="circled">3</span></li>
</ul>
</nav>
I been experimenting different solutions so far and I think the problem comes mostly from the fact that container of the number is an inline element (span). Whenever I switch the class .circled to a div instead or set the display to block, I get a perfect circle but then the number is pushed out and it breaks the flex layout. I wonder if there's any way to get the circle to work with a span?
For your .circled class you need to add the following styles:
.category-nav .circled {
...
line-height: em(12); /* needs to match the height */
display: inline-block; /* needs to not be an inline element */
text-align: center; /* center the character*/
}
You could make it an inline-block. Adding this to your example worked for me:
display: inline-block;
line-height: em(12);
text-align: center;
Check this answer for more information
$browser-context: 16;
#function em($pixels, $context: $browser-context) {
#return #{$pixels/$context}em;
}
body {
line-height: 1.6;
display: flex;
flex-direction: column;
min-height: 100vh;
font-family: 'PT Sans', sans-serif;
background: #e5dde1;
}
ul {
margin: 0;
padding: 0;
list-style: none;
}
.header-nav {
background-color: #ff4c61;
color: white;
font-family: 'Oswald', sans-serif;
}
.category-nav ul {
background-color: #212d5b;
display: flex;
justify-content: space-evenly;
}
.category-nav a {
color: #ff4c61;
font-size: em(34);
text-decoration: none;
}
.category-nav .circled {
border-radius: 50%;
width: em(12);
height: em(12);
padding: em(4);
border: em(1) solid #ff4c61;
}
.numberCircle {
display: inline-block;
border-radius: 50%;
behavior: url(PIE.htc);
/* remove if you don't care about IE8 */
width: 1em;
height: 1em;
padding: auto;
background: transparent;
border: 2px solid red;
color: red;
text-align: center;
font: 20px Arial, sans-serif;
}
<header class="header-nav">
<h1> APP</h1>
</header>
<nav class="category-nav">
<ul>
<li>A</li>
<li>B</li>
<li>C <div class="numberCircle">3</div></li>
</ul>
</nav>
Related
I am a beginner, and I am trying to get this to work.
How do I position the link to the right side of the connect text?
I want the text links to be inline but to the right.
.footer {
grid-area: footer;
margin-top: 38px;
margin-left: 100px;
margin-right: 100px;
height: 700px;
}
.footer-text {
padding: 200px 100px;
font-family: "Khula", sans-serif;
font-size: 80px;
color: #222222;
}
.footer-contact {
font-family: "Khula", sans-serif;
font-size: 35px;
color: #222222;
letter-spacing: -1px;
text-decoration: none;
padding: 100px 60px;
}
ul {
list-style-type: none;
text-decoration: none;
}
<div class="footer-text">Contact</div>
<ul>
<li>Email</li>
<li>LinkedIn</li>
<li>Instagram</li>
</ul>
You can add this to the .footer-text:
display:flex;
justify-content: right;
Note that this will apply to all childs of the .footer-text div.
Please update this two class properties as like the following code:
.footer-text {
padding: 200px 100px;
font-family: "Khula", sans-serif;
font-size: 80px;
color: #222222;
display: inline-block;
}
ul {
list-style-type: none;
text-decoration: none;
display: inline-block;
}
This can be solved easily by using a wrapper div. like so,
.wrapper {
overflow: auto;
}
.footer-text {
float: left;
}
.ul {
float: right;
}
<div class="wrapper">
<div class="footer-text">Contact</div>
<ul class="ul">
<li>Email</li>
<li>LinkedIn</li>
<li>Instagram</li>
</ul>
</div>
This is what I am trying to recreate. A basic nav.
As you can see here, there is an image next to the "ABOUT US" text, that is what I am having trouble with. How exactly can I make the img appear before the "ABOUT US" text? It always appears above it. Thanks in advance!
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
img {
max-width: 100%;
height: auto;
}
body {
font-family: "Open Sans",sans-serif;
}
.container {
max-width: 900px;
margin: 0 auto;
}
header {
padding: 2em 4em;
background-color: #121b21;
}
.nav-area {
list-style: none;
text-align: center;
}
.nav-area li {
display: inline-block;
padding: 0 1.5em;
color: #c4cbcf;
font-weight: 700;
font-size: 0.9em;
background-color: transparent;
}
<header>
<div class="container">
<nav>
<img src="header_logo.png" alt="Logo header">
<ul class="nav-area">
<li>ABOUT US</li>
<li>CONSULTING</li>
<li>SKYLIGHT</li>
<li>CONTACT</li>
</ul>
</nav>
</div>
</header>
Give a display:flex; property to nav and it will work :) Then you can adjust other CSS accordingly.
You may also set display:flex; on .nav-area, then you don't need inline-block on .nav-area li's.
.nav-area {
list-style: none;
text-align: center;
display:flex;
align-items:center;
}
CODEPEN WORKING DEMO: https://codepen.io/emmeiWhite/pen/WNGYJjq
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
img {
width:25px;
height: auto;
margin-left:1.5em;
}
body {
font-family: "Open Sans",sans-serif;
}
.container {
max-width: 900px;
margin: 0 auto;
}
header {
padding: 2em 4em;
background-color: #121b21;
}
nav{
display:flex;
align-items:center;
}
.nav-area {
list-style: none;
text-align: center;
}
.nav-area li {
display: inline-block;
padding: 0 1.5em;
color: #c4cbcf;
font-weight: 700;
font-size: 0.9em;
background-color: transparent;
}
<header>
<div class="container">
<nav>
<img src="https://picsum.photos/200" alt="Logo header">
<ul class="nav-area">
<li>ABOUT US</li>
<li>CONSULTING</li>
<li>SKYLIGHT</li>
<li>CONTACT</li>
</ul>
</nav>
</div>
</header>
I tried like this.
nav {
display: flex;
align-items: center;
justify-content: center;
}
If you want logo goes to left and nav-menu goes to right, try like this.
nav {
display: flex;
align-items: center;
justify-content: space-between;
}
Add the float attribute to the img CSS declaration to obtain the desired lay-out.
img {
max-width: 100%;
height: auto;
float: left;
}
I have the following HTML code
<header>
<nav>
<ul>
<li>Childhood</li>
<li>Early years</li>
<li>End</li>
<li>About this</li>
</ul>
</nav>
<div id="header-content">
<div id="info-title">
<h1 id="title">Henry Charles Bukowski Jr.</h1>
<h2>"Find what you love and let it kill you."</h2>
</div>
<figure>
<img src="images/charles-img1-2x.png" alt="Charles Bukowski's picture">
</figure>
</div>
<div id="tribute-info">
<p>8/16/1920</p>
<p>3/09/1994</p>
</div>
<span class="next">next section</span>
</header>
Which presents this page with the CSS:
https://prnt.sc/qx4qim
CSS:
/* Montserrat font import */
#import url('https://fonts.googleapis.com/css?family=Montserrat:100,300,400,600,700&display=swap');
* {
margin: 0;
padding: 0;
}
body {
background-color: #2F2E2E;
}
#main {
font-family: 'Montserrat', sans-serif;
color: #E0E1DD;
}
header,
section {
padding: 40px 60px;
height: calc(100vh - 80px);
}
#childhood,
#end {
background: #31303B;
}
ul {
list-style: none;
}
/* text style */
h1 {
font-weight: bold;
font-size: 80px;
}
h2 {
font-weight: 100;
font-size: 60px;
}
h3 {
font-weight: 600;
font-size: 60px
}
h4 {
font-weight: 600;
font-size: 50px;
}
p {
font-weight: 400;
font-size: 45px;
}
/* text style end */
/* nav link */
nav ul {
display: flex;
justify-content: space-between;
font-weight: 300;
font-size: 50px;
}
nav ul li a {
text-decoration: none;
color: #E0E1DD;
transition: .3s color;
}
nav ul li a:hover {
color: rgb(138, 128, 128);
}
/* nav links end */
#header-content {
display: flex;
}
#info-title{
align-self: center;
}
header figure img {
height: auto;
max-height: 850px;
max-width: 630px;
}
I align the texts on the page with the align-self: center property; but if I want to upload these texts a bit to look like this: https://prnt.sc/qx4qol
Is there a property that allows me to enter numeric values for vertical alignment?
The top property does not work since the display is set to flex
I think if you move:
<div id="tribute-info">
<p>8/16/1920</p>
<p>3/09/1994</p>
</div>
into the header-content element then modify the css to this, should do the trick:
.header { position: relative; }
.tribute-info { position: absolute; bottom: 15px; left: 15px; }
add display: flex; and flex-direction: column; to header
add margin: auto 0; to #header-content
/* Montserrat font import */
#import url('https://fonts.googleapis.com/css?family=Montserrat:100,300,400,600,700&display=swap');
* {
margin: 0;
padding: 0;
}
body {
background-color: #2F2E2E;
}
#main {
font-family: 'Montserrat', sans-serif;
color: #E0E1DD;
}
header,
section {
padding: 40px 60px;
height: calc(100vh - 80px);
}
#childhood,
#end {
background: #31303B;
}
ul {
list-style: none;
}
/* text style */
h1 {
font-weight: bold;
font-size: 80px;
}
h2 {
font-weight: 100;
font-size: 60px;
}
h3 {
font-weight: 600;
font-size: 60px
}
h4 {
font-weight: 600;
font-size: 50px;
}
p {
font-weight: 400;
font-size: 45px;
}
/* text style end */
/* nav link */
nav ul {
display: flex;
justify-content: space-between;
font-weight: 300;
font-size: 50px;
}
nav ul li a {
text-decoration: none;
color: #E0E1DD;
transition: .3s color;
}
nav ul li a:hover {
color: rgb(138, 128, 128);
}
/* nav links end */
#header-content {
display: flex;
margin: auto 0; /*add this*/
}
#info-title{
align-self: center;
}
header figure img {
height: auto;
max-height: 850px;
max-width: 630px;
}
/* add flex*/
header {
display: flex;
flex-direction: column;
}
<header>
<nav>
<ul>
<li>Childhood</li>
<li>Early years</li>
<li>End</li>
<li>About this</li>
</ul>
</nav>
<div id="header-content">
<div id="info-title">
<h1 id="title">Henry Charles Bukowski Jr.</h1>
<h2>"Find what you love and let it kill you."</h2>
</div>
<figure>
<img src="images/charles-img1-2x.png" alt="Charles Bukowski's picture">
</figure>
</div>
<div id="tribute-info">
<p>8/16/1920</p>
<p>3/09/1994</p>
</div>
<span class="next">next section</span>
</header>
So I've just learnt flexbox, however even after stating justify-content: flex-start; the list is not aligned to the left side of the column like so:
Image of the problem
Essentially I would like to align the list to the left side of the #navigation container so that there is not space present like in the image above. Any ideas what to change?
#navigation {
min-height: 50px;
width: 100%;
background-color: #2F4E6F;
}
.navflex {
display: flex;
flex-direction: row;
margin: 0;
list-style-type: none;
justify-content: flex-start;
}
.navflex a {
text-decoration: none;
text-decoration: none;
font-family: 'Open Sans';
font-size: 25px;
color: #FFFFFF;
display: block;
padding: 5px 25px;
text-align: center;
}
#home_button {
width: 38px;
height: 38px;
}
.tilde {
color: #FFFFFF;
font-size: 22px;
font-weight: bold;
font-family: 'Open Sans';
padding: 7px 0px;
}
#media all and (max-width: 800px) {
.navflex {
flex-direction: column;
flex-wrap: wrap;
}
.tilde {
display: none;
}
}
<div id="navigation">
<ul class="navflex">
<li>
<img src="images/home_button.png" alt="An icon representing a house." id="home_button">
</li>
<li>Phantom of the Opera</li>
<li class="tilde">~</li>
<li>The Lion King</li>
<li class="tilde">~</li>
<li>Wicked</li>
<li class="tilde">~</li>
<li>Bookings</li>
<li class="tilde">~</li>
<li><a href='#'>Location</a></li>
</ul>
</div>
Add padding: 0; to your ul (= .navflex) to avoid the default list padding. And if that isn't close enough to the left, also add padding-left: 0 to the li elements:
#navigation {
min-height: 50px;
width: 100%;
background-color: #2F4E6F;
}
.navflex {
display: flex;
flex-direction: row;
margin: 0;
list-style-type: none;
justify-content: flex-start;
padding: 0;
}
.navflex li {
padding-left: 0;
}
.navflex a {
text-decoration: none;
text-decoration: none;
font-family: 'Open Sans';
font-size: 25px;
color: #FFFFFF;
display: block;
padding: 5px 25px;
text-align: center;
}
#home_button {
width: 38px;
height: 38px;
}
.tilde {
color: #FFFFFF;
font-size: 22px;
font-weight: bold;
font-family: 'Open Sans';
padding: 7px 0px;
}
#media all and (max-width: 800px) {
.navflex {
flex-direction: column;
flex-wrap: wrap;
}
.tilde {
display: none;
}
}
<div id="navigation">
<ul class="navflex">
<li><img src="images/home_button.png" alt="An icon representing a house." id="home_button"></li>
<li>Phantom of the Opera</li>
<li class="tilde">~</li>
<li>The Lion King</li>
<li class="tilde">~</li>
<li>Wicked</li>
<li class="tilde">~</li>
<li>Bookings</li>
<li class="tilde">~</li>
<li><a href='#'>Location</a></li>
</ul>
</div>
I need the grey vertical line to be underneath "latest work" work. When I set the z-index to negative though it disappears, I assume under the body? Hoping this is a simple solution. I attached an image of my mockup to show what it should look like. I have a div with a background of #212121 so the copy "latest work" has padding above and below and makes it look like the line goes underneath.
body {
font-size: 16px;
background: #f9f9f9;
}
.container {
max-width: 1600px;
}
#dt-lpStatic {
height:60px;
width: 100%;
padding:6px 0;
font-family: 'Montserrat', sans-serif;
font-size: 0.875em;
text-transform: uppercase;
}
#dt-lpStatic ul {
float: left;
margin-top: 3px;
}
#dt-lpStatic ul li {
display: inline;
color:#545454;
margin-left:40px;
}
#dt-lpStatic ul li:nth-child(1) {
margin-left:0;
}
.subscribe-btn-muted {
padding:12px 50px;
border:2px solid #555;
border-radius: 13%/50%;
-webkit-border-radius: 13%/50%;
-moz-border-radius: 13%/50%;
float:right;
color:#555;
}
#hero {
width:100%;
background: #212121;
height:100vh;
}
#hero-content {
margin:30vh auto;
text-align: center;
}
#hero .secTitle-bg-dark {
width:200px;
padding: 15px 0;
font-family: 'Open Sans', sans-serif;
font-style: italic;
color: #555;
font-size: 1.5em;
font-weight: 300;
margin:30vh auto;
background: #212121;
}
.secTitle-bg-dark:after {
content:"";
position: absolute;
z-index: 0;
top: 65vh;
bottom: 0;
left: 50%;
border-left: 2px solid #313131;
}
<body>
<section id="hero">
<header id="dt-lpStatic">
<div class="container">
<ul>
<li><img src="imgs/logo-muted.png" alt="RH logo"></li>
<li>Home</li>
<li>Blog</li>
<li>About</li>
<li>Get In Touch</li>
</ul>
<div class="subscribe-btn-muted">Subscribe</div>
</div>
</header>
<div id="hero-content">
<img src="imgs/logo-full-big.png" alt="RH Visual Design logo">
<div class="secTitle-bg-dark">latest work</div>
</div>
</section>
</body>
This is actually a really great candidate for flexbox. You can simplify the code a lot just by doing this:
Edit: Just a friendly tip: Psuedo-elements should be prefixed with ::, like ::before and ::after. Psuedo-selectors only have one colon, like a:hover and input:focus.
body {
background-color: #333;
}
.latest-work {
color: #999;
display: flex;
flex-direction: column;
align-items: center;
}
.latest-work span {
display: block;
padding: 10px 0;
}
.latest-work::before,
.latest-work::after {
width: 1px;
height: 100px;
content: '';
background-color: #999;
}
<div class="latest-work">
<span>latest work</span>
</div>
Add display: block; to the :after element - pseudo elements require this for block layout.