I am using bootstrap to create a layout however, I can't seem to understand why display:inline-block with vertical-align: middle isn't working.
I would prefer not to use position absolute.
JSFiddle: https://jsfiddle.net/yheep9hh/
Any help would be appreciated
HTML:
Currently using bootstrap to create the layout (navbar, etc)
<header>
<nav class="navbar navbar-transparent">
<div class="container">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#myNavbar"><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button><a class="navbar-brand" href="#">hello</a></div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right">
<li><a class="active" href="/Home">Home</a></li>
<li>Website Design</li>
<li>Tech Support</li>
<li>Data Security</li>
<li>Networking</li>
</ul>
</div>
</div>
</nav>
</header>
<div class="container-fluid wrapper bgImage">
<div class="indexWelcome">
<div class="row">
<div class="col-md-12">
<h1 class="text-center">Welcome To Amparo Tech</h1>
<h3 class="text-center">How Can We Help You?</h3></div>
</div>
<div class="row input-fixedWidth">
<div class="col-md-12">
<form class="homeForm" method="POST">
<div class="row">
<div class="col-sm-8 col-sm-push-2 col-md-8">
<input class="homeFormEmail" type="text" name="email" placeholder="Email">
</div>
</div>
<div class="row">
<div class="col-sm-8 col-sm-push-2 col-md-8">
<input class="homeFormPostcode" type="text" name="postcode" placeholder="Postcode">
</div>
</div>
<div class="row">
<div class="col-sm-8 col-sm-push-2 col-md-8">
<textarea class="homeFormMessage" name="message" placeholder="Your Message or Tech Issue"></textarea>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="push"></div>
</div>
<footer class="footer">
<div class="container">
<div class="row clearfix">
<div class="col-md-4 text-left pull-left">
<p>name</p>
</div>
<div class="col-md-4 text-right pull-right">
<p>number</p>
</div>
<div class="col-md-4 text-center">
<p>address</p>
</div>
</div>
</div>
</footer>
CSS:
Custom CSS
* {
box-sizing: border-box;
}
html,
body {
height:100%;
}
h1,
h2,
h3,
h4,
h5,
h6 {
margin:0 auto;
margin-bottom: 10px;
}
.wrapper {
min-height:calc(100% - 82px);
margin: 0 auto -10px;
}
.footer, .push {
height: 10px;
}
.navbar {
margin:0;
height:52px;
}
input, textarea {
width: 100%;
margin:0 auto;
}
.input-fixedWidth {
max-width:750px;
margin: 0 auto;
}
.formWrapper {
position:relative;
}
.indexWelcome {
display:inline-block;
vertical-align:middle;
width: 100%;
text-align:center;
}
.navbar-transparent {
background-color: transparent;
}
.homeFormEmail {
margin-top: 20px;
}
.homeFormEmail,
.homeFormPostcode,
.homeFormMessage {
text-indent: 10px;
margin-bottom: 15px;
font-size:14px;
}
.homeFormEmail,
.homeFormPostcode {
height:40px;
}
.homeFormMessage {
height: 80px;
padding-top:10px;
resize: vertical;
}
Vertical-align:middle; works well with display:table-cell; that is if the parent div is display:table;
To display a <div> block vertically aligned in the middle, you need to use display table and table-cell to the parent and child respectively.
Have a look at the updated Fiddle (jsFiddle)
Just like:
/* Parent */
.wrapper {
display: table;
}
/* Child */
.indexWelcome {
display: table-cell;
}
Hope this helps!
since css flexbox is supported almost everywhere these days i would use it, since it makes vertical alignment very easy:
.wrapper {
display:flex;
align-items:center;
justify-content:center;
}
demo: https://jsfiddle.net/7totjt2p/2/
Related
I'm trying to get my logo stick to the top of the page but I can't manage to do that.
I've tried with:
#logo {
position: sticky;
top:0
}
I also check if there's an overflow property but I've found nothing, I'm also using bootstrap framework version 5.
This is the part where I've put logo:
<div class="container" id="header">
<div class="row">
<div class="col-4 col-md-3 align-items-start d-flex">
<img src="../media/logos/mb-logo.png" id="logo" class="img-fluid" alt="logo">
</div>
<div class="col-7 col-md-8 align-items-end justify-content-end d-flex" id="menu_mobile">
<div class="row">
<div class="col-12 justify-content-end d-flex">
<span class="menu_item">about me</span>
</div>
<div class="col-12 justify-content-end d-flex">
<span class="menu_item">competencies</span>
</div>
<div class="col-12 justify-content-end d-flex">
<span class="menu_item">portfolio</span>
</div>
<div class="col-12 justify-content-end d-flex">
<span class="menu_item">contact</span>
</div>
</div>
</div>
<div class="col justify-content-end align-items-center d-flex" id="menu_desk">
<span class="menu_item_desk">about me</span>
<span class="menu_item_desk">competencies</span>
<span class="menu_item_desk">portfolio</span>
<span class="menu_item_desk">contact</span>
</div>
</div>
</div>
Can someone help me?
edit: after trying the solution posted by #Fork:
<div class="container" id="header">
<div class="row">
<div class="col-4 col-md-3 align-items-start d-flex " >
<img src="../media/logos/mb-logo.png" id="logo" class="img-fluid position-fixed top-0" alt="logo">
</div>
The logo stay in position while I scroll down but other element changed of disposition. I managed to fix them adding some paddings and margin
edit 2: Here's the snippet and thanks to Fork now it works fine, another thing I would like to accomplish is that when the page is scrolled, the image goes up above the page for a tiny bit. I found this fiddle but is not exactly what i mean https://jsfiddle.net/z2r40y8c/. The image needs to go up and block at a specified amount of pixels.
html {
scroll-behavior: smooth;
}
body {
width: 100%;
height: 2000px
}
a{
text-decoration: none;
}
.container {
max-width: 100%;
padding: 0%;
margin: 0%;
}
body{
background-color: #161616;
}
#logo {
margin-left: 25px !important;
position: fixed;
top:0
}
.menu_mobile{
padding-top: 5%;
}
.menu_item {
font-family: 'sublimaextrabold';
font-size: 18px;
color: rgba(112,112,112,1);
padding-bottom: 5%;
cursor: pointer;
}
#media only screen and (min-width: 810px) {
#menu_mobile {
display: none !important;
}
}
#media only screen and (max-width: 810px) {
#menu_desk {
display: none !important;
}
}
.menu_item_desk {
font-family: 'sublimaextrabold';
color: rgba(112,112,112,1);
padding-left: 5%;
font-size: 30px;
cursor: pointer;
padding-top: 5%;
}
#media only screen and (max-width: 1197px) {
.menu_item_desk {
font-size: 24px;
}
}
#media only screen and (max-width: 993px) {
.menu_item_desk {
font-size: 20px;
}
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>MB</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
<link rel="stylesheet" href="../html/style.css">
</head>
<body ondragstart="return false;" ondrop="return false;">
<div class="container" id="header">
<div class="row">
<div class="col-sm-12">
<div class="container">
<div class="col-sm-3 align-items-start d-flex">
<img src="https://www.startpage.com/av/proxy-image?piurl=https%3A%2F%2Fdictionary.cambridge.org%2Ffr%2Fimages%2Fthumb%2Foblong_noun_002_25303.jpg%3Fversion%3D5.0.245&sp=1657096049T030f5c6f84a41f399845576d2d63d9849144e614f9e0077172506ae40946828e" id="logo" class="img-fluid position-fixed top-0" alt="logo">
</div>
<div class="col-sm-11 d-flex justify-content-end align-items-center " id="menu_desk">
<span class="menu_item_desk">section 1</span>
<span class="menu_item_desk">section 2</span>
<span class="menu_item_desk">section 3</span>
<span class="menu_item_desk">section 4</span>
</div>
<div class="col-11 align-items-end pt-3 justify-content-end d-flex" id="menu_mobile">
<div class="row">
<div class="col-12 justify-content-end d-flex">
<span class="menu_item">section 1</span>
</div>
<div class="col-12 justify-content-end d-flex">
<span class="menu_item">section 2</span>
</div>
<div class="col-12 justify-content-end d-flex">
<span class="menu_item">section 3</span>
</div>
<div class="col-12 justify-content-end d-flex">
<span class="menu_item">section 4</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Not sure why you just want the position: sticky; just on the logo rather than the whole navigation bar, but if you want to go that route, I would suggest using position: fixed; instead. Additionally, apply it to the div that's surrounding your image. Like so:
<div class="col-4 col-md-3 align-items-start d-flex position-fixed top-0">
<img src="../media/logos/mb-logo.png" id="logo" class="img-fluid" alt="logo">
</div>
Hope this helps :)
As far as I know the problem is, that for some constructions, like a bootstrap carousel, if you want to display it on a fullscreen, bootstrap requires the height of html to be set to 100%.
For position: sticky it is required to have no height set.
You could try making the nav sticky with JS:
const nav = document.querySelector('#nav');
let navTop = nav.offsetTop;
function fixedNav() {
if (window.scrollY >= navTop) {
nav.classList.add('fixed');
} else {
nav.classList.remove('fixed');
}
}
window.addEventListener('scroll', fixedNav);
and the CSS for the activated navbar:
#nav.fixed {
position: fixed;
box-shadow: 5px 5px 19px 0px rgba(0, 0, 0, 0.5);
}
#nav.fixed ul li img {
height: 36px;
}
#nav.fixed ul li a {
font-size: 14px;
}
Look at my screenshot, How can I move these two elements in the center.
The elements are .
I did almost anything but not working.
Anybody could help? Text-align: center not working either
.setup-box {
margin-left: 1em;
}
.treeview-box-title {
padding-top: .5em;
margin-top: 1.5em;
}
.treeview-container {
display: flex;
justify-content: space-between;
}
.treeview-ul {
margin: 0 1em 0 1.5em;
text-align: left;
}
<div class="row">
<div class="col-xs-12 col-sm-4 col-md-4">
<div class="setup-box">
<h4 class="treeview-box-title">Windows</h4>
<div class="treeview-container">
<ul class="treeview-ul">
<li>
Download Application
</li>
</ul>
</div>
</div>
</div>
<div class="col-xs-12 col-sm-4 col-md-4">
<div class="setup-box">
<h4 class="treeview-box-title">Android</h4>
<div class="treeview-container">
<ul class="treeview-ul">
<li>Google PlayStore</li>
</ul>
</div>
</div>
</div>
</div>
add to your div.row d-flex and justify content:
<div class="row mx-auto d-flex justify-content-center">
.setup-box {
margin-left: 1em;
border:1px solid blue;
border-radius:0.5em;
}
.m-g-b{
margin-bottom:20px;
}
.windows-header{
border-bottom:1px solid blue;
}
.android-header{
border-bottom:1px solid blue;
}
.treeview-box-title {
text-align:center;
}
.treeview-container {
display: flex;
padding:0.1em;
}
.treeview-ul {
text-align: left;
}
<div class="row m-g-b">
<div class="col-xs-12 col-sm-4 col-md-4">
<div class="setup-box">
<div class="windows-header">
<h4 class="treeview-box-title">Windows</h4>
</div>
<div class="treeview-container">
<ul class="treeview-ul">
<li>
Download Application
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-4 col-md-4">
<div class="setup-box">
<div class="android-header">
<h4 class="treeview-box-title">Android</h4>
</div>
<div class="treeview-container">
<ul class="treeview-ul">
<li>Google PlayStore</li>
</ul>
</div>
</div>
</div>
</div>
I'm working on a site which needs an image centered in the div on the left side, centered off the right div with a background.
I tried to a common solution, but for some reason, it won't work. It must be responsive as well, so I'm a bit in the dark over here. See my fiddle for the example.
<div class="container-fluid">
<div class="row">
<div class="col-12 col-sm-6">
<div class="leftSide">
<img src="https://images.pexels.com/photos/3755760/pexels-photo-3755760.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260" class="img-fluid imgLeft">
</div>
</div>
<div class="col-12 col-sm-6">
<div class="rightSide">
<h3>
Some text
</h3>
<p>
Some more text
</p>
<button type="button" class="btn btn-primary">Some text</button>
</div>
</div>
https://jsfiddle.net/Onno0297/grvwxby2/1/
If I understand your question correctly then below code will work.
Visit https://jsfiddle.net/alishapatel/n3ap1vjo/4/!
.leftSide {
height: 100%;
display: flex;
align-items: center;
}
.rightSide {
background: #313131;
height: 546px;
color: #fff;
}
.rightSide h3 {
text-align: center;
padding-top: 200px;
}
.rightSide p {
text-align: center;
}
.btn.btn-primary {
margin: 0 auto;
display: block;
}
.imgLeft {
max-height: 400px;
max-width: 300px;
margin: 0 auto;
width: 100%;
}
<div class="container-fluid">
<div class="row">
<div class="col-12 col-sm-6">
<div class="leftSide">
<img src="https://images.pexels.com/photos/3755760/pexels-photo-3755760.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260" class="img-fluid imgLeft">
</div>
</div>
<div class="col-12 col-sm-6">
<div class="rightSide">
<h3>
Some text
</h3>
<p>
Some more text
</p>
<button type="button" class="btn btn-primary">Some text</button>
</div>
</div>
</div>
</div>
Here I am trying to draw a horizontal line between the buttons. I have tried in many ways but I can't get it. I think I need to do some magics in CSS but I am new to HTML and CSS That's why I can't find the way to make it work.
I want:
I got this:
.divided {
display: flex;
align-items: center;
}
.divider {
flex-grow: 1;
border-bottom: 1px solid black;
margin: 5px
}
<div class="col-sm-9" style="padding-left:0px;padding-right:0px">
<div class="col-sm-12 row">
<div class="container" style="padding-left:0px;padding-right:0px">
<div class="row divided">
<div class="col-sm-3">
<button mat-mini-fab>1</button>
<span style="padding-left:15px">Login</span>
</div>
<span class="divider"></span>
<div class="col-sm-3">
<button mat-mini-fab>2</button>
<span style="padding-left:15px">Address</span>
</div>
<span class="divider"></span>
<div class="col-sm-3">
<button mat-mini-fab>3</button>
<span style="padding-left:15px">Mycart</span>
</div>
<span class="divider"></span>
<div class="col-sm-3">
<button mat-mini-fab>4</button>
<span style="padding-left:15px">Payment</span>
</div>
</div>
</div>
</div>
</div>
Can anyone help me to solve this ?
Update:
Use pseudo :after to <div class="col-sm-3 divder">
Instead using <span class="divider"></span> (-- remove it)
.divder:after{
content: '';
width: 71px;
height: 2px;
top: 15px;
background: black;
position: absolute;
right: -12px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-sm-9" style="padding-left:0px;padding-right:0px">
<div class="col-sm-12 row">
<div class="container" style="padding-left:0px;padding-right:0px">
<div class="row divided">
<div class="col-sm-3 divder">
<button mat-mini-fab>1</button>
<span style="padding-left:15px">Login</span>
</div>
<div class="col-sm-3 divder">
<button mat-mini-fab>2</button>
<span style="padding-left:15px">Address</span>
</div>
<div class="col-sm-3 divder">
<button mat-mini-fab>3</button>
<span style="padding-left:15px">Mycart</span>
</div>
<div class="col-sm-3">
<button mat-mini-fab>4</button>
<span style="padding-left:15px">Payment</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
I think you're trying to do the same as you would do when using a stepper
https://material.angular.io/components/stepper/overview
Using import {MatStepperModule} from '#angular/material/stepper';
and the correct elements will do the trick
You can use :after psuedo class
.divider:after {
height:1px;
width:40px;
content:'';
background: red;
position:absolute;
right:0px;
top:15px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<div class="col-sm-12" style="padding-left:0px;padding-right:0px">
<div class="col-sm-12 row">
<div class="container" style="padding-left:0px;padding-right:0px">
<div class="row divided">
<div class="col-sm-3">
<button mat-mini-fab>1</button>
<span style="padding-left:0px">Login</span>
<span class="divider"></span>
</div>
<div class="col-sm-3">
<button mat-mini-fab>2</button>
<span style="padding-left:0px">Address</span>
<span class="divider"></span>
</div>
<div class="col-sm-3">
<button mat-mini-fab>3</button>
<span style="padding-left:0px">Mycart</span>
<span class="divider"></span>
</div>
<div class="col-sm-3">
<button mat-mini-fab>4</button>
<span style="padding-left:0px">Payment</span>
</div>
</div>
</div>
</div>
</div>
Following code adds equally sized lines between menu items as long there is enough space.
/* all direct children of menu and item are laid out in a single row as long as there is enough space */
.menu,
.item {
display: flex;
flex-flow: row wrap;
}
/* all menu items can grow except the last one */
.item:not(:last-child) {
flex-grow: 1;
}
/* a horizontal line is appended to all items if space is available (except the last item) */
.item:not(:last-child):after {
content: '';
border-bottom: 1px solid #000;
height: 50%; /* centers line vertically */
flex-grow: 1;
margin-right: 10px;
}
/* not relevant for menu (typography and resets) */
button,
span {
font-family: Times;
font-size: 16px;
padding: 0;
border: 0;
margin-right: 10px;
}
/* not relevant for menu (rounded buttons) */
button {
background-color: #ddd;
border-radius: 50%;
height: 20px;
width: 20px;
}
<div class="menu">
<div class="item">
<button>1</button>
<span>Login</span>
</div>
<div class="item">
<button>2</button>
<span>Address</span>
</div>
<div class="item">
<button>3</button>
<span>Mycart</span>
</div>
<div class="item">
<button>4</button>
<span>Payment</span>
</div>
</div>
A
I've got a partial view that I want to have a sticky footer on. Unfortunately the scrollable div overflows with my footer no matter what I try.
<div id="wrap">
<div class="container">
<div class="scrollable">
<div class="scrollable-content">
<div class="list-group">
<a ng-repeat="msg in chatmessages" href="#" class="list-group-item">
<div class="bubble bubble-{{msg.dir}}">{{msg.text}}</div>
</a>
</div>
</div>
</div>
</div>
</div>
<div id="footer">
<div class="container">
<form class="row row-chat">
<div class="input-group">
<input type="text" class="form-control" ng-model="messageText" placeholder="Type your message" />
<span class="input-group-btn">
<button type="submit" class="btn btn-primary">Send</button>
</span>
</div>
</form>
</div>
</div>
Custom CSS:
#wrap {
min-height: 100%;
height: auto !important;
margin: 0 auto -60px;
}
#footer {
margin-left: -20px;
margin-right: -20px;
padding-left: 20px;
padding-right: 20px;
}
fix the footer with the specifec height like using styles
#footer
{
top:1200px;
left:300px;
}