How to make a circular image? - css

The problem is this image, I want to make it circular, I used border-radius:50% and set equal height and width. I searched for the question and found this one How to make a circular image in css and I tried to make something similar but I used flexbox.
<div className='nav-bar'>
<ul className='nav-links'>
<li className='nav-link'>
<Link >
Home
</Link>
</li>
<li className='nav-link'>
<Link >
Add question
</Link>
</li>
<li className='nav-link'>
<Link >
Leaderboard
</Link>
</li>
</ul>
<ul className='nav-user-sign-out'>
<li className='nav-item'>
<p>Welcome, </p>
</li>
<li className='nav-item'>
<div className='avatar'>
<img src={} alt='' />
</div>
</li>
<li className='nav-item'>
<button className='sign-out'>
Sign out
</button>
</li>
</ul>
</div>;
.nav-bar {
display: flex;
align-items: center;
justify-content: space-between;
}
.nav-links {
display: flex;
}
Link {
padding: 10px;
}
.nav-user-sign-out {
display: flex;
align-items: center;
justify-content: space-around;
}
.sign-out {
padding: 10px;
}
.avatar {
width: 30px;
height: 30px;
border-radius: 50%;
overflow: hidden;
}
img {
height: 100%;
width: 100%;
}

Either make height and width of fixed and equal value or if you are using percentage confirm to that image has same width and height.

I just made a codesandbox with your code, and it's working without an issue, maybe the issue is with another CSS class that declared somewhere else, or maybe the object-fit property on the image. I'll put the link to my sandbox here, feel free to go ahead and try it with your code. I added object-fit to the image styles there.
working example

.nav-bar {
display: flex;
align-items: center;
justify-content: space-between;
}
.nav-links {
display: flex;
}
Link {
padding: 10px;
}
.nav-user-sign-out {
display: flex;
align-items: center;
justify-content: space-around;
}
.sign-out {
padding: 10px;
}
.avatar {
width: 30px;
height: 30px;
border-radius: 50%;
overflow: hidden;
}
img {
height: 100px;
width: 105px;
border-radius: 50%;
}
<div className='nav-bar'>
<ul className='nav-links'>
<li className='nav-link'>
<Link >
Home
</Link>
</li>
<li className='nav-link'>
<Link >
Add question
</Link>
</li>
<li className='nav-link'>
<Link >
Leaderboard
</Link>
</li>
</ul>
<ul className='nav-user-sign-out'>
<li className='nav-item'>
<p>Welcome, </p>
</li>
<li className='nav-item'>
<div className='avatar'>
<img src="https://media.sproutsocial.com/uploads/2015/02/Facebook_Embed.png" alt=''width ="200" />
</div>
</li>
<li className='nav-item'>
<button className='sign-out'>
Sign out
</button>
</li>
</ul>
</div>

Related

Remove gap between flex item

In menu item, i am using display: Flex
on hover there is space between items
Used: Align-content: stretch but no result
see image: space showing
My Code
.menu {
display: flex;
justify-content: space-between;
}
.menu li {
display: flex;
padding: 10px;
}
.menu li:hover {
background-color: #ddd;
}
.menu li a {
display: flex;
flex-direction: column;
align-items: center;
}
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css"
/>
<ul
class="menu dflx border-top-light px-10 container py-10 justify-between items-center"
>
<li>
<i class="fa-solid fa-magnifying-glass"></i> Explore
</li>
<li>
<i class="fa-solid fa-location-dot"></i> Attractions
</li>
<li>
<i class="fa-regular fa-star"></i> Latest Deals
</li>
<li>
<i class="fa-solid fa-bars"></i> Menu
</li>
</ul>
Just use flex: 1; justify-content: center; in .menu li
Working example
.menu {
display: flex;
justify-content: space-between;
}
.menu li {
display: flex;
padding: 10px;
flex: 1;
justify-content: center;
}
.menu li:hover {
background-color: #ddd;
}
.menu li a {
display: flex;
flex-direction: column;
align-items: center;
}
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css"
/>
<ul
class="menu dflx border-top-light px-10 container py-10 justify-between items-center"
>
<li>
<i class="fa-solid fa-magnifying-glass"></i> Explore
</li>
<li>
<i class="fa-solid fa-location-dot"></i> Attractions
</li>
<li>
<i class="fa-regular fa-star"></i> Latest Deals
</li>
<li>
<i class="fa-solid fa-bars"></i> Menu
</li>
</ul>

I need centering flexbox columns in conteiner

