Center block vertically if text inside it too loing - html

I'm backend coder and I'm very new in frontend development, but I have a free time now and I want to try learn basics of HTML / CSS :)
These images describe my question:
I have following. Simple info on the left side and title on the right side.
But if title is long my markup goes bad:
I want to achieve this (Paint):
In other words I want to increase height of the main (gray) block and center its content vertically if title too long.
Here is my code:
<div class="header"> <!-- Main (gray) block -->
<div class="author">
<div class="left">
<img src="http://cs421319.vk.me/v421319968/b0e1/ljfuXCyMOFI.jpg" width="50" height="50"/>
</div>
<div class="author_details">
<span class="name">_Dark_</span>
<br>
<span class="time">01.01.2014 — 23:59 </span>
</div>
</div>
<div class="title">
<h1>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse sollicitudin, est non tempus lacinia, urna. </h1>
</div>
</div>
And LESS:
.header {
min-height: 60px;
background-color: #EEE;
padding: 5px;
-moz-box-sizing: border-box;
box-sizing: border-box;
.title {
display: inline-block;
vertical-align: top;
}
h1 {
font-weight: normal;
font-size: 24px;
margin: 0;
}
.author {
max-width: 200px;
display: inline-block;
border-right: 1px solid #CCC;
}
.author_details {
margin: 0 0 0 55px;
padding: 0 5px 0 0;
.name {
font-size: 20px;
font-weight: bold;
}
.time {
font-size: 12px;
}
}
}
Sorry if I explained my problem bad, but I really doesn't know what to do and I want some advice about my (ugly maybe) code :)
Here is JSFiddle with current markup

Your code (HTML) is okay, but can be more simplified, with less elements:
<div class="infoBox">
<p>
<img src="http://cs421319.vk.me/v421319968/b0e1/ljfuXCyMOFI.jpg" />
_Dark_<br />
<span>01.01.2014 — 23:59 </span>
</p>
<h1>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse sollicitudin, est non tempus lacinia, urna. </h1>
</div>
With this CSS (added some comments to explain what some things do).
.infoBox {
min-height: 60px;
background: #eee;
padding: 5px;
-moz-box-sizing: border-box;
box-sizing: border-box;
display: table; /* display the box as table */
width: 100%;
}
.infoBox > p, /* selects all p that are direct child of .infoBox */
.infoBox > h1 {
display: table-cell; /* display the p and h1 as a table cell */
}
.infoBox > p {
width: 200px;
margin: 0;
padding: 0;
font-size: 20px;
font-weight: bold;
}
.infoBox > p img {
width: 50px;
height: 50px;
margin-right: 5px;
float: left;
}
.infoBox > p span {
font-size: 12px;
font-weight: normal;
}
.infoBox > h1 { /* select h1 that is a direct child of .infoBox */
font-size: 14px;
margin: 0;
padding: 0;
}
Also check this demo.

Your markup is way too intensive. Look here to make a simpler markup:http://jsfiddle.net/hdqvY/8/
Just keep in mind a few things. If you can group things together, it makes it easier to place items within the page. That small box of information is contained in one area while your text(paragraph) can be contained in another. Getting the boxes to line up is easy: just use display:inline-block; and float:left; to get them to line up. But keep in mind the width of the surrounding container along with the boxes inside so they match up.
HTML
<div class="container">
<div class="box">//Main (gray)block<br>
<img src="http://cs421319.vk.me/v421319968/b0e1/ljfuXCyMOFI.jpg" width="50" height="50"/><br>
_Dark_<br>
01.01.2014-23:59
</div>
<div class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse sollicitudin, est non tempus lacinia, urna.
</div>
</div>
CSS
.container{
width:800px;
height:100%;
display:inline-block;
}
.box{
width:140px;
height:300px;
display:inline-block;
float:left;
}
.text{
font-family:arial;
font-size:14px;
display:inline-block;
width:400px;
text-wrap:none;
float:left;
}

Related

How can I stack Columns when window is resized [duplicate]

