Aligning text vertically using vertical align css [duplicate] - html

This question already has answers here:
How do I vertically align text in a div?
(34 answers)
Closed 6 years ago.
What the hell am I doing wrong haha.
I don't want to set the div's height because it should be set to auto depending on the image next to it. Am I using the tag wrong or something?
See my attached code.
Any help is greatly appreciated.
*{margin:0;padding:0;box-sizing:border-box;}
.hugme{margin:0 auto;max-width:947px;}
[class*=bit-]{float:left;padding:5px;}
#font-face {
font-family: 'Market Deco';
font-style: normal;
font-weight: normal;
src: local('Market Deco'), url('http://www.adambwhitten.com/obsw/Market_Deco.woff') format('woff');
}
/* Grids */
.box{background:#ed1b2e;font-family: 'Open Sans', sans-serif;font-size:14px;font-weight:700;text-align:center;padding:10px 0;}
.box-2{background:#00aabe;}
.bit-1{width:100%;}
.bit-2{width:50%;}
.bit-2-2{width:50%;}
.bit-3{width:33.33333%;}
.bit-4{width:25%;}
.bit-5{width:20%;}
.bit-6{width:16.66667%;}
.bit-7{width:14.28571%;}
.bit-8{width:12.5%;}
.bit-9{width:11.11111%;}
.bit-10{width:10%;}
.bit-11{width:9.09091%;}
.bit-12{width:8.33333%;}
.bit-25{width:25%;}
.bit-40{width:40%;}
.bit-60{width:60%;}
.bit-75{width:75%;}
.bit-35{width:35%;}
.bit-65{width:65%;}
.holdsmaller{max-width: 960px; margin: 0 auto;}
/* Buttons / Video Styles */
.holdbutton1 {
z-index:899;
margin: 10px;
}
.holdbutton2 {
z-index:899;
margin: 10px;
}
.holdbutton3 {
z-index:899;
margin: 10px;
}
.button-wrapper{
position:absolute;
width:100%;
height: 100%;
display:flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
}
.btnFall {
-webkit-border-radius: 5;
-moz-border-radius: 5;
border-radius: 5px;
color: #ffffff;
width:200px;
font-size: 14px;
background: #772539;
padding: 10px 20px 10px 20px;
text-decoration: none;}
.btnFall:hover {
background: #959356;
text-decoration: none;
}
#media only screen and (max-width: 756px){
.button-wrapper{flex-direction: column;}
}
#cf {position:relative; width:100%; margin:0 auto;}
#cf img {position:absolute; left:0; width:100%; height:auto; -webkit-transition: opacity 1s ease-in-out; -moz-transition: opacity 1s ease-in-out; -o-transition: opacity 1s ease-in-out; transition: opacity 1s ease-in-out;}
#cf img.top:hover{opacity:0;}
.showmobile{display:none;}
/* Responsive Goodness */
/* Defaults above are set Desktop resolution or higher */
/* Laptop */
#media (min-width:50em) and (max-width:68.75em){
.bit-7,.bit-35,.bit-65{width:100%;}
.bit-10,.bit-12,.bit-4,.bit-8{width:50%;}
}
/* Tablet */
#media (min-width:30em) and (max-width:50em){
.bit-10,.bit-12,.bit-4,.bit-6,.bit-8{width:50%;}
.bit-1,.bit-11,.bit-3,.bit-5,.bit-7,.bit-9{width:100%;}
img.product {margin-top:43px;}
img.product2 {margin-top:56px;}
}
/* Mobile */
#media (max-width:30em){
.bit-4{width:50%;}
.bit-1,.bit-10,.bit-11,.bit-12,.bit-2,.bit-3,.bit-5,.bit-6,.bit-7,.bit-8,.bit-9{width:100%;}
#cf, img.product, img.product2, img.hidemobile, .button-wrapper {display:none;}
.showmobile {display:block;}
}
<div class="hugme">
<div class="bit-2">
<div class="inner" style="vertical-align:middle;">
<font style="font-family:'Market Deco'; font-size:50px; color:#772539;">BOOT UP</font><br>
<font style="font-size:18px; color:#000;">Short, tall, over the knee, or with plush touches.<br>This fall, take your pick.</font>
<div class="btnFall" style="text-align:center;">SHOP NOW ></div>
</div>
</div>
<div class="bit-2">
<div id="cf">
<a href="http://www.google.com/">
<img class="bottom" src="http://i.imgur.com/J3DOMlR.jpg" width="100%"/> <!-- hover -->
<img class="top" src="http://i.imgur.com/dMmmOz9.jpg" width="100%"/> <!-- static -->
</a>
</div>
</div>
</div>
Thanks guys and gals!

