Vertically align text to middle of inline-block - html

I am trying to get text to vertically align to the middle but can't seem to get it to work.
HTML:
<div class="row">
<div class="col-md-4">
Login
</div>
<div class="col-md-4">
Menu
</div>
<div class="col-md-4">
Contact
</div>
</div>
CSS:
.custom-button {
color:#ECDBFF;
background-color:#4F0100;
display:inline-block;
height: 220px;
font-family:Verdana, Geneva, sans-serif;
font-size:20px;
font-weight:bold;
text-align:center;
text-decoration:none;
}
.width-100 {width: 100%;}
I have googled quite a bit and tried a couple of things but i can't seem to get the text to go to the middle. can anyone advise what i would need to add/change to get this to work.

If your have a text which is restricted to single line then line-height would be the best solution.
try with this
line-height:220px; /*height of your container */
JsFiddle Demo

You can as well use vertical-align a pseudo element (:before or :after ) and an extra box (inline-block) to allow content to wrap on a few lines : see and run snippet below.
.custom-button {
color: #ECDBFF;
background-color: #4F0100;
display: inline-block;
height: 220px;
font-family: Verdana, Geneva, sans-serif;
font-size: 20px;
font-weight: bold;
text-align: center;
text-decoration: none;
}
.width-100 {
width: 100%;
}
.custom-button:before {
display:inline-block;
content:'';
height:220px;
vertical-align:middle;
margin:-0 -0.25em;;
}
a span {display:inline-block;
vertical-align:middle;
}
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"/>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css"/>
<div class="row">
<div class="col-md-4 col-xs-4">
Login
</div>
<div class="col-md-4 col-xs-4">
Menu
</div>
<div class="col-md-4 col-xs-4">
<span>Cont<br/>act</span>
</div>
</div>

Related

There are excess white spaces between three divs on the same row

HTML
<div id="main_page">
<div class="row d-flex align-items-center">
<div class="d-inline-block col-md-4 cuisine_slogan">
<h2>Enjoy different cuisines around the world!</h2>
</div>
<div class="d-inline-block col-md-4 padding-0 pict01">
<img src="different_cuisines.png" alt="cuisines_picture01" width="630" height="600">
</div>
<div class="d-inline-block col-md-4 padding-0 pict02">
<img src="different_cuisines02.png" alt="cuisines_picture02" width="600" height="600">
</div>
</div>
</div>
CSS
body {
padding-top: 60px;
margin: 0;
overflow-x: hidden;
}
#main_page {
padding-top:20px;
}
#main_page h2{
float:left;
}
.cuisine_slogan{
height:600px;
background-color:greenyellow;
}
.cuisine_slogan h2{
padding-top:150px;
padding-left:30px;
font-size:80px;
text-align:center;
}
.row{
padding:0;
margin-right: 0;
}
img{
margin-right: 0;
margin-left:0;
}
I tried to use margin-left:0; and margin-right:0; on the img part but when I refresh the html page it still contains white spaces between images and the green box. May I ask is there a method to make the green box stick with the images without any white spaces on the row including the leftmost and rightmost?
I think you are using bootstrap, so you can add inline padding-left:0; to columns
.padding-0 {
padding-left: 0 !important;
}

Centering text in bootstrap

