Ok, so i have been looking around for someone with the same problem as me, but didn't find any(almost 100% shure some of you guys are going to link to to one).
I have managed to center a div inside a div which again is inside footer(pretty shure overkill). But my problem is that i have centered two images with two lines of text connected to them. I want the text to be displayed vertically centered(with the image in mind), and not in the bottom right corner of the images, like now.
Pretty shure it's something simple, but here is a link:
http://jsfiddle.net/rdsdmuw8/
<footer>
<div id="footer">
<div id="sosial">
<img src="bilder/telefon.jpg" style="height:50%;">
+47 930 98 907
<img src="bilder/mail.png" style="height:50%; margin-left:20%; margin-top:20px;">
Bryter-pedersen#hotmail.com
</div>
</div>
</footer>
*{
margin: 0px;
padding: 0px;
color: #fff;
}
footer {
width:100%;
height: 80px;
background-color: red;
}
#footer{
height: 100%;
}
#sosial {
text-align: center;
vertical-align: middle;
}
#sosial a{
list-style-type: none;
text-decoration: none;
}
In order to vertically align the img elements next to the anchors set vertical-align: middle for both of the elements.
#sosial img,
#sosial a {
vertical-align: middle;
}
In order to vertically center all the containing elements within the footer, you can use the table-cell/table approach.
#footer {
height: 100%;
width: 100%;
display: table;
}
#sosial {
text-align: center;
display: table-cell;
vertical-align: middle;
}
Updated Exmaple
I removed the inline CSS styling in the example. You can use img:nth-of-type() to apply the margin to the second element. Just throwing options out there.
#sosial img:nth-of-type(2) {
margin-left:50px;
}
if you know what is the height you want for the images you can use, in my example is 50px:
#sosial a {
list-style-type: none;
text-decoration: none;
line-height: 50px;
display: inline-block;
height: 100%;
vertical-align: middle;
}
Related
I'm trying to line this logo and the text on the same line, but have the logo on the left hand corner of the site, and the text be centered. Here's what it looks like now and what the CSS and HTML is so far.
Here's my current code:
#title {
font-family: sans-serif;
text-align: center;
color: #E03DA7;
vertical-align: top;
display: inline;
align-content: right;
}
body {
align-content: center;
vertical-align: top;
margin: 0;
width: 100%;
height: 100%;
}
#navbar {
font-family: monospace;
font-size: 25px;
text-align: center
}
#mainpara {
text-align: left;
max-width: 300px;
max-height: 750px;
font-size: 20px;
vertical-align: middle;
font-family: sans-serif
}
img {
max-width: 100px
}
<img src="WOW_logo_RGB.jpg">
<h1 id="title">Welcome, to WOW Virtual.</h1>
<h3 id="navbar">About Us | Live Radar | Why Join?</h3>
<p id="mainpara">Welcome to WOW Virtual, a fresh new Virtual Airline for the Flight Simulator community. We offer only the best for our pilots, and strive to maintain the best service for any of our pilots. Interested? Join Today!</p>
You can achieve the desired results with Flexbox
If you contain your img and h1 in a container (say header), add the following CSS to the header tag
header {
display: flex;
align-items: center; /* align vertical */
}
Results can be found here, with your modified code: JSFiddle
Have the text and picture in one div with text-align centered. Then you can center the div itself if you want it to be in the center.
It's as simple as this:
#title, img {
vertical-align: middle;
}
#title {
display: inline;
}
<img src="https://placeimg.com/60/60/tech">
<h1 id="title">Welcome, to WOW Virtual.</h1>
<h3 id="navbar">About Us | Live Radar | Why Join?</h3>
Edit: If you want the text to be centered, you have to take another approach:
#header {
position: relative;
}
h1 {
line-height: 60px;
text-align: center;
}
#header img {
position: absolute;
height: 60px;
}
#navbar {
text-align: center;
}
<div id="header">
<img src="https://placeimg.com/60/60/tech">
<h1>Welcome, to WOW Virtual.</h1>
</div>
<h3 id="navbar">About Us | Live Radar | Why Join?</h3>
By using position:absolute on the img tag, you ensure that the h1 tag is centered to the full width of the page.
More of an hackish way, you can put the img and h1 into a div with class .header.
Then set the line-height of the div to the height of the image:
.header {
line-height:100px;
}
You can see the output here.
Normally with table tag, you can apply Vertical align property as middle for you table cells .
If you want to use the same property / behaviour for your div. Then use display:table-row to your parent (.header) and then display:table-cell to the child div around Logo and the text.
That would allow you to use vertical-align:middle.
check through the edit made by copying your initial code snippet. Let me know if you have any query
.header{
display:table-row;
}
.header > div{
display:table-cell;
vertical-align:middle;
}
#title {
font-family: sans-serif;
text-align: center;
color: #E03DA7;
vertical-align: top;
display: inline;
align-content: right;
}
body {
align-content: center;
vertical-align: top;
margin: 0;
width: 100%;
height: 100%;
}
#navbar {
font-family: monospace;
font-size: 25px;
text-align: center
}
#mainpara {
text-align: left;
max-width: 300px;
max-height: 750px;
font-size: 20px;
vertical-align: middle;
font-family: sans-serif
}
img {
max-width: 100px
}
<html>
<body>
<div class="header">
<div>
<img width="250" height="250" src="WOW_logo_RGB.jpg">
</div>
<div>
<h1 id="title">Welcome, to WOW Virtual.</h1>
</div>
</div>
<h3 id="navbar">About Us | Live Radar | Why Join?</h3>
<p id="mainpara">Welcome to WOW Virtual, a fresh new Virtual Airline for the Flight Simulator community. We offer only the best for our pilots, and strive to maintain the best service for any of our pilots. Interested? Join Today!</p>
</body>
</html>
I need to horizontally and vertically center text in a paragraph. The paragraph itself must fill 100% of the available height and width of the parent element without setting an explicit/static width for the paragraph (percentage like 100% is acceptable).
HTML
<div>
<p>Sudo make me a sandwich.</p>
</div>
CSS
div
{
background-image: url('idahoisntafraidofgorillas.png');
height: 138px;
width: 100%;
}
p
{
display: table-cell;
text-align: center;
vertical-align: center;
}
Ideally this should not require anything greater than CSS level 2. The current code doesn't actually center the text unless I set a static width however that would spam up the CSS I'm working on so I'm seeking a more elegant and proper solution.
Try vertical-align: middle also add display: table to div
div {
height: 138px;
width: 100%;
border: 1px solid black;
display: table;
}
p {
display: table-cell;
text-align: center;
vertical-align: middle;
}
<div>
<p>Sudo make me a sandwich.</p>
</div>
Set the line-height, vertical-align:middle;, and make sure there is no extra margin, margin:0px; all on the paragraph element.
div {
height: 138px;
width: 100%;
border: 1px solid black;
}
p {
margin:0px;
line-height:138px;
text-align: center;
vertical-align: middle;
}
<div>
<p>Sudo make me a sandwich.</p>
</div>
I want to position the content of these two divs to the top.
HTML
<div class="menu">
<div></div>
</div>
<div class="content">
<h1>SDFSDFSD SDFSD</h1>
<h1>SDFSDFSD SDFSD</h1>
<h1>SDFSDFSD SDFSD</h1>
</div>
css
.
menu {
display: table-cell;
background-color: yellow;
width: 20%;
}
.menu > div {
padding: 20px;
background-color: red;
vertical-align: top;
}
.content {
display: table-cell;
background-color: blue;
width: 80%;
}
http://jsfiddle.net/99u4vm3g/
I tried with vertical-align: top and with position: absolute and top:0 with no luck.
What should I do to send those content to the top of their containers?
Thanks in advance!
You added vertical-align:top to the wrong place, it should be applied to the table-cell elements.
Updated: http://jsfiddle.net/tfqmwko1/
You need to put the vertical-align on the table-cell elements
.menu {
vertical-align: top;
}
.content {
vertical-align: top;
}
http://jsfiddle.net/99u4vm3g/1/
You are going to see the text still not at the top and that is due to the margin on the header elements
This one has no margin on the header tags http://jsfiddle.net/99u4vm3g/2/
Link to site
/*Align width 1170px*/
.align-1170{
height: 100%;
width: 1170px;
margin: 0 auto;
}
/*Align vertically*/
.align-vertically{
height: 100%;
display: table;
}
/*Header*/
header{
height: 60px;
width: 100%;
background-color: #1ccb56;
}
.logo{
display: table-cell;
vertical-align: middle;
}
.author{
float: right;
display: table-cell;
vertical-align: middle;
}
Why Can't I use float:right; to move "Author: projekcior.com" to right side
(with vertically alignment)?
Why my h3 tag is so wide? (650px)
Thanks!
An element that is floated is automatically display: block;
use
h3 { display:inline-block; }
to manage your h3 width.
Let me answer your question in steps.
Why Can't I use float:right; to move "Author: projekcior.com" to right side (with vertically alignment)?
Maybe because, you're not setting the margins to it. It actually is to the right side of the web page. I just tried to use margin for it.
p.white {
margin: 20px;
}
Using this, it came down a bit from the top corner.
Why my h3 tag is so wide? (650px)
Because you've not set any of the width: value to the element, so browser would automatically set the width. I used width property to minimize the size.
h3 {
width: 200px;
}
Here is the screen shot for your page.
Hey Komon i guess you didn't write a proper css for your webpage so i tried to correct your page see the mentioned below CSS :-
CSS
.align-vertically {
border: 1px solid;
}
.align-1170 {
height: 100%;
margin: 0 auto;
width: 1170px;
}
.logo {
float: left;
}
h3 {
border: 1px solid;
display: inline-block;
font-family: 'Lato',sans-serif;
font-size: 1.5em;
}
.author {
float: right;
}
see the css and try to understand where u made mistake actually your parent div were not floated that's why your child div are not in control....
apply this css i guess through this you will achieve your desired results...
I have following fiddle: http://jsfiddle.net/BFSH4/
As you see there are two issues:
The h1 and h2 aren't vertically aligned.
The nav and the content aren't horzontal alligned.
For the 1. I already tried margin and padding. No success...
The second one also isn't that easy the common ways of floating and using inline-block don't work...
What am I doing wrong?
I finally managed floating the header. The problem was that hgroup isn't a block element.
However even it worked after all I think it is better to use a real image for the enterprise name and slogan.
Now only the issue with the horizontal alignment fails.
I don't know why:
http://jsfiddle.net/BFSH4/2/
I can do what I want there is no way that they wan't to be side by side!
Solution for your first problem (found here):
HTML
<div class="header">
<span></span><img src="images/prototype.png" /><hgroup><h1>Prototype</h1><h2>SideBySide</h2></hgroup>
</div>
CSS
.header {
height: 160px;
border: 1px solid #8a2be2;
/* text-align: center; */
}
.header span {
height: 100%;
vertical-align: middle;
display: inline-block;
}
.header img {
display: inline-block;
height: 160px;
float: left; /* added, so the image will appear left to the text correctly */
}
.header hgroup {
margin: 0;
vertical-align: middle;
display: inline-block;
}
This solution depends on display: inline-block
Solution for the second problem:
.nav {
width: 229px;
display: block;
margin: 0 auto;
}
Live demo: http://jsfiddle.net/BFSH4/4/