According to MDN, vertical-align is a property used for inline elements. I don't think it would work on a div.

Related

My page keeps changing how it looks when I change window size

Let me first point out that I am new to HTML. I'm in high school and I'm currently making a website for my portfolio. Here's the problem, I can't get my page to be responsive. I have tried the stuff that was on the internet but they didn't seem to work. Here is my website- http://danil1.gitastudent.online/
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css2?family=Quicksand&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Quicksand', sans-serif;
font-size:25px;
overflow-x:hidden;
}
.container {
position:absolute;
width:100%;
}
.zoom {
padding: 10px;
transition: transform .2s;
margin: 0 auto;
}
.textG {
left:730px;
top:250px;
transition-property: left;
transition-duration: 0.15s;
transition-timing-function: linear;
position:relative;
z-index:-1;
}
.textI {
left:1180px;
top:250px;
transition-property: left;
transition-duration: 0.15s;
transition-timing-function: linear;
position:relative;
z-index:-1;
}
.textT {
left:730px;
top:750px;
transition-property: left;
transition-duration: 0.15s;
transition-timing-function: linear;
position:relative;
z-index:-1;
}
.textA {
left:1180px;
top:750px;
transition-property: left;
transition-duration: 0.15s;
transition-timing-function: linear;
position:relative;
z-index:-1;
}
.container:hover .textG{
left:850px;
}
.container:hover .textI{
left:1340px;
}
.container:hover .textT{
left:830px;
}
.container:hover .textA{
left:1400px;
}
.zoom:hover {
transform: scale(1.02);
</style>
</head>
<body>
<div style="position:relative; left:30; top:30; font-size:30px;"><b>GITA.</b></div>
<div class="container">
<div class="zoom">
<img src="G.png" id="g" width="40%" style="position:absolute; left:300; top:10;">
</div>
<div class="textG">
<div><b>ABOUT</b></div>
</div>
</div>
<div class="container">
<div class="zoom">
<img src="I.png" id="i" width="40%" style="position:absolute; left:850; top:10;">
</div>
<div class="textI">
<div><b>WORKS</b></div>
</div>
</div>
<div class="container">
<div class="zoom">
<img src="T.png" id="t" width="40%" style="position:absolute; left:300; top:450;">
</div>
<div class="textT">
<div><b>GITA</b></div>
</div>
</div>
<div class="container">
<div class="zoom">
<img src="A.png" id="a" width="40%" style="position:absolute; left:850; top:450;">
</div>
<div class="textA">
<div><b>CONTACT</b></div>
</div>
</div>
</body>
</html>
For each screen size you can use:
#media screen and (min-width: 900px) {
#your Code...
}
or
#media screen and (max-width: 900px) {
#your Code...
}
For more: https://developer.mozilla.org/en-US/docs/Web/CSS/#media
As I mentioned in my original comment, I'd strongly advise against using CSS position to establish layout. You'll find yourself in a cat-herding situation as content changes and as you're trying to adapt to different viewport sizes.
The snippet below does not faithfully recreate every aspect of your existing page, but it demonstrates a much simpler approach using less markup and less css that will be much easier to manage and make responsive.
img {
max-width: 100%; /* prevent images from being larger than their container */
}
.big-nav {
list-style: none; /* get rid of default list styling */
padding: 0; /* get rid of default list margin */
margin: 0; /* get rid of default list padding */
max-width: 1024px; /* limit max width */
margin: 0 auto; /* center in the page */
display: grid; /* use a grid layout */
grid-template-columns: 1fr 1fr; /* two equally sized columns */
gap: 1rem; /* space between the grid cells */
}
.big-nav > * {
border: 1px dashed lightblue; /* so you can see the grid */
}
<!-- set base href so your images will load -->
<base href="http://danil1.gitastudent.online/"/>
<div>
<div><b>GITA.</b></div>
<ul class="big-nav">
<li>
<img src="G.png">
<div class="label">ABOUT</div>
</li>
<li>
<img src="I.png">
<div class="label">WORKS</div>
</li>
<li>
<img src="T.png">
<div class="label">GITA</div>
</li>
<li>
<img src="A.png">
<div class="label">CONTACT</div>
</li>
</ul>
</div>

Where Has The Border Radius Gone on Mouseover

