How do I center aligned vertically the text with my image - html

I'm trying to vertically centered align the text with my image. Currently, the text looks like it's aligned at the bottom of the image.
Here's my jsfiddle:
http://jsfiddle.net/huskydawgs/L5Le0w37/7/
Here's my HTML:
<div class="column-resources-box">
<img alt="Apples" height="50" src="http://www.clipartbest.com/cliparts/acq/ezj/acqezjKcM.jpeg" width="50" />
<h4 class="title-bar">Apple<br>
Center</h4>
<ul>
<li>Gala</li>
<li>Pink Lady</li>
<li>Fuji</li>
</ul>
</div>
Here's my CSS:
.column-resources-box {
width: 200px;
float: left;
margin: 15px;
}
.column-resources-box img {
margin:0 2%;
float:left;
height:50px;
width:50px;
}
}
h4.title-bar {
color: #2251a4;
background: none;
font-family: 'Arial', inherit;
font-weight: normal;
text-transform: none;
line-height: normal;
margin: 0;
padding: 0;
text-align: left;
}

Try this out.
I wrapped the two items you want centered in the div, and then centered the image.
.wrap {
display:inline
}
.apple_image {
vertical-align:middle
}
.column-resources-box {
width: 200px;
float: left;
margin: 15px;
}
.column-resources-box img {
margin:0 2%;
float:left;
height:50px;
width:50px;
}
}
h4.title-bar {
color: #2251a4;
background: none;
font-family: 'Arial', inherit;
font-weight: normal;
text-transform: none;
line-height: normal;
margin: 0 0 0 0;
padding: 0;
text-align: left;
}
<div class="column-resources-box">
<div class="wrap">
<a class="apple_image" href="http://en.wikipedia.org/wiki/Apple">
<img alt="Apples" height="50" src="http://www.clipartbest.com/cliparts/acq/ezj/acqezjKcM.jpeg" width="50" />
</a>
<h4 class="title-bar">AppleCenter</h4>
</div>
<ul>
<li>Gala</li>
<li>Pink Lady</li>
<li>Fuji</li>
</ul>
</div>

You could use absolute positioning to put things exactly where you want them.
Fiddle: http://jsfiddle.net/t8rL871j/
.column-resources-box {
width: 200px;
float: left;
margin: 15px;
position: relative;
}
.column-resources-box img {
margin:0 2%;
height:50px;
width:50px;
position: absolute;
}
h4.title-bar {
color: #2251a4;
background: none;
font-family:'Arial', inherit;
font-weight: normal;
text-transform: none;
line-height: normal;
margin: 0 0 0 0;
padding: 0;
text-align: left;
position: absolute;
top: 10px;
left: 60px;
}
.column-resources-box ul {
margin:60px 2%;
height:50px;
width:70px;
position: absolute;
}
<div class="column-resources-box"> <img alt="Apples" height="50" src="http://www.clipartbest.com/cliparts/acq/ezj/acqezjKcM.jpeg" width="50" />
<h4 class="title-bar">Apple<br>
Center</h4>
<ul>
<li>Gala</li>
<li>Pink Lady</li>
<li>Fuji</li>
</ul>
</div>

There's a syntax error in your CSS. Here's your CSS, excerpted from the top:
.column-resources-box {
width: 200px;
float: left;
margin: 15px;
}
.column-resources-box img {
margin:0 2%;
float:left;
height:50px;
width:50px;
}
}
Notice the extraneous close brace. That seems to be preventing the browser from getting to the remaining CSS.
Fixed: http://jsfiddle.net/L5Le0w37/13/
You can move it down a little to center it with position:relative; top:7px;:
Centered: http://jsfiddle.net/L5Le0w37/16/

I rewrote your code a bit but here's another possible way using top padding..
vertical-align: top;
padding: 4px 0px 0px 0px; /* adjust top padding */
http://jsfiddle.net/Hastig/mj5yzsr7/3/
You can adjust the spacing between Apple and Center with h4.title-bar { line-height: 25px; } then adjust the top padding to compensate.

Wrap your text and image inside of a div and style it like this:
HTML
<div class="appleWrapper">
<img alt="Apples" height="50" src="http://www.clipartbest.com/cliparts/acq/ezj/acqezjKcM.jpeg" width="50" />
<h4 class="title-bar">Apple<br>Center</h4>
</div>
CSS
.appleWrapper {
height: 50px;
}
.title-bar {
margin: 0;
position: relative;
top: 50%;
transform: translateY(-50%);
}
Check out the online example here

