How would I separate an item from a UL that is centered? - html

I am trying to achieve the following:
But what I am getting is this:
Here is my HTML (react JSX but is the same thing):
<div className="snavbarcontainer">
<div className="toplefticon">
<a class="test" href="#"><img src={topleft} alt="Testing Logo" /></a>
</div>
<div className="mainIcons">
<ul className="icons_ul">
<li><img src={ILookupPupils} alt="Pupil Lookup" /></li>
<li><img src={IMUsers} alt="Manage Users" /></li>
<li><img src={IHand} alt="Coming Soon" /></li>
<li><img src={IMAdmins} alt="Manage Admins" /></li>
<li><img src={IDash} alt="Dashboard" /></li>
<li><img src={IDB} alt="Dashboard" /></li>
</ul>
</div>
</div>
And my (S)CSS:
body {
//! background-color: red; - DEBUGGING ONLY!
margin: 0
}
.snavbarcontainer {
background-color: black;
width: 3.5em;
height: 100vh;
position: fixed;
display: flex;
flex-direction: column;
align-items: center;
}
.icons_ul {
text-decoration: none;
list-style-type: none;
padding: 0;
li /* Adds property to EACH LI, not the UL itself. */{
margin: 1em 0;
}
}
.icons_ul {
justify-content: center;
}
.toplefticon {
justify-content: flex-start;
}
I cannot find out for the life of me how to do this, whether with flexbox or something else!
Thanks for your answers,
Henry