My 3 images need to be in screen center. I use flexbox. After adding size to images all of them go to left. Also I can't throw off margin
This is what I need
This is what I have
My cod:
.collection {
list-style: none;
display: flex;
flex-direction: column;
align-items: center;
}
<ul class="collection">
<li><img class="col-img" src="images/bouquets.jpeg" alt=""><p class="col-text">Букети</p></li>
<li><img class="col-img" src="images/natural_flowers.jpeg" alt=""><p class="col-text">Живі квіти</p></li>
<li><img class="col-img" src="images/own_bouquet.png" alt=""><p class="col-text">"Свій" букет</p></li>
</ul>
This can be solved by absolutely positioning your p tag on top of your image. Use translate and top/left rules to move it to the center. Also make the a tag as display:block so it effectively covers the image. See below.
Edited:
There were a few small tweaks, the a tag had a 3 pixels below it which are space for descenders. This has been removed using line-height and means that images stack directly on top of each other. In the comments it was also stated that the images needed to be cropped and centered. This was done with display: flex on the anchor tag and then using align-self: center to prevent it from shrinking to the size of the parent div. Finally they were cropped using overflow:hidden. Now that the anchor tag is using flexbox the need to use inset and translate isn't needed as they center anyway.
Hope this helps
.collection {
list-style: none;
display: flex;
flex-direction: column;
align-items: center;
padding-left: 0;
}
a {
display: flex;
align-items: center;
justify-content: center;
position: relative;
color: white;
line-height:1;
height: 200px;
overflow: hidden;
box-shadow: 0px 0px 20px 2px #757575;
}
a p {
position: absolute;
background-color: #A6BFEA;
padding: 1rem 2rem;
margin: 0;
box-shadow: 0px 0px 20px 2px #757575;
line-height:normal;
}
img {
align-self:center;
translate: auto -50%;
}
<ul class="collection">
<li>
<a href="#">
<img class="col-img" src="https://placekitten.com/500/300" alt="">
<p class="col-text">Букети</p>
</a>
</li>
<li>
<a href="#">
<img class="col-img" src="https://www.fillmurray.com/500/300" alt="">
<p class="col-text">"Свій" букет</p>
</a>
</li>
<li>
<a href="#">
<img class="col-img" src="https://www.placecage.com/500/300" alt="">
<p class="col-text">"Свій" букет</p>
</a>
</li>
</ul>
.collection {
list-style: none;
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
}
Something like this?
li {
margin-bottom: 3rem;
}
.collection {
list-style: none;
display: flex;
flex-direction: column;
align-items: center;
}
.container {
position: relative;
display: flex;
align-items: center;
justify-content: center;
}
.container p {
position: absolute;
background: green;
color: white;
}
<ul class="collection">
<li>
<a href="#">
<div class="container">
<img class="col-img" src="https://dummyimage.com/300x150/000/fff" alt="">
<p class="col-text">Букети</p>
</div>
</a>
</li>
<li>
<a href="#">
<div class="container">
<img class="col-img" src="https://dummyimage.com/300x150/000/fff" alt="">
<p class="col-text">Букети</p>
</div>
</a>
</li>
<li>
<a href="#">
<div class="container">
<img class="col-img" src="https://dummyimage.com/300x150/000/fff" alt="">
<p class="col-text">Живі квіти</p>
</div>
</a>
</li>
</ul>

Centering Bootstrap navbar

I am new to css. I will like to center brand logo and also the links in the navbar.
HTML
<nav class="navbar navbar-expand-md center">
<a class="navbar-brand" href="http://www.dimsum.dk" target="_blank">
<img src={% static 'media/HIDDEN DIMSUM logo final.png'%} width="100" alt="">
</a>
<button class="navbar-toggler navbar-dark" type="button" data-toggle="collapse" data-target="#main-navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="main-navigation">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Book Table</a>
</li>
<li class="nav-item">
<a class="nav-link" href="http://www.dimsumbox.dk" target="_blank">
Order Dimsum Box</a>
</li>
<li class="nav-item">
<a class="nav-link" href="http://www.dimsumshop.dk" target="_blank">
Order Takeaway</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#" target="_blank">
About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#" target="_blank">
Contact</a>
</li>
</ul>
</div>
</nav>
CSS
.navbar {
background: #d48498;
}
.nav-link {
color: black;
font-size: 24px;
font-weight: bold;
}
.navbar.center .nav-item {
text-align: center;
display: inline-block;
vertical-align: middle;
}
This is how the navbar looks right now
I want to have the logo centered and the links appearing in a new line also centered so it looks like
Logo
Link 1 Link 2 Link 3 Link 4
I have tried justify center in css but it doesn't work.
Add this bit to your css
#media (min-width: 768px) {
.navbar {
flex-flow: wrap;
}
.navbar-brand {
width: 100%;
text-align: center;
}
.navbar-brand img {
height: 50px; /*Set a logo size*/
width: auto;
}
.navbar-collapse {
justify-content: center;
}
}
use justify content: center and display: flex in css
display: flex;
justify-content: center;
for reference https://www.w3schools.com/cssref/css3_pr_justify-content.asp
add this css after bootstrap.css:
.navbar-brand {
display: flex;
width: 100%;
justify-content: center !important;
}
.navbar {
flex-wrap: wrap !important;
justify-content: center !important;
}
.navbar-nav{
width:100%;
justify-content:center !important
}