Related

HTML/CSS: How can I push the footer downwards indefinitely?

So far, I have managed to get my footer to always stick to the bottom, however, I have been struggling to get the content or images on my webpage to push the footer down. I have been trying absolute, fixed, relative positions for the footer but to no avail as the content in the class "container2" continues to go under the footer. It also shouldn't be sticky footer similar to the nav bar but like a natural footer where it is pushed down by content.
HTML/CSS: https://jsfiddle.net/jof0hzhc/2/
HTML
<!DOCTYPE html>
<html lang="en" class="app">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>ResponsiveNav</title>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script type="text/javascript" src="js/script.js"> </script>
</head>
<body class="bg2">
<div class="wrapper">
<header>
<nav>
<div class="menu-icon">
<i class="fa fa-bars fa-2x"></i>
</div>
<div class="logo">
ResponsiveNav
</div>
<div class="menu">
<ul>
<li>Home</li> <!--Classifying the button as "activepage" will allow the button to be red when the user is on the page.-->
<li>Current page</li>
<li>About Us</li>
<li>Contact</li>
</ul>
</div>
</nav>
</header>
<section class="content">
<p class="apphead">Heading</p>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<div class="container2">
<p class="apptext">Sub-heading</p>
<div class="games">
<img src="images/1.png">
<img src="images/2.jpg">
<img src="images/3.jpg">
<img src="images/4.jpg">
<img src="images/5.jpg">
<img src="images/6.jpg">
</div>
<br><br><br><br><br><br><br><br>
</div>
</section>
</div>
<footer>
<p class="foot">
Footer text. <br>
__________________________________________________________________________________________________ <br> <br>
About us
|
Contact us <br>
__________________________________________________________________________________________________
<section>
<p class="foot">Social Media</p>
<span class="social">
<img src="images/mail.png" alt="Mail" width="50px" height="50px"/>
<img src="images/facebook.png" alt="Facebook" width="50px" height="50px"/>
<img src="images/twitter.png" alt="Twitter" width="50px" height="50px"/>
</span>
</section>
<section>
<h3>All rights reserved<br></h3>
</section>
</p>
</footer>
</body>
</html>
CSS
html, body {
margin: 0;
padding: 0;
width: 98%;
background-color: black;
min-height: 100%;
}
body {
font-family: "Helvetica Neue",sans-serif; /*Keep this font or hamburger disappears*/
font-weight: lighter;
}
header {
width: 98%;
height: 13vh;
}
li>a{display:;}
li>a:hover, /*li hover makes the area around the list of text have a block of color around it when you hover over the text*/
li>a:focus{color:red;text-decoration:underline;} /*li focus is when you select the element, the element gets into a focus*/
footer { /*How do I even make the footer always stick at the very bottom no wonder the dimensions of the browser?*/
width:100%;
position:absolute;
height:300px;
font-size: 15px;
margin-left:auto;
margin-right:auto;
text-align:center;
background-color:black;
border-width: 10px;
color: white;
}
p {
color: black;
position: relative;
margin: 5px;
padding: 10px;
}
a { /*General styling for links to other pages or websites*/
text-decoration:none;
position:relative;
font-family: Trebuchet MS, sans-serif;
}
h2 { /*Styling for site title*/
font-size: 50px;
text-align:left;
color:white;
margin: 20px;
font-family: courier;
}
h3 {
font-size:20px;
padding-left:20px;
color: white;
}
.content { /*the main container that consists of most of the existing content*/
margin-top:5px;
width:100%;
height: 1400px;
margin-left: auto;
margin-right: auto;
}
.logo {
line-height: 60px;
position: fixed;
float: left;
margin: 16px 46px;
color: #fff;
font-weight: bold;
font-size: 20px;
letter-spacing: 2px;
}
nav {
position: fixed;
width: 100%;
line-height: 60px;
z-index: 1; /*Allows for the navigation bar to stack on top of content and not appear as it overlaps*/
}
nav ul {
line-height: 60px;
list-style: none;
background: black;
overflow: hidden;
color: #fff;
padding: 0;
text-align: right;
margin: 0;
padding-right: 40px;
transition: 1s;
}
nav.black ul {
background: orange;
opacity: 10;
}
nav ul li {
display: inline-block;
padding: 16px 40px;;
}
nav ul li a {
text-decoration: none;
color: white;
font-size: 16px;
}
.menu-icon {
line-height: 60px;
width: 100%;
background: #000;
text-align: right;
box-sizing: border-box;
padding: 15px 24px;
cursor: pointer;
color: orange;
display: none;
}
.activepage {
font-size: 25px;
color: red;
text-decoration: underline;
}
.welcome {
font-family: courier;
}
.inquiry {
font-size: 17px;
color: white;
}
.container2 {
background-color: darkgrey;
padding: 10px;
margin: 0;
width: 97.8%;
height: 1000px;
z-index: 0;
position:absolute;
overflow:hidden;
}
p.heading {
font-size: 25px;
font-weight: bold;
font-family: courier;
}
.foot {
color: white;
}
.bg2 {
background-image:url("hex.jpg");
height: 550px;
width: 102%;
}
.apphead {
color: white;
font-size: 100px;
font-family: courier;
}
.apptext {
color:white;
font-size: 45px;
font-weight: bold;
font-family: courier;
}
.games {
margin:0;
position:relative;
border:solid white;
}
.games img {
width: 640px;
height:250px;
padding: 5px;
transition: 1s;
}
.games img:hover {
transform: scale(1.1);
}
.item img{
display:block;
}
#media(max-width: 786px) {
.logo {
position: fixed;
top: 0;
margin-top: 16px;
}
nav ul {
max-height: 0px;
background: #000;
}
nav.black ul {
background: #000;
}
.showing {
max-height: 34em;
}
nav ul li {
box-sizing: border-box;
width: 100%;
padding: 24px;
text-align: center;
}
.menu-icon {
display: block;
}
}
First off, I am a bit confused why you are using the <br> tag so much, but it almost looks like you are trying to space the elements with them. You may want to use padding or margin to do that.
Lastly, I think what you are looking for is position: fixed. Try this:
footer {
width:100%;
position: fixed; /* use fixed instead of absolute */
bottom: 0; /* set bottom to 0 */
height:300px;
font-size: 15px;
margin-left:auto;
margin-right:auto;
text-align:center;
background-color:black;
border-width: 10px;
color: white;
}
You have several problems in your css. The main problem for your content not to appear is that you're using overflow: hidden; in container2 and height: 1000px; this causes everything that exceeds 1000px won't be show. Try removing overflow: hidden or overflow: x-scroll.
This is the documentation for the overflow property, I suggest you read it for a better understanding of your problem. https://developer.mozilla.org/en-US/docs/Web/CSS/overflow
There are some things that you should change 1. you are using absolute position outside relative 2. using absolute values for hight is not good practice 3. is always better use padding and margin to make space ect. Keep fixed position only for header nav and comment out all fixed hight values(px)and absolute and relative positioning to start with. Absolute position should be inside relative if there is not special reason not to do that. To get out from main problem start with footer and container2. But there is lot more to fix.
You need set a min-height for html, body {min-height: 100vh;}
Set footer as position: fixed; bottom: 0; left: 0;
Hopefully this will help you.