I'm making a menu selection bar, and I'm running into a problem when I mouse over. The icon's corners should all be curved, but only the left hand side ones are.
Here's a demo of the code: https://jsfiddle.net/gfqgcwq5/
From what I can tell, it seems like inline-block is the culprit here:
.wrapper{
display:inline-block;
margin:10px;
}
I just don't know how to accomplish the inline array without it. I'm not great at css, so if someone could lend me a hand, I'd appreciate it.
try this one:
.icon{
border-radius:8px;
padding-top:15px;
padding-bottom:5px;
transition:.1s;
font-size:60px;
display: inline-table;
}
.icon:hover{
cursor:pointer;
background-color: #00B1EB;
color:#fff;
}
span#picture > span {
padding-right:9px;
padding-left:10px;
padding-top:7px;
padding-bottom:10px;
}
.text{
text-align:center;
}
.wrapper{
display:inline-block;margin:10px;
}
DEMO HERE
Used to this
Define your .icon display inline-block
as like this
.icon{display:inline-block;line-height:60px;}
or you can used to
.icon{display:block;}
Demo
Remember that the border-radius is a property (in this case) of the .icon class, if you use the inspector you will see that the wrapper has the proper size and shapewraper
So as the other says the issue is on the display of the .icon class, If your idea is to have more than one .icon elements inside of the wrapper and inline, you should use display: inline-block;, if your call is to have just one per wrapper use display: block;.
Hope this helps you.
You gotta give icon block display: inline-block property in order to work !!
.icon {
border-radius: 8px;
padding: 15px;
padding-bottom: 5px;
transition: .5s all ease;
font-size: 60px;
display: inline-block;
}
.icon:hover {
cursor: pointer;
background-color: #00B1EB;
color: #fff;
}
span#picture > span {
padding-right: 9px;
padding-left: 10px;
padding-top: 7px;
padding-bottom: 10px;
}
.text {
text-align: center;
}
.wrapper {
display: inline-block;
margin: 10px;
}
<link href="https://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="wrapper">
<span id="picture" class="icon"><span class="glyphicon glyphicon-picture"></span></span>
<div class="text">PICTURES</div>
</div>
<div class="wrapper">
<span id="picture" class="icon"><span class="glyphicon glyphicon-picture"></span></span>
<div class="text">PICTURES</div>
</div>
<div class="wrapper">
<span id="picture" class="icon"><span class="glyphicon glyphicon-picture"></span></span>
<div class="text">PICTURES</div>
</div>
<div class="wrapper">
<span id="picture" class="icon"><span class="glyphicon glyphicon-picture"></span></span>
<div class="text">PICTURES</div>
</div>
Apply padding for the text div to allow the entire curve to visible.
.text{
text-align:center;
padding:0px 7px;
}
DEMO

Overriding listview item background in HTML- Windows Phone 8.1

I have the following template deisgned to display a listview. But the items in the list assign a background color of black by default. I am not able to override their BG color property. I have experience in native WP developement using C#. But in HTML 5 and WinJS am not able to figure out half the things about design.
HTML Code:
<div id="pivotScenario3" data-win-control="WinJS.UI.Pivot" data-win-options="{ selectedIndex: 4 }">
<div id="listViewMenu" class="listviewpivotitem" data-win-control="WinJS.UI.PivotItem" data-win-options="{ 'header': 'SPORTS' }">
<div data-win-control="WinJS.UI.ListView" data-win-options="{ itemDataSource: All.dataSource, layout: { type: WinJS.UI.ListLayout }, itemTemplate: menuItemTemplate, selectionMode: 'none' }"></div>
</div>
Template code:
<div id="menuItemTemplate" data-win-control="WinJS.Binding.Template">
<div class="menuItem">
<table>
<tr>
<td>
<img data-win-bind="src: logo" alt="Databound image" class="logo" />
</td>
<td>
<div class="selectionmodeHitTarget win-interactive"></div>
<div class="sportNameRoot">
<h2 class="sportName" data-win-bind="innerHTML: sportName"></h2>
</div>
</td>
</tr>
</table>
</div>
</div>
CSS:
.menuItem {
display: -ms-grid;
-ms-grid-columns: 20px 1fr 60px;
-ms-grid-rows: auto auto auto;
background-color: transparent;}
.menuItem .selectionmodeHitTarget {
/* So it is stacked on top of other grid elements */
position: relative;
z-index: 1;
-ms-grid-column: 1;
-ms-grid-row: 1;
-ms-grid-row-span: 3;
width: 16px; /* reserve 4px gap between highlight and item edge */
height: 100%;
transition: background-color 250ms ease-out 250ms, visibility 0ms linear 500ms, transform cubic-bezier(0.17,0.79,0.215,1.0025) 250ms;
}
.menuItem .selectionmodeHitTarget:active {
transition: background-color ease-out 100ms; /* fade in fast */
background-color: Highlight;
}
.menuItem .selectionmodeHitTarget:after {
margin: 0 16px;
width: 16px;
height: 100%;
content: '';
}
.win-selectionmode .menuItem .selectionmodeHitTarget {
transform: translateX(-41px); /* delayed by transition */
visibility: hidden;}
.win-selectionmode .win-item {
overflow: visible;}
CSS for pivot n listview
.listviewpivotitem.win-pivot-item .win-pivot-item-content {
/* Stretch across the whole width of the screen so the whole thing is pannable.*/
padding: 0;
margin: 0;
width: 100%;}
.win-listview {
height: 100%;}
#pivotScenario3 .win-listview .win-container {
margin: 0;
padding: 5px 0 0 0;
background-color: transparent;}
#pivotScenario3 .win-listview.win-rtl .win-item {
margin: 0 0 0 20px;}
#pivotScenario3{
color:white;}
My need is that, i want to set any desired color as background color for listview items.
I know this is a lot of code to go through but my problem is too complicated. Haven't found a solution since a week. This is my last resort.
All help, suggestions and answers are appreciated!
Bind color code with style property
like:
<div data-win-bind="style.background:Color"></div>
it will give you the expected result.
All the Best..!!