I want to create a website as a portfolio for my other work. However I'm having a lot of trouble with centering text within my links. I've tried multiple methods to no avail.
The text I'm trying to alter is the text in the navigation section "about me" "portfolio" "skills" "contact" The text is within a row-->column-->link
I've attempted applying the text-center class in multiple different positions throughout the code and I've also tried applying it within my CSS using the text-align function. There isn't too much code so I imagine that someone with a bit of HTML experience will solve this in no time.
#mainContainer{
z-index:0;position:fixed;
width:100%; height:100%;
background-color: white;
}
.headerClass{
margin-top:auto;
margin-bottom:auto;
}
#headText{
color:white;
font-size: 1.5vw;
font-family: fantasy;
vertical-align: middle;
}
#infoBox{
height:100%;
width:100%;
}
#infoBoxCol{
background-repeat: no-repeat;
background-size:cover;
}
.navbar{
border-style: solid;
border-color: white;
width: 100%;
color:white;
font-family:fantasy;
font-size: 1.1vw;
text-align:center;
}
.navRoof{
text-align:center;
width:100%;
height:10%;
background-color:white;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<div class="container-fluid text-center" id="mainContainer">
<div class="row" style="background-color: black; height:30%;">
<div class="col-4 my-auto text-fluid" class="headerClass" id="headText">
Software Developer
</div>
<div class="col-1"></div>
<div class="col-2 my-auto"><img class="img-fluid" src="images/logo.jpg" style="max-width:85%;"></div>
<div class="col-1"></div>
<div class="col-4 my-auto">
<div class="row" id="navigation">
<div class="col-3">About Me</div>
<div class="col-3">Portfolio</div>
<div class="col-3">Skills</div>
<div class="col-3">Contact</div>
</div>
</div>
</div>
</div>
Here i using bootstrap flex instead of row > col-* to have a more flexible design, one thing that you are doing wrong is u are overwriting the bootstrap class "navbar" it have his properties more your news properties this make your design problems. Also is bad idea use vw as unit for font-size if u want get responsive design.
#mainContainer{
z-index:0;position:fixed;
width:100%; height:100%;
background-color: white;
}
.headerClass{
margin-top:auto;
margin-bottom:auto;
}
#headText{
color:white;
font-size: 1.5vw;
font-family: fantasy;
vertical-align: middle;
}
#infoBox{
height:100%;
width:100%;
}
#infoBoxCol{
background-repeat: no-repeat;
background-size:cover;
}
.navRoof{
text-align:center;
width:100%;
height:10%;
background-color:white;
}
.custom-navbar-container {
border-style: solid;
border-color: white;
}
.custom-link {
white-space: nowrap;
color:white;
font-family:fantasy;
font-size: 1.1vw;
padding: .25rem;
display: block;
}
.custom-link:hover {
text-decoration: none;
color: grey;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<div class="container-fluid text-center" id="mainContainer">
<div class="row" style="background-color: black; height:30%;">
<div class="col-4 my-auto text-fluid" class="headerClass" id="headText">
Software Developer
</div>
<div class="col-1"></div>
<div class="col-2 my-auto"><img class="img-fluid" src="images/logo.jpg" style="max-width:85%;"></div>
<div class="col-1"></div>
<div class="col-4 my-auto">
<div class="d-flex" id="navigation">
<div class="p-1">
<div class="custom-navbar-container">
About Me
</div>
</div>
<div class="p-1">
<div class="custom-navbar-container">
Portfolio
</div>
</div>
<div class="p-1">
<div class="custom-navbar-container">
Skills
</div>
</div>
<div class="p-1">
<div class="custom-navbar-container">
Contact
</div>
</div>
</div>
</div>
</div>
</div>

HTML CSS aligning divs and text next to image

Hello I have read a few articles of people with similar struggles to me but none of the solutions seem to work for me.enter image description here
I am trying to create something like the picture attached but the text always seems to go underneath the image, whatever CSS I edit.
.newstitle {
background-color: #ffed00;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: 20px;
display: inline-block;
}
.newspic img {
padding: 20px;
height: 300px;
vertical-align: middle;
}
<section class="main">
<div class="newspic">
<img src="https://placehold.it/500x300" alt="Photo placeholder">
</div>
<div class="newstitle">
D'votion presents his bassline remix of Post Malone's Rockstar
</div>
</section>
Just place the text container inside the div with the image.
<section class="">
<div class="newspic">
<img src="Art portfolio/illustrations/IMG_0844.JPG" alt="Photo placeholder">
<div class="newstitle">
D'votion presents his bassline remix of Post Malone's Rockstar
</div>
</div>
</section>
Why not try this instead:
HTML
<section class="main">
<div class="newspic">
<img src="https://images.unsplash.com/photo-1476124861542-44354851e622?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&s=eac3b3d003e83c809de608dd6dcc3857" alt="Photo placeholder">
</div>
<div class="newstitle">
D'votion presents his bassline remix of Post Malone's Rockstar
</div>
</section>
CSS
.main {
display: flex;
justify-content: space-between;
}
.newspic {
width: 50%;
}
.newspic img {
max-width: 100%;
}
You can view it here: https://codepen.io/jobaelish/pen/QaxXww
This is a simple fix.
Nonetheless, if you're HTML is not being affected, then you need to make sure your stylesheet is linked in your document head element properly.
<link rel="stylesheet" type="text/css" href="PATHTOCSSHERE">
There are "several" ways to accomplish this task. One way is to just add display inline on your side text and float the picture to the left. Also set a width on your picture. You could also use flexbox or you could of just used float with the text in the same div as the picture.
.newstitle{
background-color: #ffed00;
font-family : Arial, Helvetica, sans-serif;
font-weight : bold;
font-size: 20px;
display: inline;
}
.newspic img{
width: 300px;
float: left;
padding: 20px;
height: 300px;
vertical-align: middle;
}
<section class="main">
<div class="newspic">
<img src="https://www.google.com/logos/doodles/2018/zhou-youguangs-112th-birthday-5826412689752064-law.gif" alt="Photo placeholder">
</div>
<div class="newstitle">
D'votion presents his bassline remix of Post Malone's Rockstar
</div>
</section>
I removed the <div> container for the <img> and passed the class="newspic" to the image. Then I positioned both .newstitle and .newspic relatively to their parent and gave them width:70% and width:30%; respectively.
The key here, since you are using paddings is to include box-sizing:border-box; into both classes so the paddings are taken account for when calculating the width.
Here is the working code: (run the snippet & try full screen)
.main{
}
.newstitle
{
position:relative;
float:left;
width:70%;
background-color: #ffed00;
font-family : Arial, Helvetica, sans-serif;
font-weight : bold;
font-size: 16px;
box-sizing:border-box;
}
.newspic
{
position:relative;
float:left;
padding: 20px;
width:30%;
height: auto;
box-sizing:border-box;
}
<section class="main">
<img class="newspic" src="https://i2.wp.com/farm3.staticflickr.com/2883/9197736562_3cce3c65ee_o.jpg" alt="Photo placeholder" />
<div class="newstitle">
<p>D'votion presents his bassline remix of Post Malone's Rockstar</p>
</div>
</section>

Why I can't align two divs correctly

I have one div container called row3red3
Inside I have 2 divs, left (.row3red3slika) and right(.row3red3info).
I can't right divs .row3red3info to set on top inline after image.
I tried and set width for .row3red3slika but not working, i have problem i think with row3red3slika width.?
HTML
<div class="row3red3">
<div class"row3red3slika">
<img src="img/slika2.jpg" alt="Slika2" height="150px" width="215px">
<div class="imgtext1">
<span><i class="fa fa-university"></i></span>
</div><div class="imgtext2">
<span>PORTSAID EGYPT</span>
</div>
</div>
<div class="row3red3info">
<span>text</span>
</div>
</div>
CSS
.row3red3{
width:900px;
padding-left: 15px;
padding-top: 15px;
}
.row3red3slika{
width:215px;
height:150px;
}
.row3red3 .imgtext1{
display:inline-block;
position: relative;
background-color:#3E6373;
color:white;
margin-top: 95px;
margin-left:10px;
padding: 4px;
}
.row3red3 .imgtext2{
display:inline-block;
position: relative;
font-size: 14px;
background-color:#3E6373;
color:white;
font-family: 'Roboto Condensed', sans-serif;
margin-top: 60px;
padding: 4px;
}
.row3red3 img{
position: absolute;
display:inline-block;
vertical-align: top;
}
.row3red3info{
font-size:20px;
}
Add float: left; to .row3red3, .imgtext1 and .row3red3info, and .row3red3 img. Also you missed a = in:
<div class"row3red3slika">
it should be:
<div class="row3red3slika">
Have you tried floating your inner divs?
.row3red3info {float:right;}
.row3red3slika{float:left;}
Might help to set up a jsfiddle for this.
you can use float:left . also if you want to get rid of coding you can use Bootstrap. it does have a perfect grid system that is totally customizable
here a link to it's grid system tutorial http://www.w3schools.com/bootstrap/bootstrap_grid_system.asp

header width should adjust if floating image is not there

<div class="info-content" style="display:none;">
<div class="info-content-header clear">
<h1 class="lg-grn-color">Connect To Your Security System</h1>
<div><img src="/mobile/images/smb_fast.png"/> </div>
</div>
</div>
<style>
.info-content .info-content-header h1 {
float: left;
font-weight: normal;
}
.info-content .info-content-header div{
float:left;
margin-left:2rem;
width:30%;
}
</style>
So this my css and html file when image div is not there header should expand to 100% width
Since you float the h1 tag, it will only be the width it needs (adapting to its content). Put the image inside your header, and make the image float. The header then will always be 100% width.
<div class="info-content" style="display:none;">
<div class="info-content-header clear">
<h1 class="lg-grn-color">Connect To Your Security System
<img src="/mobile/images/smb_fast.png"/></h1>
</div>
</div>
.info-content .info-content-header h1 {
font-weight: normal;
}
.info-content .info-content-header h1 img {
float:left;
margin-left:2rem;
width:30%;
}