Center icon vertically next to text

I have tried below code to get desired output, how to display that lock in middle of that.
I have tried so many thing, which I found on SO, but nothing helpful.
I am not very experienced in CSS.
I want to display like this:
.inline-block {
display: inline-block;
}
.lock_image {
width: 30px;
height: 30px;
}
hr {
width: 250px;
margin: 0px;
bottom: 1px;
margin-bottom: 5px !important;
margin-top: 5px !important;
}
.title {
margin: 0px;
}
<div class="inline-block"><img src="https://image.ibb.co/f7sA2Q/icons8_Lock_50.png" alt="icons8_Lock_50" border="0" class="lock_image"></div>
<div class="inline-block">
<p class="title">Google Drive Integrated Email</p>
<hr>
<a class="mgl20" href="javascript:void(0);">xyz#gmail.com</a>
</div>
I added a wrapper around the content you had and made it a flexbox with vertical center alignment.
.wrapper {
display: flex;
align-items: center;
}
.inline-block {
display: inline-block;
}
.lock_image {
width: 30px;
height: 30px;
}
hr {
width: 250px;
margin: 0px;
bottom: 1px;
margin-bottom: 5px !important;
margin-top: 5px !important;
}
.title {
margin: 0px;
}
<div class="wrapper">
<div class="inline-block">
<img src="https://image.ibb.co/f7sA2Q/icons8_Lock_50.png" alt="icons8_Lock_50" border="0" class="lock_image">
</div>
<div class="inline-block">
<p class="title">Google Drive Integrated Email</p>
<hr>
<a class="mgl20" href="javascript:void(0);">xyz#gmail.com</a>
</div>
</div>
Please add vertical-align:middle in inline-block class.
.inline-block{
display:inline-block;
vertical-align:middle;
}
.lock_image{
width:30px;
height:30px;
}
hr{
width: 250px;
margin: 0px;
bottom: 1px;
margin-bottom: 5px !important;
margin-top: 5px !important;
}
.title{
margin:0px;
}
<div class="inline-block"><img src="https://image.ibb.co/f7sA2Q/icons8_Lock_50.png" alt="icons8_Lock_50" border="0" class="lock_image"></div>
<div class="inline-block"><p class="title">Google Drive Integrated Email</p><hr>
<a class="mgl20" href="javascript:void(0);">xyz#gmail.com</a>
</div>
Try this code:
Here is the jsfiddle: https://jsfiddle.net/rhulkashyap/71a9uLvy/
.inline-block{
display:inline-block;
vertical-align:middle;
}
.lock_image{
width:30px;
height:30px;
}
hr{
width: 250px;
margin: 0px;
bottom: 1px;
margin-bottom: 5px !important;
margin-top: 5px !important;
}
.title{
margin:0px;
}
<div class="inline-block"><img src="https://cdn.pbrd.co/images/GHHKwv7.png" alt="icons8_Lock_50" border="0" class="lock_image"></div>
<div class="inline-block"><p class="title">Google Drive Integrated Email</p><hr>
<a class="mgl20" href="javascript:void(0);">xyz#gmail.com</a>
</div>