CSS perfect square grid slightly imperfect; small margin forms from who knows where

I'm trying to create a group of divs that are to be perfectly fluid squares, resizable with the viewport.
Here's the HTML structure:
<div id="container">
<div id="row">
<div class="cell A1">
<img class="spacer" src="http://imgur.com/t5M1ryQ">
<div id="text">MIKEY
<br/>
<p>SPINDRIFT KIOSK</p>DIGITAL COLLAGE</div>
</div>
<div class="cell A2">
<img class="spacer" src="http://imgur.com/t5M1ryQ">
<div id="text">ERIC
<br/>
<p>LIZ & RYAN HEMSWORTH</p>ALBUM DESIGN</div>
</div>
<div class="cell A3">
<img class="spacer" src="http://imgur.com/t5M1ryQ">
<div id="text">MIKEY
<br/>
<p>EPHEMERA</p>DIGITAL COLLAGE</div>
</div>
<div class="cell A4">
<img class="spacer" src="http://imgur.com/t5M1ryQ">
<div id="text">ERIC
<br/>
<p>REJJIE SNOW</p>SITE DESIGN</div>
</div>
</div>
The img class="spacer" image is a blank square png intended to 'stretch out' a div to prevent it from being 0x0.
Here's some CSS. I've included a little extra because I'm not sure exactly what's causing it.. I believe it's the :before elements.
.A1, .A2, .A3, .A4 {
position:relative;
}
.A1:before, .A2:before, .A3:before, .A4:before {
content:"";
position: absolute;
width: 100%;
height: 100%;
top: 0px;
left: 0px;
transition: opacity .2s ease-in-out;
-moz-transition: opacity .2s ease-in-out;
-webkit-transition: -webkit-filter .2s ease-in-out;
filter: url(filters.svg#grayscale);
/* Firefox 3.5+ */
filter: gray;
/* IE6-9 */
-webkit-filter: grayscale(90%) brightness(30%);
/* Google Chrome, Safari 6+ & Opera 15+ */
z-index: -1;
}
.A1:before {
background-image:url('spindrift.jpg');
background-size:cover;
}
.A2:before {
background-image:url('daynnite.jpg');
background-size:cover;
}
.A3:before {
background-image:url('');
background-size:cover;
}
.A4:before {
background-image:url('');
background-size:cover;
}
.A1:hover:before, .A2:hover:before, .A3:hover:before, .A4:hover:before {
-webkit-filter:none;
}
/* text hover */
div.cell:hover #text {
opacity:0;
}
#text {
opacity:1;
display:table;
position:absolute;
z-index:999;
color:#ffffff;
text-align:center;
width:100%;
top:44%;
left:0;
text-decoration:none;
}
p {
font:16px ProximaNovaBold, sans serif;
margin:0;
padding:1 0 1 0;
}
/* table rules */
#container {
display:table-row;
width:100%;
}
#row {
display:table-row;
width:100%;
}
.cell {
position:relative;
display:table-cell;
width:700px;
height:auto;
}
html {
margin:0;
padding:0;
height:100%;
width:100%;
}
body {
height:100%;
width:100%;
margin:0;
padding:0;
background-color:black;
color:black;
}
/* image SPACER rules */
img {
max-height:600px;
max-width:100%;
height:auto;
width:100%;
z-index:2;
}
I'm using some webkit filters over the background images of these divs, and I don't want these filters affecting the child text so I MUST use the :before indicator. Here's a fiddle
http://jsfiddle.net/QC28s/2/
They are blank(with no background images) right now, it shouldn't matter. If you go into developer tools and look at the divs, the spacer is behaving correctly as it forces each square to 209x209. However if you look at the :before indicator directly before it on the HTML you can see that it(:before) is putting a small 6px margin on the bottom of the squares, making them 209x215. That's what my problem is... Much appreciated.
Explanation :
The :before element has position:absolute; so it can't expand it's parent. The problem doesn't come fro there.
The issue is the whitespace created by the images. Images are inline elements they add white-space just after them (like inline-block elements).
Solution :
Add display:block; to the image tag so they are not inline elements anymore and don't add white-space.
See this FIDDLE
Btw you might be intersted in this question

