Place logo and text in the same line - html

I am trying to create the header part of my page. In the header, I want to have an image (a logo) on the left side, and a "logged in as ..." on the right side of the same line.
The problem that I have is that the logo simply overrides the "logged in as" text, so only logo stays visible on the page, and there is no text.
Here is the code:
<div class="header">
<span class="myLogo"/>
<span class="user">
Logged in as " target="_blank">${user}</a>
</span>
</div>
CSS:
.myLogo {
display: inline;
float: left;
margin-left: 10px;
margin-top: 30px;
content:url("myLogo.png");
}
.user {
text-align: right;
white-space: nowrap;
display: inline;
float: left;
margin-top: 20px;
margin-right: 30px;
font-size: large;
}
.header {
display: inline-block;
}
How can I have my logo on the left side of the page, and my text on the right side of the page, but in the same line?

I think you should set
display: inline-block;
for both class or change class user to
float: right

Use this CSS.
.myLogo {
display: inline;
float: left;
margin-left: 10px;
margin-top: 30px;
content:url("myLogo.png");
}
.user {
white-space: nowrap;
display: inline;
float: right;
margin-top: 20px;
margin-right: 30px;
font-size: large;
}
.header {
display: inline-block;
width: 100%;clear:both;
}

Why do you use content instead of an <img> tag?
Anyway, what I could suggest for you is to use flexbox:
.header{
display: flex;
align-items: baseline;
}
.user{
margin-left: auto;
}

You can try this method
HTML:
<div>
<img class="myLogo" src = "myLogo.png"/>
</div>
<div class="user">
Logged in as <a target="_blank">${user}</a>
</div>
CSS:
.myLogo {
display: inline;
float: left;
margin-left: 10px;
margin-top: 30px;
height: 10px;
width: auto;
}
.user {
text-align: right;
white-space: nowrap;
display: inline;
float: left;
margin-top: 20px;
margin-right: 30px;
font-size: large;
}
.header {
display: inline-block;
}

You have to make 2 changes
remove inline block for .header class
Change float:right under .user class
.myLogo {
display: inline;
float: left;
margin-left: 10px;
content:url("https://1.bp.blogspot.com/-NknV6HIVxKc/V06_WraBJEI/AAAAAAAAJWc/QwJMGxKHaywCIf2QHOLD-YwFQdn8VDaVgCLcB/s320/chelsea-logo.PNG");
width:50px;
height:50px;
}
.user {
text-align: right;
white-space: nowrap;
display: inline;
float: right;
margin-right: 30px;
font-size: large;
}
<div class="header">
<span class="myLogo"></span>
<span class="user">
Logged in as <a target="_blank">hai</a>
</span>
</div>

Related

Icon and padding

bob i {font-size: 10px} shows a neat horizontal block, and the name titles are aligned. When I increase the font-size for bob i to 30px, then the two spans are not neatly horizontally aligned anymore. The icon is not that big so why does it make the bob span block blow up? Is it possible to have bob i {font-size: 40px} and keep everything neatly horizontally aligned?
.joe span
{
display: block;
padding: 20px;
text-align: left;
}
.pete
{
width: 30%;
float: left;
background-color: green;
}
.bob
{
width: 10%;
float: left;
background-color: blue;
}
.bob i {
font-size: 30px;
padding-left: 10%;
}
<div class="wrapper"><div class="joe"><span class="pete">Pete</span>
<span class="bob">Bob<i class="icon">#</i></span>
</div></div>
Just change these class property
.joe span {
display: flex;
align-items: center;
padding: 20px;
}
.bob i {
font-size: 40px;
padding-left: 10%;
line-height: 0;
}
.joe span {
display: flex;
align-items: center;
padding: 20px;
}
.pete
{
width: 30%;
float: left;
background-color: green;
}
.bob
{
width: 10%;
float: left;
background-color: blue;
}
.bob i {
font-size: 40px;
padding-left: 10%;
line-height: 0;
}
<div class="wrapper"><div class="joe"><span class="pete">Pete</span>
<span class="bob">Bob<i class="icon">#</i></span>
</div></div>

How this div align the middle?