Text wont align right

I cant get my text to align right:
#login_status
{
font-size: 1.2em;
text-align: right;
display: block;
float:right;
}
Here is the other pertinent css:
#logo
{
position: absolute;
top: 15%;
margin-left: 1em;
}
#login_status
{
font-size: 1.2em;
text-align: right;
display: block;
float:right;
}
#header_container
{
background: #7fc041;
height: 7.4em;
left: 0;
right: 0;
position: fixed;
width: 100%;
top: 0;
}
#header_text
{
margin-left: 9.75em;
font-size: 2em;
color: White;
font-style: italic;
}
and the html/server controls:
<div id="header_container">
<div id="header">
<div id="headerBar">
<img src="images/logo.png" id="logo"/>
<span id="header_text">Scrum Reports</span>
<asp:LoginStatus ID="LoginStatus1" runat="server" CssClass="login_status" />
</div>
</div>
</div>
Well I'm no asp.net expert, but I see you using #login_status with text-align: right and CssClass="login_status", which seems to me like it would output
<div class="login_status">
Thus you should either change #login_status to .login_status, or have it set the id rather than the class because the styles seem to be fine.
http://jsfiddle.net/ExplosionPIlls/mzUTW/

Website fast in Firefox, Mediocre in Internet Explorer and slow in Google Chrome