How To Add An "a href" Link To A "div"?

I need to know how to add an a href link to a div? Do you put the a href tag arounf the entire "buttonOne" div? Or should it be around or inside the "linkedinB" div?
Here's my HTML:
<div id="buttonOne">
<div id="linkedinB">
<img src="img/linkedinB.png" width="40" height="40">
</div>
</div>
Can't you surround it with an a tag?
<a href="#"><div id="buttonOne">
<div id="linkedinB">
<img src="img/linkedinB.png" width="40" height="40">
</div>
</div></a>
try to implement with javascript this:
<div id="mydiv" onclick="myhref('http://web.com');" >some stuff </div>
<script type="text/javascript">
function myhref(web){
window.location.href = web;}
</script>
In this case, it doesn't matter as there is no content between the two divs.
Either one will get the browser to scroll down to it.
The a element will look like:
buttonOne
Or:
linkedinB
Try creating a class named overlay and apply the following css to it:
a.overlay { width: 100%; height:100%; position: absolute; }
Make sure it is placed in a positioned element.
Now simply place an <a> tag with that class inside the div you want to be linkable:
<div id="buttonOne">
<a class="overlay" href="......."></a>
<div id="linkedinB">
<img src="img/linkedinB.png" alt="never forget the alt tag" width="40" height="40"/>
</div>
</div>
PhilipK's suggestion might work but it won't validate because you can't place a block element (div) inside an inline element (a). And when your website doesn't validate the W3C Ninja's will come for you!
An other advice would be to try avoiding inline styling.
I'd say:
<a href="#"id="buttonOne">
<div id="linkedinB">
<img src="img/linkedinB.png" width="40" height="40">
</div>
</div>
However, it will still be a link. If you want to change your link into a button, you should rename the #buttonone to #buttonone a { your css here }.
Your solutions don't seem to be working for me, I have the following code. How to put link into the last two divs.
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<style>
/* Import */
#import url(https://fonts.googleapis.com/css?family=Quicksand:300,400);
* {
font-family: "Quicksand", sans-serif;
font-weight: bold;
text-align: center;
text-transform: uppercase;
-webkit-transition: all 0.25s ease;
-moz-transition: all 0.25s ease;
-ms-transition: all 0.25s ease;
-o-transition: all 0.025s ease;
}
/* Colors */
#ora {
background-color: #e67e22;
}
#red {
background-color: #e74c3c;
}
#orab {
background-color: white;
border: 5px solid #e67e22;
}
#redb {
background-color: white;
border: 5px solid #e74c3c;
}
/* End of Colors */
.B {
width: 240px;
height: 55px;
margin: auto;
line-height: 45px;
display: inline-block;
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
-o-box-sizing: border-box;
}
#orab:hover {
background-color: #e67e22;
}
#redb:hover {
background-color: #e74c3c;
}
#whib:hover {
background-color: #ecf0f1;
}
/* End of Border
.invert:hover {
-webkit-filter: invert(1);
-moz-filter: invert(1);
-ms-filter: invert(1);
-o-filter: invert(1);
}
</style>
<h1>Flat and Modern Buttons</h1>
<h2>Border Stylin'</h2>
<div class="B bo" id="orab">See the movies list</div></a>
<div class="B bo" id="redb">Avail a free rental day</div>
</html>