How to align a menu to center to look uniform? - html

I have got a problem with my design. I am trying to align a menu to center, but I need it to be uniform. I need it to be somehow as it is in the below picture.
I do not get why my code is aligning irregularly if I set text-align:center for .menu. And if I use align left, it send them back to the left border. The parent left-menu should align them center, and menu should align them left-center.
.left-menu {
width: 15%;
float: left;
background-color: lightgrey;
height: 100%;
text-align: center;
color: #3f3f3f;
}
.right-content {
width: 85%;
float: right;
background-color: white;
height: 100%;
}
.menu {
height: 100%;
text-align: left;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/css/bootstrap.min.css" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css" integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<div class="left-menu">
<div class="menu">
<p><i class="fa-brands fa-slack"></i><span class="ms-1 d-none d-sm-inline">Dashboard</span></p>
<p><i class="fa-brands fa-twitter"></i><span class="ms-1 d-none d-sm-inline">Twitter</span></p>
<p><i class="fa-brands fa-linkedin-in"></i><span class="ms-1 d-none d-sm-inline">LinkedIn</span></p>
<p><i class="fa-brands fa-youtube"></i><span class="ms-1 d-none d-sm-inline">YouTube</span></p>
<p><i class="fa-solid fa-gear"></i><span class="ms-1 d-none d-sm-inline">Settings</span></p>
<p><i class="fa-solid fa-right-from-bracket"></i><span class="ms-1 d-none d-sm-inline">Logout</span></p>
</div>
</div>
<div class="right-content">
</div>

You can try setting the menu items to display as inline-block and then center aligning the parent container.
Add this to your CSS code:
.menu p {
display: inline-block;
margin: 20px 0;
}
Also change the text-align property on the .left-menu class:
.left-menu {
width: 15%;
float: left;
background-color: lightgrey;
height: 100%;
text-align: center;
color: #3f3f3f;
display: flex;
align-items: center;
justify-content: center;
}
This should center align the menu items vertically and horizontally.

Here's how I might go about this.
Get rid of floats. They're not a modern layout technique.
Use flexbox with Bootstrap's classes (and a bit of custom CSS)
Get rid of your hard widths. Let the content determine that.
Use flexbox to space the menu items, too.
Don't use paragraphs for menu items. That's not their purpose.
Do use semantic elements and ARIA labels for the menu for better accessibility. See https://www.w3.org/WAI/tutorials/menus. If you follow Bootstrap's guides you'll see a lot of that kind of thing.
Also review the Bootstrap docs to avail yourself of all it offers. You're duplicating code with some of your CSS, which Bootstrap provides already.
.left-menu {
background-color: lightgrey;
text-align: center;
color: #3f3f3f;
}
.right-content {
background-color: white;
height: 100%;
}
.menu {
height: 100%;
text-align: left;
}
.menu>div {
white-space: nowrap;
justify-content: space-around;
}
.menu>div>i {
margin-right: 1rem;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/css/bootstrap.min.css" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css" integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ==" crossorigin="anonymous" referrerpolicy="no-referrer"
/>
<div class="d-flex">
<div class="left-menu">
<div class="menu d-flex flex-column px-3">
<div><i class="fa-brands fa-slack"></i><span class="ms-1 d-none d-sm-inline">Dashboard</span></div>
<div><i class="fa-brands fa-twitter"></i><span class="ms-1 d-none d-sm-inline">Twitter</span></div>
<div><i class="fa-brands fa-linkedin-in"></i><span class="ms-1 d-none d-sm-inline">LinkedIn</span></div>
<div><i class="fa-brands fa-youtube"></i><span class="ms-1 d-none d-sm-inline">YouTube</span></div>
<div><i class="fa-solid fa-gear"></i><span class="ms-1 d-none d-sm-inline">Settings</span></div>
<div><i class="fa-solid fa-right-from-bracket"></i><span class="ms-1 d-none d-sm-inline">Logout</span></div>
</div>
</div>
<div class="right-content px-3">
Right Content
</div>
</div>

Related

how to put text right and left in a footer like the one in the image

Firstly this is my second question in stackoverflow so dont be strict :( .
I am trying to create a template using html,css and sometimes bootstrap
In the footer i want to put text to the right like" terms and conditions,privacy" and in the left the social media icons.
I tried using columns but something was wrong or it does not work that way.
i am not in level 10 reputation so i hope the screenshot will help you understand...More info are that i want the whole template to be centered so i used a class with wrap.
https://i.stack.imgur.com/4fEIY.png
Basically you can just use display: flex and justify-content: space-between to achieve this.
/* Important things */
footer {
display: flex;
justify-content: space-between;
}
/* Decorative */
a {
text-decoration: none;
color: #555;
}
a + a {
margin-left: 10px;
}
footer {
background-color: #eee;
padding: 20px 40px;
}
<footer>
<section>
Terms and Conditions
Privacy
</section>
<section>
Follow
♠
♣
♥
</section>
</footer>
On Bootstrap 4, you can use float-right and float-left classes.
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/js/all.min.js"></script>
<section>
Terms and conditions
Privacy
<div class="iconHere float-right">
Follow
<i class="fab fa-facebook-f"></i>
<i class="fab fa-twitter"></i>
<i class="fab fa-instagram"></i>
</div>
</section>
You can see the full documentation here.
You did not provide code but this is how you can do it.
There're many ways you could do it, you could use flex-box, or just use positions, or floats like I did below.
.footer{
width: 100%;
padding: 15px;
box-sizing: border-box;
min-height: 15px;
border: thin solid #d3d3d3;
}
.block{
display: inline-block; /* important */
}
.shift-right{
float: right; /* important */
}
<div class="footer">
<div class="block ">Left Content</div>
<div class="block shift-right"> Right Content</div>
</div>

CSS - get 3 divs in a line with text on bottom? [duplicate]

This question already has answers here:
How do you make div elements display inline?
(20 answers)
Display Images Inline via CSS
(3 answers)
How to make the <img> tags line up horizontally in the div?
(5 answers)
How to put img inline with text
(3 answers)
Closed 5 years ago.
Im just having a frustrating time trying to emulate this - where the arrows function as buttons and text sits below the img -
For CSS, Ive tried as other questions suggest:
.ico-selector {
display: inline-block;
width: 123px;
float: left;
}
Example
.ico-selector {
display: inline-block;
width: 123px;
float: left;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="ico-selector">
<i class="fa fa-chevron-left"></i>
<img src="https://d1j8pt39hxlh3d.cloudfront.net/development/emojione/2.2/843/2270.svg" />
<p>My Icon</p>
<i class="fa fa-chevron-right"></i>
</div>
but they remain vertically stacked. How can I do this?
You can simply do this :
.ico-selector {
width: 123px;
text-align: center;
display: inline-block;
}
/*adjust these values as you need*/
.ico-selector img {
width: 65%;
margin: 0 5px;
}
.ico-selector>* {
vertical-align: middle;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<div class="ico-selector">
<i class="fa fa-chevron-left"></i>
<img src="https://d1j8pt39hxlh3d.cloudfront.net/development/emojione/2.2/843/2270.svg" />
<i class="fa fa-chevron-right"></i>
<p>My Icon</p>
</div>
I assume your ico-selector box has fixed dimensions. Why not just position the chevrons absolutely within that box?
.ico-selector {
position:relative;
display: inline-block;
width: 123px;
}
.fa-chevron-left{
position: absolute;
left:0;
top: 50%;
}
.fa-chevron-right{
position: absolute;
right:0;
top: 50%;
}
Its a rather rough example but it illustrates the idea.
You can use divs to surround each part of your icon selector like this:
.ico-selector {
width: 123px;
height: 200px;
line-height: 200px;
}
.left-arrow, .icon, .right-arrow {
display: inline-block;
vertical-align: middle;
line-height: normal;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="ico-selector">
<div class="left-arrow">
<i class="fa fa-chevron-left"></i>
</div>
<div class="icon">
<img src="https://d1j8pt39hxlh3d.cloudfront.net/development/emojione/2.2/843/2270.svg" />
<p>My Icon</p>
</div>
<div class="right-arrow">
<i class="fa fa-chevron-right"></i>
</div>
</div>

Vertically align two items by the middle of each item

Sorry if the title is confusing. Hopefully, the image speaks for itself.
How can I use css to align the middle of the plus sign with the cross section of the x?
I know I could use something like position to nudge the x up a few pixels but I'm looking for a more consistent solution that works for several different screen sizes.
Heres the HTML. pretty-link is just a class with the cursor property set to hand and pointer
<span className='pull-right' style={{verticalAlign: 'middle', margin: 'auto', display: 'inline-block'}}>
<i className='fa fa-minus pretty-link' style={{verticalAlign: 'middle'}} onClick={e => toggleSystemUnit(e, index)}></i>
<i className='fa fa-times pretty-link' style={{verticalAlign: 'middle'}}></i>
</span>
Here is an example utilizing flex, does not work
http://jsfiddle.net/f1aejwwf/1/
Here is an example utilizing vertical-align, does not work
http://jsfiddle.net/hw4au2km/
In each example the x remains slightly below the +
Setting explicit widths for a wrapping span and floating each:
http://jsfiddle.net/u99q01t2/2/
In each of these examples the x seems to land slightly below the + so maybe it's a problem with fa?
For anyone coming here from Google, I do not think the fa-times icon can easily be aligned this way. All the above solutions work great for fa-plus and fa-minus but the fa-times icon is slightly off-center. Maybe someone can find a solution to that but for now I've switched to material icons for my project.
Those two images are horizontally aligned on the baseline, that's why you need to add some margin-bottom to the right one in order to make them horizontally centered, I think 2px do the job just fine:
.pretty-link {
cursor: pointer;
/* display: inline-block; not necessary */
vertical-align: middle;
}
.containerdiv {
display: flex; /* displays children inline */
justify-content: space-between; /* children are evenly distributed, first child is on the far left, last on the far right */
align-items: center; /* vertical alignment / centering */
margin: auto;
width: 70%;
padding: 5px 20px 5px 10px;
background-color: #eee;
border-bottom: 2px solid #ddd;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class='containerdiv'>
<h4>Detail</h4>
<span class='pull-right'>
<i class='fa fa-plus pretty-link'></i>
<i class='fa fa-times pretty-link' style="margin-bottom: 2px;"></i>
</span>
</div>
I created this snippet to help you with your question. As you can see the two blocks have different heights but giving them display: inline-block; and vertical-align: middle; they are vertically centered. Hope it helps :)
.element.first {
font-size: 65px;
background: blue;
margin-right: 10px;
}
.element.second {
font-size: 35px;
background: yellow;
}
.element {
display: inline-block;
vertical-align: middle;
}
<div class="container">
<div class="element first">First Icon</div>
<div class="element second">Second Icon</div>
</div>
Give your span class a width and height, then give your first <i> class float:left; and your second <i>classfloat:right; Both <i>must have width in px;
You can try this
<!DOCTYPE html>
<html>
<head>
<style>
.textpart {
margin-left: -6px;
}
</style>
</head>
<body>
<h1 class="text">+<span class="textpart">X</span></h1>
</body>
</html>
You can use flexbox or line-height . Flexbox is the greatest way if you are using autoprefixer and a task runner.
HTML
<h3>
Normal
</h3>
<span>
<i class="fa fa-minus pretty-link"></i>
<i class="fa fa-times pretty-link"></i>
Lorem ipsum
</span>
<hr>
<h3>
Flex
</h3>
<span class="container-flex">
<i class="fa fa-minus pretty-link"></i>
<i class="fa fa-times pretty-link"></i>
Lorem ipsum
</span>
<hr>
<h3>
Line Height
</h3>
<span class="container-line-height">
<i class="fa fa-minus pretty-link"></i>
<i class="fa fa-times pretty-link"></i>
</span>
CSS
.container-flex{
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
.container-line-height .fa{
vertical-align: middle;
display: inline-block;
}

setting an image vertically aligned with text

EDIT: Please disregard the phone/email row.
I would like to reach this kind of result:
Since I need the side texts to be as the same height of the icon, I am having some issues with the relative and absolute div wrappers and how to set them right.
HTML
<div class="row topWrapper">
<div class="iconWrapper">
<i class="fa fa-user-circle-o fa-2x"></i>
</div>
<div class="captionWrapper">
<h5><strong>Liat </strong></h5>
<h5>Your recruitment counsel</h5>
</div>
</div>
SCSS
.topWrapper {
background-color: #d9534f;
height: 150px;
.iconWrapper {
background-color: #f7ecb5;
display: inline-block;
position: relative;
width:16.67%;
i{
position: absolute;
top: 50%;
#include translate(0, -50%);
}
}
.captionWrapper{
background-color: #245580;
display: inline-block;
}
}
You don't need to use absolute position to get what you want, just a few things and you are good to go.
See code snippet:
Note: i didn't use SCSS for demonstration purpose
.topWrapper {
background-color: #d9534f;
height: 150px;
padding: 5px;
}
.iconWrapper {
display: inline-block;
font-size: 17px;
}
.captionWrapper {
display: inline-block;
}
.captionWrapper h5 {
margin: 2px;
/*reduce the margin to make the two texts aligned with the icon*/
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<div class="row topWrapper">
<div class="iconWrapper">
<i class="fa fa-user-circle-o fa-2x"></i>
</div>
<div class="captionWrapper">
<h5><strong>Liat </strong></h5>
<h5>Your recruitment counsel</h5>
</div>
</div>

Positioning Font Awesome icon and a paragraph

I wanna position the icon to be on top of the sentence and both centered within bootstrap column. I tried changing the position and display in css for both the paragraph and icon but it doesnt work.
Right now it looks like this
I want it to be like this
Here's the code
#home-info {
width: 500px;
height: 200px;
background-color: rgba(0,0,0,0.7);
top: 550px;
z-index: 1;
position: absolute;
}
.col-md-3 {
height: 100px;
background-color: #1e2c38;
text-align: center;
color: white;
border-bottom: 1px solid white;
border-top: 1px solid white;
}
.col-md-4 {
height: 300px;
text-align: center;
background-color: #1b2328;
}
.col-md-3 p {
position: relative;
width: 300px;
text-align: center;
}
<div class="container-fluid"> <!-- HOME INFO -->
<div class="row">
<div class="col-md-3" id="navy2">
<div class="content-container">
<i class="fa fa-newspaper-o fa-3x" aria-hidden="true"></i>
<p>Learn more about our recent events and news!</p>
</div>
</div>
<div class="col-md-3" id="navy3">
<div class="content-container">
<i class="fa fa-calendar fa-3x" aria-hidden="true"></i>
<p>Stay up to date! Get the school's calendar here!</p>
</div>
</div>
<div class="col-md-3" id="navy2">
<div class="content-container">
<i class="fa fa-facebook-square fa-3x" aria-hidden="true"></i>
<p>Like and connect with us via Facebook!</p>
</div>
</div>
<div class="col-md-3" id="navy3">
<div class="content-container">
<i class="fa fa-youtube fa-3x" aria-hidden="true"></i>
<p>Learn more about us through our videos!</p>
</div>
</div>
</div> <!-- ROW -->
Thanks!
You can center it by making the inner p a display:block element and use margin: 0 auto to center it...
.col-md-3 p {
position: relative;
width: 300px;
display: block;
margin: 0 auto;
}
http://www.codeply.com/go/kFJwok7k0T
However, because you have the 300px set on the .col-md-3 p, the text will get cut-off at smaller widths. It would be better to not set any specific width on the .col-md-3 p so that it's responsive.
You may use <br> tag to separate the icon and text. And since you are using font-awesome icons, you use text-align: center to center both the icon and the text.