As the title suggests, my website works how I want it to work in Firefox: when I use arrow down, it doesn't flicker. But this functionality isn't such in IE and Chrome. Is there a resolution to this? The website is as follows: Contrabang. Thank you advance for your help.
HTML is as follows:
<section class="main">
<div class="icons">
<a class="twitter" target="_blank" href="http://www.twitter.com/kadeemlaurie"></a>
<a class="facebook" target="_blank" href="http://www.facebook.com/pages/Contrabang/127379984089682"></a>
<a class="googleplus" target="_blank" href="http://googleplus.com/pages"></a>
</div>
<div id="wrap">
<div id="featured">
<div class="wrap">
<div class="textwidget">
<div class="cup">
<img src="../Contrabang/img/red-cup.png" height="200" alt="red-cup">
</div>
</div>
</div>
</div>
<div id="theFixed"><h1>CONTRABANG</a></h1></div>
<div class="bg1">
<hgroup class="billboard second">
<h2 style="font-size: 33px; opacity: 1; font-family: 'dosis'">
We are an events management agency based in London. We create memorable experiences. Check out our upcoming event.</h2>
</hgroup>
<br>
<br>
<br>
<div class="pad">
<img src="../Contrabang/img/Contrabang.jpg" width="300" height="400" alt="contrabang">
</div>
<h2 style="font-size: 33px; opacity: 1; font-family: 'dosis'">
Buy Tickets: 07949747971</h2>
</div>
</div>
</section>
& the main CSS
.main{text-align:center;}
#featured {
background: #E94F78 url(http://www.contrabang.com/Contrabang/img/bubbles.png) no-repeat top;
background-size: 385px 465px;
color: #fff;
height: 535px;
overflow: hidden;
position: relative;
z-index: -2;
}
#featured .wrap {
overflow: hidden;
clear: both;
padding: 70px 0 30px;
position: fixed;
z-index: -1;
width: 100%;
}
#featured .wrap .widget {
width: 80%;
max-width: 1040px;
margin: 0 auto;
}
.textwidget{
padding: 0;
}
#wrap {
margin: 0 auto;
padding: 0;
}
.cup{
margin-top:210px;
}
body, h1, h2, h3, p {
margin: 0;
padding: 0;
}
a {
text-decoration: none;
}
a img { border: 0; }
#theFixed{
position:fixed;
background-image:url(http://www.contrabang.com/Contrabang/img/leopard-print.jpg);
width:100%;
text-align:center;
overflow: hidden;
background-position: center;
}
h1{
font: 800 1.313em "proxima-nova", sans-serif;
font-size:3.125em;
text-align:center;
padding:10px 10px;
margin:20px 20px;
background-color:#E94F78;
padding-left: 0.15em;
text-decoration:none;
display:inline-block;
letter-spacing: 6px;
padding-left: 0.15em;
color:yellow;
}
h1 a{
text-decoration: none;
letter-spacing: 8px;
padding-left: 0.15em;
color:yellow;
}
.bg1{
background-image:url(http://www.contrabang.com/Contrabang/img/grey-background.jpg);
width: 100%;
height:900px;
background-color: #e94f78;}
h2{
font-family: georgia;
font-size:3em;
color:black;
}
.billboard {
overflow: hidden;
width: 960px;
margin-left: auto;
margin-right: auto;
text-align: center;
}
.pad{
padding:20px;
}
.billboard a {
color: #000000;
}
.billboard {
padding-top:230px;
}
That Rita Ora image is almost 4mb in size. I'd hazard a guess that that's your culprit right there.
I'd suggest doing some reading up on optimising images for use on the web.
That image should be about 30/40k at most.

Image Description

http://jsfiddle.net/3V6MM/
Please tell me how can I write common style for class="property-title" to display the property name under the image.
Please guide me.
Images are placed like below
Have a look at this layout. Also note that ids should be unique. You are using image-thumb multiple times.
Live demo: http://jsfiddle.net/9C72X/
HTML
<div>
<div class="image-thumb">
<img src="http://www.javeacasas.com/images/javea-property.jpg">
<p class="property-title">Land for Sale</p>
</div>
<div class="image-thumb">
<img src="http://in.all.biz/img/in/service_catalog/15784.jpeg">
<p class="property-title">Sale at Mura, Puttur</p>
</div>
</div>
CSS
.image-thumb {
display: inline-block;
vertical-align: top; /* <-- update to solve multiline text */
width: 200px;
}
.image-thumb img {
width: 100%;
}
.property-title {
text-align: center;
font-size: 10px;
}
Personally I don't think you need to absolutely position the caption.
You might also consider using different mark-up.
<figure class="image-thumb">
<img class="imgthumg">
<figcaption class="property-title">
image title
</figcaption>
</figure>
try this, the float left is causing your image-thumb container to collapse.
.img-thumb {
position: relative;
padding-left: 5px;
word-spacing: 10px;
float: left;
}
.imgthumb {
width:230px;
height:161px;
background:#FFF;
border:1px solid #909090;
margin-left:10px;
margin-bottom: 30px;
}
.property-title {
bottom: 0;
font-family: 'Verdana';
font-size: 8pt;
margin-left: 10px;
margin-top: 10px;
width: 236px;
position: absolute;
}
Replace these css classes with the below one :
#image-thumb
{
padding-left: 5px;
word-spacing: 10px;
float:left;
}
.imgthumb
{
width:230px;
height:161px;
position:relative;
background:#FFF;
border:1px solid #909090;
margin-left:10px;
}
.property-title
{
font-family: 'Verdana';
font-size: 8pt;
margin-left: 10px;
margin-top: 0;
position: relative;
width: 236px;
}
http://jsfiddle.net/abhinavpratap/3V6MM/4/