I have this sample:
link
I want to align second div to be middle of first div...I tried to do this with vertical-align:middle but not working.
It is because we put the container display: table?
CODE HTML:
<div class="container-logo">
<div class="logo">LOGO</div>
<div class="profile-name">NAME</div>
</div>
CODE CSS:
.container-logo {
display: table;
margin: 0 auto;}
.logo{
clear: none;
float: left;
height: 57px;
width: auto;
background:red;
}
.profile-name{
float: left;
width: auto;
color: blue;
/* line-height: 22px; */
font-size: 14pt;
background:aqua;
font-family: Montserrat regular;
}
What is the problem it does not work ... Can you give me some advice please?
Thanks in advance!
EDIT:
My items must be in line and have the same height ... I just want the second div to put it in the middle of the first ... exactly the same height
<div class="container-logo">
Replace the class name.
.container-logo {
display: table;
margin: 0 auto;
vertical-align: middle;
}
.logo{
clear: none;
/*float: left;*/
height: 57px;
width: auto;
background:red;
display: table-cell;
vertical-align: middle;
}
.profile-name{
/*float: left;*/
width: auto;
/* line-height: 22px; */
font-family: Montserrat regular;
display: table-cell;
vertical-align: middle;
}
.profile-name p{
font-size: 14pt;
background:aqua;
color: blue;
padding:2px;
}
<div class="container-logo">
<div class="logo">LOGO</div>
<div class="profile-name">
<p>NAME</p>
</div>
</div>
try to remove float:left from the classes .logo and .profile-name with display:table-cell will help you fixing this.. like the below
CSS
.logo{
clear: none;
display:table-cell;
vertical-align:middle;
height: 57px;
width: auto;
background:red;
}
.profile-name{
display:table-cell;
vertical-align:middle;
width: auto;
color: blue;
/* line-height: 22px; */
font-size: 14pt;
background:aqua;
font-family: Montserrat regular;
}
Fiddle Demo
Use table-cell for inner divs and remove floats:
.container-logo {
display: table;
margin: 0 auto;
}
.logo{
clear: none;
/* float: left; */
height: 57px;
width: auto;
background:red;
}
.profile-name{
/* float: left; */
width: auto;
color: blue;
/* line-height: 22px; */
font-size: 14pt;
background:aqua;
font-family: Montserrat regular;
}
.container-logo > div{
display: table-cell;
vertical-align: middle;
}
<div class="container-logo">
<div class="logo">LOGO</div>
<div class="profile-name">NAME</div>
</div>
Or inline-block if you want to get like this fiddle.
If you want your second div inside first one then write your html like this
<div class="container-logo">
<div class="logo">LOGO
<div class="profile-name">NAME</div>
</div>
</div>
and in your css do something like this
.container-logo {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
max-width: 50%;
padding: 15px;
}
.logo{
clear: none;
float: left;
height: 57px;
width: auto;
background:red;
}
https://jsfiddle.net/hq8q8eqg/7/

text-align not working with vertical-align