Image aespect ratio - max-width is required in Chrome but breaks mobile Safari

I have flexbox columns which contain images. The images have a max-width of 100% and need to maintain their aspect ratio.
I have a really strange bug that I'm not able to recreate outside of site. I'm afraid I cant share this so the code example is an approximation only.
<ul>
<li>
<img src="https://images.unsplash.com/photo-1575014774591-d036b92ae5ba?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=612&q=80" height="912" width="1462" />
</li>
<li>
<img src="https://images.unsplash.com/photo-1575014774591-d036b92ae5ba?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=612&q=80" height="912" width="1462" />
</li>
<li>
<img src="https://images.unsplash.com/photo-1575014774591-d036b92ae5ba?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=612&q=80" height="912" width="1462" />
</li>
<li>
<img src="https://images.unsplash.com/photo-1575014774591-d036b92ae5ba?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=612&q=80" height="912" width="1462" />
</li>
<li>
<img src="https://images.unsplash.com/photo-1575014774591-d036b92ae5ba?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=612&q=80" height="912" width="1462" />
</li>
<li>
<img src="https://images.unsplash.com/photo-1575014774591-d036b92ae5ba?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=612&q=80" height="912" width="1462" />
</li>
</ul>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
ul {
border: 1px solid red;
display: flex;
flex-wrap: wrap;
width: 400px;
list-style-type: none;
justify-content: space-between;
}
li {
width: 33%;
border: 1px solid blue;
padding: 0 10px;
margin-bottom: 10px;
display: flex;
}
img {
max-width: 100%;
height: auto;
}
https://jsfiddle.net/jms4vyk0/1/
In Chrome if I remove the height: auto; from the image then the aspect ratio breaks. However in iOS Safari the aspect radio works without height: auto; but breaks when I add it. In desktop Safari it's broken either way.

Flexbox css unordered list custom styling

I want to style my unordered list like this one below
Link to what i want to achive
My structure looks like:
<div class="tabs">
<ul class="tabs__labels">
<li class="0">
<a class="active" href="#">
<img/>
<div>something</div>
</a>
</li>
<li class="1">
<a class="" href="#">
<img/>
<div>something1</div>
</a>
</li>
...
</ul>
</div>
Is it a good idea to name the list classes like 0,1 etc. and style them separately to somehow achive this effect? How to use flexbox to get similar effect? Should i group them into rows?
Would this be a start?
.tabs__labels {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
list-style: none;
margin: 0;
padding: 0;
}
.tabs__labels li {
flex-basis: 45%;
margin: 20px 0;
padding: 0;
}
.tabs__labels li:nth-child(odd) {
display: flex;
justify-content: flex-end;
}
.tabs__labels li:nth-child(even) {
display: flex;
}
.tabs__labels li:nth-child(3),
.tabs__labels li:nth-child(4) {
flex-basis: 35%;
}
.tabs__labels li a {
display: flex;
justify-content: center;
align-items: center;
height: 40px;
width: 40px;
border-radius: 50%;
border: 1px solid red;
text-decoration: none;
}
.tabs__labels li:nth-child(1)::before {
content: 'some text';
text-decoration: underline;
margin-right: 10px;
}
.tabs__labels li:nth-child(2)::after {
content: 'some text';
text-decoration: underline;
margin-left: 10px;
}
<div class="tabs">
<ul class="tabs__labels">
<li>
<a class="active" href="#">S
</a>
</li>
<li>
<a class="" href="#">S
</a>
</li>
<li>
<a class="" href="#">S
</a>
</li>
<li>
<a class="" href="#">S
</a>
</li>
<li>
<a class="" href="#">S
</a>
</li>
<li>
<a class="" href="#">S
</a>
</li>
</ul>
</div>

Resources