.snavbarcontainer {
background-color: black;
width: 3.5em;
height: 100vh;
position: fixed;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.icons_ul {
text-decoration: none;
list-style-type: none;
padding: 0;
}
.icons_ul li{
margin: 1em 0;
}
.icons_ul {
justify-content: center;
}
.toplefticon {
position: absolute;
top: 0;
left: 5px;
transform: translateX(-50%);
margin-top: 25%;
}
<div class="snavbarcontainer">
<div class="toplefticon">
<a class="test" href="#"><img src={topleft} alt="Testing Logo" /></a>
</div>
<div class="mainIcons">
<ul class="icons_ul">
<li><img src={ILookupPupils} alt="Pupil Lookup" /></li>
<li><img src={IMUsers} alt="Manage Users" /></li>
<li><img src={IHand} alt="Coming Soon" /></li>
<li><img src={IMAdmins} alt="Manage Admins" /></li>
<li><img src={IDash} alt="Dashboard" /></li>
<li><img src={IDB} alt="Dashboard" /></li>
</ul>
</div>
</div>

Try this:
//JSX
<div className="snavbarcontainer">
<div className="toplefticon">
<a class="test" href="#"><img src={topleft} alt="Testing Logo" /</a>
</div>
<div className="mainIcons">
<ul className="icons_ul">
<li><img src={ILookupPupils} alt="Pupil Lookup" /></li>
<li><img src={IMUsers} alt="Manage Users" /></li>
<li><img src={IHand} alt="Coming Soon" /></li>
<li><img src={IMAdmins} alt="Manage Admins" /></li>
<li><img src={IDash} alt="Dashboard" /></li>
<li><img src={IDB} alt="Dashboard" /></li>
</ul>
</div>
//added this
<div className="bottomlefticon">
<a class="test" href="#"><img src={bottomLeftIcon} alt="Testing Logo" /</a>
</div>
</div>
//CSS
body {
//! background-color: red; - DEBUGGING ONLY!
margin: 0
}
.snavbarcontainer {
background-color: black;
width: 3.5em;
height: 100vh;
position: fixed;
display: flex;
flex-direction: column;
//added this
justify-content: space-between;
}
.icons_ul {
text-decoration: none;
list-style-type: none;
padding: 0;
li /* Adds property to EACH LI, not the UL itself. */{
margin: 1em 0;
}
}
I added the bottom left icon at the bottom of the code so there can be proper space between them.

Related

Positions set using the justify-position attribute don't take effect at all

HTML Code (it is JSX which is the same as HTML, but class is replaced with ClassName):
<div className="snavbarcontainer">
<div className="toplefticon">
<a class="test" href="#"><img src={topleft} alt="Testing Logo" /></a>
</div>
<div className="mainIcons">
<ul className="icons_ul">
<li><img src={ILookupPupils} alt="Pupil Lookup" /></li>
<li><img src={IMUsers} alt="Manage Users" /></li>
<li><img src={IHand} alt="Coming Soon" /></li>
<li><img src={IMAdmins} alt="Manage Admins" /></li>
<li><img src={IDash} alt="Dashboard" /></li>
<li><img src={IDB} alt="Dashboard" /></li>
</ul>
</div>
</div>
My (S)CSS:
body {
//! background-color: red; - DEBUGGING ONLY!
margin: 0
}
.snavbarcontainer {
background-color: black;
width: 3.5em;
height: 100vh;
position: fixed;
display: flex;
flex-direction: column;
align-items: center;
}
.icons_ul {
text-decoration: none;
list-style-type: none;
padding: 0;
li /* Adds property to EACH LI, not the UL itself. */{
margin: 1em 0;
}
}
.icons_ul {
justify-content: center;
}
.toplefticon {
justify-content: flex-start;
}
Basically, I want the image with the class "test" at the top of the vertical sidebar - and the icons in the center. However what I have done isn't currently working.
Thanks for your responses.
Where is display: flex; on icons_ul and toplefticon?
flex, isn't inherited beyond the first child.
body {
//! background-color: red; - DEBUGGING ONLY!
margin: 0
}
.snavbarcontainer {
background-color: black;
width: 3.5em;
height: 100vh;
position: fixed;
display: flex;
flex-direction: column;
align-items: center;
}
.icons_ul {
text-decoration: none;
list-style-type: none;
padding: 0;
li /* Adds property to EACH LI, not the UL itself. */{
margin: 1em 0;
}
}
.icons_ul {
display: flex;
justify-content: center;
}
<div className="snavbarcontainer">
<div className="toplefticon">
<a class="test" href="#"><img src={topleft} alt="Testing Logo" /></a>
</div>
<div className="mainIcons">
<ul class="icons_ul">
<li><img src={ILookupPupils} alt="Pupil Lookup" /></li>
<li><img src={IMUsers} alt="Manage Users" /></li>
<li><img src={IHand} alt="Coming Soon" /></li>
<li><img src={IMAdmins} alt="Manage Admins" /></li>
<li><img src={IDash} alt="Dashboard" /></li>
<li><img src={IDB} alt="Dashboard" /></li>
</ul>
</div>
</div>
And for the toplefticon, it will be top left by default if your document is made for the English language, because that's the default flow for English documents. So no need for that class.
Remember to rename class to className before using this code in react. Hope this helps.

How to bring two outer columns close to the middle column

I want the first and last column to be closer to the middle column. This is what i have so far.
* {
box-sizing: border-box;
}
ul {
list-style: none;
font-size: 15px;
margin: 0;
padding: 0;
text-align: center;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-gap: 10px;
grid-column-gap: 10px;
}
.images {
position: relative;
top: 200px;
}
.fault {
position: relative;
left: 100px;
}
<body>
<div class="images">
<ul>
<li><img src="https://homepages.cae.wisc.edu/~ece533/images/cat.png" /></li>
<li><img src="https://homepages.cae.wisc.edu/~ece533/images/cat.png" /></li>
<li><img src="https://homepages.cae.wisc.edu/~ece533/images/cat.png" /></li>
<li><img src="https://homepages.cae.wisc.edu/~ece533/images/cat.png" /></li>
<li><img src="https://homepages.cae.wisc.edu/~ece533/images/cat.png" /></li>
<li><img src="https://homepages.cae.wisc.edu/~ece533/images/cat.png" /></li>
</ul>
</div>
If anybody could help me out it would be great. I have this code so far and it kind of works but not 100%. the outer two are too far from the middle one.
Just change the value of grid-column-gap property of ul css styles.
grid-column-gap: 2px;
Just align the images in the li based on their number in the grid row
* {
box-sizing: border-box;
}
ul {
list-style: none;
font-size: 15px;
margin: 1em;
padding: 0;
text-align: center;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-gap: 10px;
grid-column-gap: 10px;
}
li {
border: 1px solid red;
}
li:nth-child(3n+ 1) {
text-align: right;
}
li:nth-child(3n + 2) {
text-align: center;
}
li:nth-child(3n + 3) {
text-align-last: left;
}
<body>
<div class="images">
<ul>
<li><img src="http://www.fillmurray.com/g/140/100" /></li>
<li><img src="http://www.fillmurray.com/g/140/100" /></li>
<li><img src="http://www.fillmurray.com/g/140/100" /></li>
<li><img src="http://www.fillmurray.com/g/140/100" /></li>
<li><img src="http://www.fillmurray.com/g/140/100" /></li>
<li><img src="http://www.fillmurray.com/g/140/100" /></li>
</ul>
</div>

3 images on first line and 3 images on second line in centre of page

I would like 3 images on the first line and 3 images on the second line and want them in the middle of the page
* { box-sizing: border-box; }
ul {
list-style: none;
font-size: 0;
margin: 0;
padding: 0;
text-align: center; }
li { display: inline-block; padding: 10px;}
li:nth-child(1), li:nth-child(4) {
width: 50%;
}
li:nth-child(4) { text-align: right; }
li:nth-child(2) { text-align: left; }
<ul>
<li><img src="http://lorempixel.com/400/200" /></li>
<li><img src="http://lorempixel.com/400/200" /></li>
<li><img src="http://lorempixel.com/400/200" /></li>
<li><img src="http://lorempixel.com/400/200" /></li>
<li><img src="http://lorempixel.com/400/200" /></li>
</ul>
there are many ways to do it, for example:
ul {
list-style: none;
font-size: 0;
margin: 0;
padding: 0;
text-align: center;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-gap: 10px;
}
https://jsfiddle.net/d6wn79pv/4/
or
ul {
list-style: none;
font-size: 0;
margin: 0;
padding: 0;
display: flex;
flex-wrap: wrap;
text-align: center;
}
ul li {
flex-grow: 1;
width: 33%;
}
https://jsfiddle.net/d6wn79pv/9/
with use of flexbox:
* {
box-sizing: border-box;
}
ul {
list-style: none;
padding: 0;
display: flex;
justify-content:center;
flex-wrap: wrap;
}
li{
width:30%;
margin:3px auto;
}
<ul>
<li><img src="https://via.placeholder.com/150" /></li>
<li><img src="https://via.placeholder.com/150" /></li>
<li><img src="https://via.placeholder.com/150" /></li>
<li><img src="https://via.placeholder.com/150" /></li>
<li><img src="https://via.placeholder.com/150" /></li>
<li><img src="https://via.placeholder.com/150" /></li>
</ul>
check this out.
<!DOCTYPE html>
<html>
<style>
* { box-sizing: border-box; }
ul {
list-style: none;
font-size: 0;
margin: 0;
padding: 0;
text-align: center; }
li {
width: 31%;
display:block;
float:left;
margin:3px;
}
</style>
<body>
<ul>
<li><img src="http://lorempixel.com/100/100/cats/" /></li>
<li><img src="http://lorempixel.com/100/100/cats/" /></li>
<li><img src="http://lorempixel.com/100/100/cats/" /></li>
<li><img src="http://lorempixel.com/100/100/cats/" /></li>
<li><img src="http://lorempixel.com/100/100/cats/" /></li>
<li><img src="http://lorempixel.com/100/100/cats/" /></li>
</ul>
</body>
</html>
You can do it simply by using flex
<ul class="here">
<li><img src="http://lorempixel.com/400/200" /></li>
<li><img src="http://lorempixel.com/400/200" /></li>
<li><img src="http://lorempixel.com/400/200" /></li>
<li><img src="http://lorempixel.com/400/200" /></li>
<li><img src="http://lorempixel.com/400/200" /></li>
</ul>
.here{
list-style: none;
display: flex;
justify-content: space-around;
align-items: center;
flex-wrap: wrap;
width: 100%;
}
.here li {
width: 32%;
}
.here li img{
width: 100%;
}
Change the .here width to auto resize the content

3 images on first line then 2 images on the second line underneath

I want to have 3 images on the first line and 2 on the second. I have this code but it has 2 on top and 3 on the bottom.
<ul>
<li><img src="./icons/User_Management.png" /></li>
<li><img src="./icons/User_Management.png" /></li>
<li><img src="./icons/User_Management.png" /></li>
<li><img src="./icons/User_Management.png" /></li>
<li><img src="./icons/User_Management.png" /></li>
</ul>
* { box-sizing: border-box; }
ul {
list-style: none;
font-size: 0;
margin: 0;
padding: 0;
text-align: center; }
li { display: inline-block; padding: 10px;}
li:nth-child(1), li:nth-child(4) {
width: 50%;
}
li:nth-child(4) { text-align: right; }
li:nth-child(2) { text-align: left; }
I want the two bottom images to be centred with the three images at the top.
Expected Result - 3 Images on first row and 2 on second row
Actual Result - 2 Images on first row and 3 on second row
Use Flex:
#container{
width: 550px;
display: flex;
justify-content: center;
flex-wrap: wrap;
}
#container > img{
margin: 10px;
}
<div id="container">
<img src="https://via.placeholder.com/150">
<img src="https://via.placeholder.com/150">
<img src="https://via.placeholder.com/150">
<img src="https://via.placeholder.com/150">
<img src="https://via.placeholder.com/150">
</div>
You could also do something like this which is an amazing CSS tool. Use CSS grid.
//HTML
<ul class="grid">
<li><img src="./icons/User_Management.png" /></li>
<li><img src="./icons/User_Management.png" /></li>
<li><img src="./icons/User_Management.png" /></li>
<li><img src="./icons/User_Management.png" /></li>
<li><img src="./icons/User_Management.png" /></li>
</ul>
//CSS
.grid {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
Like this:
Just adjust the widths and use the appropriate nth-child
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
::before,
::after {
box-sizing: inherit;
}
ul {
list-style: none;
font-size: 0;
margin: 0;
padding: 0;
text-align: center;
}
li {
display: inline-block;
text-align: center;
width: 33.3%;
border: 1px solid red;
}
li:nth-child(4),
li:nth-child(5) {
width: 50%;
}
<ul>
<li><img src="http://www.fillmurray.com/140/100" /></li>
<li><img src="http://www.fillmurray.com/140/100" /></li>
<li><img src="http://www.fillmurray.com/140/100" /></li>
<li><img src="http://www.fillmurray.com/140/100" /></li>
<li><img src="http://www.fillmurray.com/140/100" /></li>
</ul>

My text won't flow beside my images?

How do I put the text beside these images? I've tried everything but I can't seem to figure out how? I'd like it to appear BESIDE the image.
jsFiddle using random image: https://jsfiddle.net/0z1pfbs7/
HTML
<section class="pdc">
<div class="moreproduct">
<div class="bigimg">
<img src="http://i.imgur.com/Xt6vUQD.jpg" alt="" />
</div>
<ul>
<li><img src="http://i.imgur.com/Xt6vUQD.jpg" alt="" /></li>
<li><img src="http://i.imgur.com/Xt6vUQD.jpg" alt="" /></li>
<li><img src="http://i.imgur.com/Xt6vUQD.jpg" alt="" /></li>
<li><img src="http://i.imgur.com/Xt6vUQD.jpg" alt="" /></li>
<li><img src="http://i.imgur.com/Xt6vUQD.jpg" alt="" /></li>
</ul>
<div class="producttext">
<h3>New Balance</h3>
<h1>Men's MX608v4</h1>
<p>SGF</p>
</div>
</div>
</section>
CSS
.pdc{
display: inline;
}
.moreproduct img {
position: relative;
border: 1px solid #93a2ad;
margin-top: 4px;
}
.moreproduct ul{
list-style: none;
}
.moreproduct ul li img{
width: 100px;
height: 100px;
margin-left: 80px;
}
.bigimg{
margin-top: 2em;
position: absolute;
width: 450px;
height: 450px;
margin-left: 240px;
}
.producttext{
position: absolute;
overflow: hidden;
}
Here's the code, you don't need to use position absolute to do this see the code.
.pdc{
display: inline;
}
.moreproduct img {
position: relative;
border: 1px solid #93a2ad;
margin-top: 4px;
}
.moreproduct ul{
list-style: none;
float:left;
}
.moreproduct ul li img{
width: 100px;
height: 100px;
}
.bigimg{
margin-top: 2em;
float:left;
width: 400px;
height: 450px;
margin-left: 20px;
}
.producttext{
float: left;
overflow: hidden;
margin-top: 20px;
}
.clear{
clear:both;
}
<section class="pdc">
<div class="moreproduct">
<ul>
<li><img src="http://i.imgur.com/Xt6vUQD.jpg" alt="" /></li>
<li><img src="http://i.imgur.com/Xt6vUQD.jpg" alt="" /></li>
<li><img src="http://i.imgur.com/Xt6vUQD.jpg" alt="" /></li>
<li><img src="http://i.imgur.com/Xt6vUQD.jpg" alt="" /></li>
<li><img src="http://i.imgur.com/Xt6vUQD.jpg" alt="" /></li>
</ul>
<div class="bigimg">
<img src="http://i.imgur.com/Xt6vUQD.jpg" alt="" />
</div>
<div class="producttext">
<h3>New Balance</h3>
<h1>Men's MX608v4</h1>
<p>SGF</p>
</div>
<div class="clear"></div>
</div>
</section>
As others already mentioned: Don't use absolute positioning to layout your page.
Note: You need to view the example in full-screen to see that everything is aligned "in one line".
Do you mean something like this:
.pdc{
display: inline;
}
.moreproduct img {
position: relative;
border: 1px solid #93a2ad;
margin-top: 4px;
}
.moreproduct ul{
list-style: none;
display: inline-block;
}
.moreproduct ul li img{
width: 100px;
height: 100px;
}
.bigimg{
margin-top: 2em;
display: inline-block;
height: 300px;
}
.producttext{
display: inline-block;
overflow: hidden;
height: 450px;
}
<section class="pdc">
<div class="moreproduct">
<ul>
<li><img src="http://i.imgur.com/Xt6vUQD.jpg" alt="" /></li>
<li><img src="http://i.imgur.com/Xt6vUQD.jpg" alt="" /></li>
<li><img src="http://i.imgur.com/Xt6vUQD.jpg" alt="" /></li>
<li><img src="http://i.imgur.com/Xt6vUQD.jpg" alt="" /></li>
<li><img src="http://i.imgur.com/Xt6vUQD.jpg" alt="" /></li>
</ul>
<div class="bigimg">
<img src="http://i.imgur.com/Xt6vUQD.jpg" alt="" />
</div>
<div class="producttext">
<h3>New Balance</h3>
<h1>Men's MX608v4</h1>
<p>SGF</p>
</div>
</div>
</section>
<style>
.pdc{
display: inline;
}
.moreproduct img {
position: relative;
border: 1px solid #93a2ad;
margin-top: 4px;
}
.moreproduct ul{
list-style: none;
}
.moreproduct ul li img{
width: 100px;
height: 100px;
margin-left: 80px;
}
.bigimg{
margin-top: 2em;
position: absolute;
width: 636px;
height: 450px;
margin-left: 240px;
left: 11px;
}
.producttext{
overflow: hidden;
float:right;
padding-top:25%;
}
</style>
<section class="pdc">
<div class="moreproduct">
<div class="bigimg">
<img src="http://i.imgur.com/Xt6vUQD.jpg" alt="" />
<div class="producttext">
<h3>New Balance</h3>
<h1>Men's MX608v4</h1>
<p>SGF</p>
</div>
</div>
<ul>
<li><img src="http://i.imgur.com/Xt6vUQD.jpg" alt="" /></li>
<li><img src="http://i.imgur.com/Xt6vUQD.jpg" alt="" /></li>
<li><img src="http://i.imgur.com/Xt6vUQD.jpg" alt="" /></li>
<li><img src="http://i.imgur.com/Xt6vUQD.jpg" alt="" /></li>
<li><img src="http://i.imgur.com/Xt6vUQD.jpg" alt="" /></li>
</ul>
</div>
</section>