I have 6 divs that each contain a <p> and a link, and I want them to both be centered, with the <p> at the top and the link at the bottom. This is my html (it's basically the same for all 6):
<div id="home">
<p>P</p>
<a class="nav" href="index.html">home</a>
</div>
(all 6 are wrapped in a <header>)
This is my css:
header div {
width: 133.33px;
height: 145px;
text-align: center;
font-size: 18px;
padding-bottom: 3px;
font-weight: lighter;
float: left;
display: table;
}
header div a {
text-decoration: none;
color: #474747;
vertical-align: bottom;
text-align: center;
display: table-cell;
}
header div p {
font-size: 60px;
padding: 0;
text-align: center;
vertical-align: top;
display: table-cell;
}
I can't get the text-align: center to work at the same time as the vertical-align. Is there anyway to get the top/bottom positioning without using vertical-align, or to get the text-align to work?
Here's the code you're looking for, I hope: (These are not the droids you're looking for)
.wrapper {
text-align: center;
height: 200px;
width: 200px;
border: 1px solid black;
display: table;
}
.container {
display: table-cell;
vertical-align: bottom;
}
<div class="wrapper">
<div class="container">
<p>Hello World!</p>
I am a Link!
</div>
</div>
following Alohci's comment, if you'd like the <p> tags at the top and <a> tags at the bottom you should use the position property as follows:
.wrapper {
position: relative;
text-align: center;
height: 200px;
max-height: 200px;
width: 200px;
max-width: 200px;
border: 1px solid black;
display: table;
}
.container p {
display: inline;
vertical-align: top;
}
.container a {
position: absolute;
bottom: 0;
left: 0;
right: 0;
}
<div class="wrapper">
<div class="container">
<p>Hello World!</p>
I am a Link!
</div>
</div>
Use Following CSS,
You Can Get a <p> and a link both be at centered,
div {
width: 133.33px;
height: 145px;
text-align: center;
font-size: 18px;
padding-bottom: 3px;
font-weight: lighter;
float: left;
display: table;
}
div a {
text-decoration: none;
color: #474747;
vertical-align: middle;
display: table-cell;
}
div p {
font-size: 60px;
padding: 0;
text-align: center;
}
Here is the Jsfiddle solution link.
http://jsfiddle.net/rbdqtxyf/

CSS 3 Column Layout Collapses Under Large Screen Width

I have the following section of code for by CSS 3-Column Layout. However under a very large screen width, the first column collapses (around 2000px). I added the code for the navigation, as the links could be impacting the display of the columns.
CSS and HTML
#container
{
width: 75%;
margin-left: auto;
margin-right: auto;
}
header h1
{
font-size: 40px;
float: left;
font-weight: 100;
}
header h1 a
{
text-decoration: none;
color: black;
}
header nav
{
float: right;
}
header nav ul
{
list-style-type: none;
margin: 0;
vertical-align: middle;
line-height: normal;
float: right;
z-index: 999;
position: relative; /* add this */
}
header nav ul li
{
line-height: 15px;
float: left;
padding: 45px;
font-size: 22px;
font-weight: 100;
text-align: center;
}
header nav ul li a
{
color: black;
text-decoration: none;
}
.content
{
margin-left: auto;
margin-right: auto;
width: 75%;
font-size: 20px;
line-height: 50px;
}
#media screen and (max-width: 1160px) {
header h1
{
float: none;
text-align: center;
font-size: 36px;
}
header nav
{
width: 100%;
margin-right: 20px;
}
header nav ul
{
float: none;
text-align: center;
}
header nav ul li
{
width: 100%;
box-sizing: border-box;
text-align: center;
padding: 25px;
}
}
.col {
float: left;
}
.col-1-3 {
width: 33%
}
.col-1-3 a {
font-weight: bold;
}
<div id="container">
<header>
<h1><strong>Henry</strong><span id="notbold">+Applications</span></h1>
<nav>
<ul>
<li id="me"><div id="meanimation">Home</div></li>
<li id="project"><div id="projectanimation">Project</div></li>
<li id="contact"><div id="contactanimation">Contact</div></li>
</ul>
</nav>
</header>
</div>
<br><br><br><br>
<div class="content">
<div class="col col-1-3"><p><em>Email</em></p><p>This is the quickest way to contact me!</p>
The Fastest Way
</div>
<div class="col col-1-3"><p><em>Phone</em></p><p>You can get in touch with me with a phone call or text!</p>
Text Me
</div>
<div class="col col-1-3"><p><em>Public Profile</em></p><p>Right now, I only have a Google+ profile, but I am sure to expand soon.</p>
Google+<br>
StackOverflow
</div>
</div>
I added overflow: hidden; to .content and I got the good result.
.content {
margin-left: auto;
margin-right: auto;
width: 75%;
font-size: 20px;
line-height: 50px;
overflow: hidden;
}

Set one span fixed width and other rest width

I'm creating a match list using ul and li tags. However i want to set some spans to a fixed width and then apply rest of the spans to the equal rest width. In my example there are 3 spans with a width 10px. I want the first team and second team classes to fill the rest of the width how can i do this using percentages?
.match-list {
padding: 0;
list-style-type: none;
}
.list-item {
list-style: none;
margin-bottom: 9px;
}
.list-item .image-col {
width: 50px;
float: left;
}
.list-item .empty-col {
width: 50px;
text-align: right;
float: left;
}
.list-item .time-col {
width: 50px;
text-align: center;
float: left;
}
.list-item .first-team {
text-align: right;
float: left;
}
.list-item .second-team {
float: left;
text-align: left;
}
<div>
<ul class="match-list">
<li class="list-item">
<span class="image-col">img</span>
<span class="first-team">First team</span>
<span class="time-col">12:00</span>
<span class="second-team">Second team</span>
<span class="empty-col">empty</span>
</li>
</ul>
</div>
You could use flexbox
CSS
.list-item {
list-style: none;
margin-bottom: 9px;
display:flex;
direction:row;
}
.list-item .first-team {
order:1;
flex-grow:2;
text-align: right;
float: left;
background:#d7d7d7;
text-align:center;
}
.list-item .second-team {
order:2;
flex-grow:2;
float: left;
text-align: left;
background:#a7a7a7;
text-align:center;
}
Check it on Codepen
If you can remove those float properties, you could use some table tricks on your layout, like this:
.match-list {
padding: 0;
list-style-type: none;
}
.list-item {
list-style: none;
margin-bottom: 9px;
}
/*added stuff*/
.list-item {
display: table;
width: 100%;
}
.list-item > span {
display: table-cell;
}
.list-item .image-col {
width: 50px;
}
.list-item .empty-col {
width: 50px;
text-align: right;
}
.list-item .time-col {
width: 50px;
text-align: center;
}
.list-item .first-team {
text-align: center;
}
.list-item .second-team {
text-align: center;
}
<div>
<ul class="match-list">
<li class="list-item">
<span class="image-col">img</span>
<span class="first-team">First team</span>
<span class="time-col">12:00</span>
<span class="second-team">Second team</span>
<span class="empty-col">empty</span>
</li>
</ul>
</div>
you can do this with css calc():
.list-item .first-team {
width: calc(50% - 150px);
text-align: right;
float: left;
}
.list-item .second-team {
width: calc(50% - 150px);
float: left;
text-align: left;
}
example: http://jsfiddle.net/qqu2448n/