This question already has answers here:
Flexbox responsive row column layout
(3 answers)
Converting desktop layout to single-column mobile layout
(1 answer)
Closed 1 year ago.
I am working on a website.
I have a container, that has two columns. On the left, I have a product image, that when you hover on it, it shows that product in use.
To the right, I have a title, description, tech drawings.
I want it so that when the screen is resized to a mobile format, or even if the browser is shrunk, the columns will stack on top of one another.
Right now the image just gets smaller and smaller until you cannot see it.
I tried several attempts at using FlexBox. Did not have any luck. Here was the guide/rules I was following: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Here is a quick JSfiddle I made up to see what I am talking about. This does not have any "attempt" code in it. Just the base code for the containing div, left and right columns, with some example images and text. https://jsfiddle.net/fmcdLxa4/1/
.container {
max-width: 1200px;
margin: 0 auto;
display: flex;
padding: 15px;
}
/* Columns */
.left-column {
float: left;
width: 50%;
padding: 10px;
position: relative;
border-bottom: 1px solid #E1E8EE;
}
.right-column {
float: left;
width: 50%;
padding: 10px;
}
/* Left Column */
.left-column img {
display: block;
margin-left: auto;
margin-right: auto;
vertical-align: auto;
}
/* Right Column */
/* Product Description */
.product-description {
border-bottom: 1px solid #E1E8EE;
}
.product-description span {
font-size: 12px;
color: #358ED7;
letter-spacing: 1px;
text-transform: uppercase;
text-decoration: none;
}
.product-description h1 {
font-weight: 300;
font-size: 52px;
color: #43484D;
letter-spacing: -2px;
}
.product-description p {
font-size: 16px;
font-weight: 300;
color: #86939E;
line-height: 24px;
}
.product-description a {
color: #358ED7;
}
.flip-box {
background-color: transparent;
width: 100%;
height: 100%;
perspective: 1000px;
}
.flip-box-inner {
position: relative;
width: 100%;
height: 100%;
text-align: center;
transition: transform 0.8s;
transform-style: preserve-3d;
}
.flip-box:hover .flip-box-inner {
transform: rotateY(180deg);
}
.flip-box-front,
.flip-box-back {
position: absolute;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.flip-box-front {
background-color: transparent;
}
.flip-box-back {
background-color: transparent;
transform: rotateY(180deg);
}
<div class="container">
<!-- Left Column -->
<div class="left-column">
<p> </p>
<div height="15"></div>
<div class="flip-box">
<div class="flip-box-inner">
<div class="flip-box-front">
<img src="https://dogtowndogtraining.com/wp-content/uploads/2012/06/300x300-061-e1340955308953.jpg" style="max-width: 100%">
</div>
<div class="flip-box-back">
<img src="http://www.deepdiveintel.com/wp-content/uploads/2013/09/Owl-Eye-art-300x300.jpg" style="max-width: 100%">
</div>
</div>
</div>
</div>
<!-- Right Column -->
<div class="right-column">
<!-- Product Description -->
<div class="product-description">
<span>Lorem ipsum dolor sit amet</span>
<h1>Lorem ipsum dolo</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi arcu sem, bibendum id tellus ac, aliquam faucibus massa. Nulla facilisi. Fusce vel condimentum velit. Praesent nec ultricies erat. Sed ante lectus, ultrices ut laoreet id, tincidunt
a augue.</p>
<p>Technical drawings: 7/0 | 8/0
<p />
</div>
</div>
</div>
Any help would be awesome!
flex can wrap if you set it so. Also, one of your card's image needs to remain in the flow, so it can size its container. then flex:1 1 XX% will do the job.
https://codepen.io/gc-nomade/pen/MWpxYZw
.container {
max-width: 1200px;
margin: 0 auto;
display: flex;
flex-wrap:wrap;
padding: 15px;
}
/* Columns */
.left-column {
flex:1 1 40%;
padding: 10px;
position: relative;
border-bottom: 1px solid #E1E8EE;
min-width:320px;
}
.right-column {
flex:1 1 40%;
padding: 10px;
}
/* Left Column */
.left-column img {
display: block;
margin-left: auto;
margin-right: auto;
vertical-align: auto;
}
/* Right Column */
/* Product Description */
.product-description {
border-bottom: 1px solid #E1E8EE;
}
.product-description span {
font-size: 12px;
color: #358ED7;
letter-spacing: 1px;
text-transform: uppercase;
text-decoration: none;
}
.product-description h1 {
font-weight: 300;
font-size: 52px;
color: #43484D;
letter-spacing: -2px;
}
.product-description p {
font-size: 16px;
font-weight: 300;
color: #86939E;
line-height: 24px;
}
.product-description a {
color: #358ED7;
}
.flip-box {
background-color: transparent;
width: 100%;
height: 100%;
perspective: 1000px;
}
.flip-box-inner {
position: relative;
width: 100%;
height: 100%;
text-align: center;
transition: transform 0.8s;
transform-style: preserve-3d;
}
.flip-box:hover .flip-box-inner {
transform: rotateY(180deg);
}
.flip-box-back{
position: absolute;
top:0;
}
.flip-box-front,
.flip-box-back {
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.flip-box-front {
background-color: transparent;
}
.flip-box-back {
background-color: transparent;
transform: rotateY(180deg);
}
<div class="container">
<!-- Left Column -->
<div class="left-column">
<p> </p>
<div height="15"></div>
<div class="flip-box">
<div class="flip-box-inner">
<div class="flip-box-front">
<img src="https://picsum.photos/id/1003/300/300" style="max-width: 100%">
</div>
<div class="flip-box-back">
<img src="https://picsum.photos/id/10/300/300" style="max-width: 100%">
</div>
</div>
</div>
</div>
<!-- Right Column -->
<div class="right-column">
<!-- Product Description -->
<div class="product-description">
<span>Lorem ipsum dolor sit amet</span>
<h1>Lorem ipsum dolo</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi arcu sem, bibendum id tellus ac, aliquam faucibus massa. Nulla facilisi. Fusce vel condimentum velit. Praesent nec ultricies erat. Sed ante lectus, ultrices ut laoreet id, tincidunt
a augue.</p>
<p>Technical drawings: 7/0 | 8/0
<p />
</div>
</div>
</div>

Why is my div image not appearing inside parent div?

I am making an author box. I want the person's picture at the right of the box while still inside the parent div. Whatever styles I apply, I can't make the picture appear inside the div and on the right smoothly, what is wrong here?
.authorBox {
background: #222222;
width: 100%;
padding:1.5em 2em;
position: relative;
border-left:15px solid #d53362;
box-sizing: border-box;
}
h5.author {
color: #fff;
font-weight: 600;
font-size: 1.5em;
}
h5.authorRole {
color: #d53362;
font-weight: 600;
font-size: 1.3em;
}
p.authorQuote {
color:#444;
font-style: italic;
margin-top: 20px;
font-size: 1.1em;
line-height: 1.5em;
}
.personImg1 {
width:100%;
height:100%;
background-size: cover;
background-image: url(../img/person1.jpeg);
}
.personContainer {
float:right;
}
<div class="authorBox">
<h5 class="author">First Last</h5>
<h5 class="authorRole">Job role goes here</h5>
<p class="authorQuote">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut eu erat at nisl laoreet ultrices"</p>
<div class="personContainer">
<div class="personImg1"></div>
</div>
</div>
First of all a div with no height and width won't be seen, so you div with the background has to have a defined width/height so you can see it.
and you put in the right by positioning it absolute and right:0 or a small amount just to push it from the edge.
*,
*:after,
*:before {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.authorBox {
background: #222222;
width: 100%;
padding: 1.5em 2em;
position: relative;
border-left: 15px solid #d53362;
box-sizing: border-box;
}
h5.author {
color: #fff;
font-weight: 600;
font-size: 1.5em;
}
h5.authorRole {
color: #d53362;
font-weight: 600;
font-size: 1.3em;
}
p.authorQuote {
color: #444;
font-style: italic;
margin-top: 20px;
font-size: 1.1em;
line-height: 1.5em;
}
.personContainer {
height: 100px;
width: 300px;
position: absolute;
right: 10px;
top: 1.5em;
}
.personImg1 {
width: 100%;
height: 100%;
background-size: 100% 100%;
background-image: url('http://via.placeholder.com/350x150');
}
<div class="authorBox">
<h5 class="author">First Last</h5>
<h5 class="authorRole">Job role goes here</h5>
<p class="authorQuote">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut eu erat at nisl laoreet ultrices"
</p>
<div class="personContainer">
<div class="personImg1"></div>
</div>
</div>
Your .personImg1 has width:100%; and height:100%;, which means it gets the full width and height of its parent container - i.e. relative settings.
But the parent container's only CSS property is .personContainer { float:right; } – there are no width or height settings for it, resulting in zero height both for this container, the .personImg1 DIV and therefore also the background-image of .personImg1. So you need to assign some width and height to .personContainer
Actually you might want to consider to just use a regular img tag instead of that .personImg1 DIV and its background-image...
Are you locating your image properly from your folders?
Also, you can try this
.personImg1 {
display:block;
position:absolute;
background:url("../img/person1.jpeg");
background-size: 100% 100%;
background-repeat:no-repeat;
width:100%;
height:100%;
float:right;
bottom:0;
right:0;
}
Try this solution using flex box.
.authorBox {
background: #222222;
width: 100%;
padding: 1.5em 2em;
position: relative;
border-left: 15px solid #d53362;
box-sizing: border-box;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
h5.author {
color: #fff;
font-weight: 600;
font-size: 1.5em;
}
h5.authorRole {
color: #d53362;
font-weight: 600;
font-size: 1.3em;
}
p.authorQuote {
color: #444;
font-style: italic;
margin-top: 20px;
font-size: 1.1em;
line-height: 1.5em;
}
.personImg1 {
width: 100px;
height: 100px;
background-size: cover;
background-image: url(../img/person1.jpeg);
}
<div class="authorBox">
<div class="colContainer">
<h5 class="author">First Last</h5>
<h5 class="authorRole">Job role goes here</h5>
<p class="authorQuote">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut eu erat
at nisl laoreet ultrices"</p>
</div>
<div class="personContainer">
<div class="personImg1"></div>
</div>
</div>

Floating divs inside inline-block parent goes down on resize

I have 2 floating divs, inner-left and inner-right inside parent container inner-container.
inner-container is set to display: inline-block; to have it's width to be equal of width of it's children.
The problem is, when I resize the window, inner-right div goes down and only then starts to resize itself.
How do I inner-right make it stay on the same line with inner-left, and, in the event of window resize, to resize instead of going down?
HTML:
<div class="container">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
<div class="inner-container">
<div class="inner-left"><img src="http://placehold.it/100x100" alt=""></div>
<div class="inner-right"><strong>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In justo orci, rutrum nec feugiat sed, ultrices non dolor. Aliquam laoreet.</strong><br>
Vivamus purus metus.
</div>
</div>
</div>
CSS:
.container {
background-color: #f0fff0;
padding: 10px;
border: 1px solid #bce2c1;
border-radius: 5px;
}
.inner-container {
padding: 10px;
background-color: #ffffff;
border: 1px solid #bce2c1;
border-radius: 5px;
margin-top: 10px;
display: inline-block;
}
.inner-left {
float:left;
width: 60px;
}
.inner-left img {
height: 60px;
width: 60px;
}
.inner-right {
float:right;
text-align: left;
padding-left: 10px;
}
JSFIDDLE:
https://jsfiddle.net/acidonyx/naw6ojwe/4/
well just remove float: right from .inner-right and your problem will be solved.
.inner-right {
text-align: left;
padding-left: 10px;
}
to solve your other problem you can do
.inner-right {
overflow: hidden;
text-align: left;
padding-left: 10px;
}
For this you should use flexbox, here with inline-flex to fit your requirement
.container {
display: inline-block;
background-color: #f0fff0;
padding: 10px;
border: 1px solid #bce2c1;
border-radius: 5px;
}
.inner-container {
display: inline-flex;
padding: 10px;
background-color: #ffffff;
border: 1px solid #bce2c1;
border-radius: 5px;
margin-top: 10px;
}
.inner-left img {
height: 60px;
width: 60px;
}
.inner-right {
padding-left: 10px;
}
<div class="container">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
<div class="wrap-container">
<div class="inner-container">
<div class="inner-left">
<img src="http://placehold.it/100x100" alt="">
</div>
<div class="inner-right"><strong>Lorem ipsum dolor sit</strong>
<br>Vivamus purus metus.
</div>
</div>
</div>
</div>
You could try floating .inner-right to the left instead, and giving it a width set in a percentage value, like this:
.inner-right {
float:left;
width: 85%;
}
JSFIDDLE
You can use media queries to update the percentage as you need.

HTML/CSS: two divs inside a container div

So this again links to the same website as my other question and is another positioning problem that is possibly simple.
I have a container div that I want to hold two divs inside it, one taking up a 3rd of the container on the right to contain pictures and one to contain text on the left. For some reason however, when telling both inner divs to float left the container seems to disappear and when using inspect element, is in a weird place that I cannot explain.
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Toby King - Home</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="script.js"></script>
<link rel="stylesheet" type="text/css" href="theme.css">
</head>
<body>
<div id="banner">
<div class="menu">
<div class="menuBit">
<h2 class="menuContent">HOME</h2>
</div>
<div class="menuBit">
<h2 class="menuContent">BLOG</h2>
</div>
<div class="menuBit">
<h2 class="menuContent">WORK</h2>
</div>
</div>
</div>
<div class="main">
<div class="textSection">
<div class="mainTextSection">
<h1 class="maintext">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent rhoncus erat nec porttitor facilisis. In hac habitasse platea dictumst. Mauris id faucibus arcu. Mauris non orci mauris. Vivamus a porta odio. Praesent at purus ante. Quisque magna odio, elementum ut facilisis vitae, consequat at tellus. Praesent nulla est, ultrices sit amet sagittis eget, consequat id justo. Integer elementum in nibh eu ultricies. Integer fringilla urna in mollis accumsan. Etiam iaculis urna et malesuada tincidunt. Nunc dignissim purus eu tempor bibendum.</h1>
</div>
<div class="mainPictureSection">
<img src="images/Example.svg">
</div>
</div>
</div>
<div id="footer">
<h2 class="social">CONTACT:</h2>
<img src="images/fb.png" class="social">
<h2 class="social">some text</h2>
<img src="images/insta.png" class="social">
<h2 class="social">some text</h2>
</div>
</body>
</html>
CSS:
#banner {
height: 50px;
width: 100%;
margin: 0px;
padding: 0px;
overflow: hidden;
position: fixed;
background-image: url("images/menuHor.png");
}
.menuBit {
height: 40px;
width: 100px;
margin: 0px;
padding: 0px;
float: left;
margin-left: 10px;
}
.menuContent:hover {
text-decoration: underline;
cursor: pointer;
}
.menuContent {
font-family: "cicle-gordita";
font-size: 30px;
text-align: center;
padding: 0px;
margin: 0px;
margin-top: 10px;
color: #ffffff;
}
.main {
position: fixed;
margin: 0px;
margin-top:50px;
padding: 0px;
width: 100%;
height: 94.7916666667%;
overflow: scroll;
background: url("images/backgr.png");
}
.maintext {
font-family: "cicle-gordita";
}
.textSection {
width: 65%;
height: auto;
background: #FFFFFF;
margin-right: 17.5%;
margin-left: 17.5%;
margin-top: 2.5%;
margin-bottom: 5%;
border-radius: 10px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
}
.mainPictureSection {
height: auto;
width: 21.67%;
float: left;
overflow: hidden;
margin: 0px;
padding: 0px;
}
.mainTextSection {
height:auto;
width: 43.33%;
float: left;
margin: 0px;
padding: 0px;
}
#footer {
width: 100%;
height: 30px;
clear: both;
position: fixed;
bottom: 0;
background-image: url("images/menuHor.png");
}
.social {
float: left;
padding: 0;
margin-top: 0px;
margin-bottom: 2.5px;
margin-left: 10px;
font-family: "cicle-gordita";
color: #ffffff;
}
.social h2 {
margin-top: 5px;
}
The Jscript/jQuery file is just to fade bits in and out but contributes no effect to positioning
Change float: left to display: inline-block should be the best way to do this.
display: inline-block adds white-space. One way to remove this is adding comments between your divs:
<div class="container">
<div class="child">
</div><!--
--><div class="child">
</div>
</div>
or have the divs inline like this:
<div class="container">
<div class="child"></div><div class="child"></div>
</div>
To align them at the top add vertical-align: top to the child divs.
Where has the parent element gone?
If a container has only floating children, its height will collapse as floating elements are not considered when calculating height of a container. You need to clear those floating elements to make the container actually contain the floating children.
One way to do this is by adding a clearfix and putting the class on the container element (taken from http://nicolasgallagher.com/micro-clearfix-hack/):
/**
* For modern browsers
* 1. The space content is one way to avoid an Opera bug when the
* contenteditable attribute is included anywhere else in the document.
* Otherwise it causes space to appear at the top and bottom of elements
* that are clearfixed.
* 2. The use of `table` rather than `block` is only necessary if using
* `:before` to contain the top-margins of child elements.
*/
.clearfix:before,
.clearfix:after {
content: " "; /* 1 */
display: table; /* 2 */
}
.clearfix:after {
clear: both;
}
/**
* For IE 6/7 only
* Include this rule to trigger hasLayout and contain floats.
*/
.clearfix {
*zoom: 1;
}
That's kind of ugly. Any other solution?
There is an (more than one) alternative, though, the most common probably being using display: inline-block instead of float: left.
Unfortunately, looking at the following example you'll see it does not work as expected initially:
.container {
background-color: #a00;
}
.child {
background-color: #f0f0f0;
display: inline-block;
width: 50%;
}
<div class="container">
<div class="child">Child One</div>
<div class="child">Child Two</div>
</div>
You see that the second container wraps to a new line even though both have been defined to have their fair share of 50% of the container's width.
Why does this happen?
As soon as your HTML contains any sort of whitespace between inline-block elements, it's going to get rendered and consume space.
So how can I fix that?
The most common way to avoid that is to set the container's font-size: 0; (which is not always the go-to-solution, but in most cases), and re-setting it ony the children as needed:
.container {
background-color: #a00;
font-size: 0;
}
.child {
background-color: #f0f0f0;
display: inline-block;
font-size: 16px;
width: 50%;
}
<div class="container">
<div class="child">Child One</div>
<div class="child">Child Two</div>
</div>

How can I make some divs align on a nav?

This is my first post on stack overflow, so if I do something wrong please inform me :).
This is the HTML:
<nav>
<div><img src="images/logo.png"</div>
<div>Noticias</div>
<div>Eventos</div>
<div>Alumnos</div>
<div>Contacto</div>
</nav>
<div id="content">
<h3><span class="green">Noticias |</span> Los comunicados y anuncios <span class="green">oficales</span> de la institución</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec magna pulvinar, posuere lacus nec, suscipit risus. Nunc vitae sollicitudin nisl.</p>
And the CSS:
#import url(http://fonts.googleapis.com/css?family=Comfortaa); *{border:1px dotted black;}
html {
background-color: #FFFFFF;
min-height: 2000px;
}
body {
color: #1F4F75;
font-family: Comfortaa, sans-serif;
}
nav {
height: 10%;
width:100%;
position: fixed;
box-shadow: 0px 10px 10px #888888;
background-color: #FFFFFF;
display: block;
}
nav div {
display: block;
float:right;
height: 100%;
font-size: 25px;
}
nav:first-child {
float:left;
}
#content {
width: 70%;
margin: auto;
margin-top: 7%;
}
.green {
color:#91BA30;
}
h3 {
font-size: 25px;
text-align: center;
font-weight: 700;
}
p {
line-height: 1.4;
font-size: 17px;
text-align: justify;
color: #1F4F75;
font-weight: 400;
}
This is the fiddle http://jsfiddle.net/LuTLm/ .
My nav has 5 elements: an image and four links. I'm trying to make the apear aligned on the navigation bar, with every element floating to the right, exept the first one (the image) wich floats left and should be resized to fit on the 10% nav.
This shoul be pretty basic. I'm just starting to code web. Alternatives are also welcome as long as they are a actual better solutions.
Sorry, I missed the bit about floating the img left..
clean up the html to close off the IMG tag with /> and then either add a class or inline css to float the div containing the img to the left..
<div style='float:left'><img src="images/logo.png" /></div>
or
<div class='FloatLeft'><img src="images/logo.png" /></div>
.FloatLeft
{
float: left;
}
or
change the css like this
nav div:first-child {
float:left;
}
Just update yuor css from
nav:first-child {
float:left;
}
to
nav div:first-child {
float:left; // make it float left
width: 10%; // resize it to 10% width
}
DEMO
You can also use CSS tables to do navigation bars. I've found they have a lot of nice properties, such as filling up the full width with evenly spaced navigation items, and are well supported in all modern browsers. They even work well with all sorts of semantic markup, including links of lists.
Given the HTML:
<body>
<nav>
<div>
<img src="images/logo.png">
</div>
<div>Noticias</div>
<div>Eventos</div>
<div>Alumnos</div>
<div>Contacto</div>
</nav>
<div id="content">
<h3><span class="green">Noticias |</span> Los comunicados y anuncios <span class="green">oficales</span> de la institución</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec magna pulvinar, posuere lacus nec, suscipit risus. Nunc vitae sollicitudin nisl.</p>
You would use the following CSS:
#import url(http://fonts.googleapis.com/css?family=Comfortaa);
html {
background-color: #FFFFFF;
min-height: 2000px;
}
body {
color: #1F4F75;
font-family: Comfortaa, sans-serif;
}
nav {
height: 10%;
width:100%;
position: fixed;
top: 0;
left: 0;
box-shadow: 0px 10px 10px #888888;
background-color: #FFFFFF;
display: table;
table-layout: auto;
}
nav div {
display: table-cell;
font-size: 25px;
vertical-align: middle;
}
nav div:first-child {
width: 10%;
}
#content {
width: 70%;
margin: auto;
margin-top: 7%;
}
.green {
color:#91BA30;
}
h3 {
font-size: 25px;
text-align: center;
font-weight: 700;
}
p {
line-height: 1.4;
font-size: 17px;
text-align: justify;
color: #1F4F75;
font-weight: 400;
}
DEMO