This question have been asked a lot on the web. But each try don't suceed
For a Website I need to make a header, I'm using django + boilerplate (I think that's boilerplate should be the cause, as copy paste of my code in js fiddle works, while it doesn't on local).
Here is the HTML I use:
<div id="topbar">
<div id="networking">
<div id="title">
EasyMusik
</div>
<div id="logo">
<img src="{% static "img/icons/myzik.svg" %}" />
</div>
</div>
</div>
And here is the CSS:
#topbar{
display:block;
background-color : #29A329;
position: relative;
float: top;
}
#tobbar div{
height: 100%;
display:inline-block;
}
#networking{
padding-left:25%;
}
#networking div{
display:inline-block;
}
#title{
position: relative;
height:100%;
font-size: 24px;
}
#logo img{
width:100%;
display:block;
float:left;
}
#logo{
position: relative;
height: 100%;
padding-left:15px;
background-color : #FF0000;
}
And I got this result
I want the Red area to fullfill the green one. Wich property should i add/remove to achieve that?
EDIT: Finally managed to get a fiddle:
Fiddle here
This did the worked for me. Though its not your CSS.
CSS:
.parent
{
width:100%;
background-color:Green;
height:50px;
text-align:center;
font-size:24px;
}
.sub
{
width:50px;
background-color:Red;
height:50px;
display: inline-block;
}
.img
{
vertical-align:middle;
padding-top:15px;
}
HTML:
<div class="parent">
Easy Muzik
<div class="sub">
<img alt="" class="img" src="style/img.png" />
</div>
</div>
Give #topbar a height. If you want your child container to be 100% height or width, your parent container has to have a height or width specified. Good luck!
#topbar{
display:block;
background-color : #29A329;
position: relative;
float: top;
height: 200px
}
Related
Please I have an image as a link to another page and I have a menu of 2 text options (using ul&li) When I use only my image, it works, but when I try to put everything together, my image doesn't link, only the menu works. My code run in Chrome and Explorer, I can't see where the problem is. Someone please help me.
Thanks!
Here my html code:
<body>
<div id="container">
<div id="header">
<div id="home">
<img id="flores" src="images/flores.jpg" alt="home" />
</div>
<div id="connexion">
<section id="formulario">
<p id="titulo">Mi cuenta</p>
<form action="" method="get">
...
</form>
</section>
</div>
<div id="contenido">
<div id="contenido_menu">
<ul>
<li>Rosa</li>
<li>Jasmin </li>
</ul>
</div>
</div>
</div>
</div>
</body>
My css code:
#container{
position: relative;
margin:auto;
margin-top:150px;
width:1024px;
height:768px;
background-color: grey;
}
#header{
margin:auto;
margin-top:0px;
width:1024px;
height: 150px;
}
#home{
position:absolute;
width:624px;
height:150px;
}
#flores {
margin-top:0px;
width:100%;
height:100%;
}
#contenido{
position:absolute;
margin: auto;
width:1024px;
height:438px;
background-color: pink;
}
#contenido_menu{
position: absolute;
margin-top:5px;
background-image: url("img/rosas.jpg");
background-size: 100% 100%;
width:619px;
height:95px;
line-height:95px;
float:left;
}
#contenido_menu ul{
margin: 0 auto;
}
#contenido_menu li{
display:inline;
padding-top: 50%;
padding-bottom: 5px;
}
#contenido_menu a:link, #contenido_menu a:visited{
font-family: Arial;
font-size:19px;
font-weight:bold;
color:#1a53ff;
height:40px;
padding:30px 50px;
text-decoration:none;
}
Only thing I can imagin is that some div or the menu is over the picture. Try to check it with an tag inspector from your debugging tools.
Check your code properly.
In the html you have given the location of flores.jpg as "images/flores.jpg".
While for the other image rosas.jpg, in your css you typed the location as "img/rosas.jpg".
Check whether both images are in their respective folders, or you might have typed one of them wrong.
The problem comes from the below declaration. Remove padding-top:50%. I hope by mistake you put % instead px.
#contenido_menu li{
display:inline;
padding-top: 50px;
padding-bottom: 5px;
}
Also remove position:absolute from #home class.
#home{
/*position:absolute;*/
width:624px;
height:150px;
}
DEMO
You positioned the home and the menu div absolute, if I remove absolute it works fine:
http://jsfiddle.net/2m8rmvuh/
Edit: Linked to an old fiddle, now its the correct one ;)
#home{
width:624px;
height:150px;
}
#contenido{
margin: auto;
width:1024px;
height:438px;
background-color: pink;
}
#contenido_menu{
margin-top:5px;
background-image: url("img/rosas.jpg");
background-size: 100% 100%;
width:619px;
height:95px;
line-height:95px;
float:left;
}
I dont know if thats the look you want, but if you give them the attribute absolute, they are overlapping, if you use a large picture.
The image shows what I want to accomplish:
Here is the code that I have:
http://jsfiddle.net/ZNtKj/202/
<div style="width: 200px" >
<div class="niveles-porcentaje">
<div class="alta" style="width: 40%"> <span class="porcentaje">40%</span></div>
</div>
And the style I am having trouble to fix:
div.niveles-porcentaje {
width:100%;
height:100%;
align-self:center;
text-align:center;
display:inline-table;
background-color:#D7D7D7;
}
div.alta {
display:inline-table; /*inside a table*/
line-height: 2em;
background-color: #06AC09;
height:100%;
float:left;
}
span.porcentaje{
text-align:center;
vertical-align:middle;
z-index:99;
}
The div will be inside a td.
You will have to make the text's parent full width. To do that, remove the back color and width definition from the .alta div, and create an inner absolute div to deal with the color fill, that won't interfeer with the text.
Also, remember to set the text span to display: block to be full width. Check here: http://jsfiddle.net/ZNtKj/209/
<div style="width: 200px" >
<div class="niveles-porcentaje">
<div class="alta">
<div class="fill" style="width: 40%"></div>
<span class="porcentaje">40%</span>
</div>
</div>
</div>
CSS:
div.niveles-porcentaje {
width:100%;
height:100%;
align-self:center;
text-align:center;
display:inline-table;
background-color:#D7D7D7;
}
div.alta {
display:inline-table; /*inside a table*/
line-height: 2em;
height:100%;
width: 100%;
position: relative;
}
div.alta .fill {
background-color: #06AC09;
height:100%;
position: absolute;
}
span.porcentaje{
text-align:center;
vertical-align:middle;
z-index:99;
position: relative;
display: block;
}
Here is the Fiddle with example. You can simply change the text div width to see the result.
div.niveles-porcentaje {
width:100%;
height:20px;
align-self:center;
text-align:center;
background-color:#D7D7D7;
position:relative;
}
div.alta {
line-height: 2em;
background-color: #06AC09;
height:20px;
float:left;
position:relative;
}
span.porcentaje{
position:absolute;
left:46%;
top:0;
}
____________________________________________________________
| logo_icon page_Tittle |
------------------------------------------------------------
I want to make a header of my phonegap app like this one. On the left of the header there should be a logo(img) and on center there should be page tittle(text). Now I have already try this one.
<div data-role="header" >
<div class="logo" > <img src="img/logo.png" /> </div>
<h1 id="tittle">Main Page</h1>
Exit
</div>
and the css its css is:
.logo {
vertical-align: left;
}
.tittle{
text-align: center;
display: inline-block;
vertical-align: middle;
}
Kindly help me how it will be work? I am new in css.
<div data-role="header" class="header" >
<div class="logo" > <img src="img/logo.png" /> </div>
<h1 id="tittle">Main Page</h1>
Exit
</div>
the css:
.header{display:inline-block;
padding:5px 15px;
text-align:center;
width:100%;
}
.logo{float:left;}
.header h1 {font-size:15px;
width:80%;
text-align:center;}
basically, by adding the text align property of the header div as center, and setting the float property of the logo element to left, should solve your problem
check out the js fiddle link :)
http://jsfiddle.net/Q2Hkj/
This should work for you:
.logo {
float:left;
}
.tittle{
text-align: center;
width:75%; margin:0 auto;
vertical-align: middle;
}
I recommend you to do that with max number of % size and position in your css and use a JavaScript function for center the elements depending of the window size.
Anyway I created a fiddle example for you, take a look and some ideas.
HTML:
<div id="top_bar">
<img id="logo_top_bar" src="../img/logo_top_bar.png">
<section id="title">App title</section>
</div>
CSS:
html,body{
position: relative;
padding: 0px;
margin: 0px;
width: 100%;
max-width: 100%;
height: 100%;
max-width: 100%;
overflow:hidden;
}
#top_bar{
position:relative;
float:left;
height: 60px;
width:100%;
left:0;
top:0;
overflow:hidden;
background-color:rgb(46, 42, 42);
}
#logo_top_bar{
position:absolute;
height:30px;
width:70px;
left:4%;
top:15px;
}
#title{
position:absolute;
left:45%;
top:16px;
font-size: 1.5em;
color:white;
}
I would like to create a page on my website where there are 5 inline images which are automatically resized with the browser so they would be in the same position but just resized when viewed on any screen size.
Currently i have it working in such a way that there are 5 images all inline with each other and they do squeeze and keep their aspect ratio when i change the browsers size, but my question is how do i make this line of 5 images be central on the page at all times without them changing their position to go below eachother?
I have tried to add margin:0 auto; to both my container which is #images and to my img {} but neither seem to work,
Here is my current CSS;
#images {
margin-top:400px;
}
img {
width:18%;
padding-left:2px;
position:relative;
}
Here is HTML;
<div id="images">
<img src="images/imagepage/200x2001.jpg">
<img src="images/imagepage/200x2001.jpg">
<img src="images/imagepage/200x2001.jpg">
<img src="images/imagepage/200x2001.jpg">
<img src="images/imagepage/200x2001.jpg">
</div>
Thanks for any help
To help you understand more here is a JSfiddle showing what i currently have, all i would like is the row of images to be centered at all times, http://jsfiddle.net/c26NJ/
See this FIDDLE
#images {
margin-top:400px;
width:100%;
text-align:center;
}
img {
width:18%;
padding-left:2px;
position:relative;
box-sizing:border-box;
}
Set either width or height css property in % and set the other one as auto, for example
.imageGallery
{
width:20%;
height:auto;
display:inline; // or try float:left
}
This might work (assuming the #images is inside a full-width section):
#images {
max-width: 100%;
width: 400px;
margin: 400px auto;
}
img {
width:18%;
padding-left:2px;
}
HTML:
<div id="images">
<img src="images/imagepage/200x2001.jpg" class="first">
<img src="images/imagepage/200x2001.jpg">
<img src="images/imagepage/200x2001.jpg">
<img src="images/imagepage/200x2001.jpg">
<img src="images/imagepage/200x2001.jpg">
</div>
and
CSS:
#images {
width: 100%;
}
#images img {
width: 19.6%;
float: left;
display: block;
margin-left: 0.5%;
}
#images img.first {
margin-left: 0;
}
Check this fiddle
In the above fiddle the images will remain in the same line no matter to how much extent the user resizes the window.
CSS
html,body{
width:100%;
height:100%;
margin:0px auto;
padding:0px;
text-align:center;
}
#images {
display:inline-block;
width:100%;
}
img {
width:18%;
padding-left:2px;
position:relative;
display:table-cell;
}
I've tried numerous of things to fix this. I cannot seem to get the nested div inside the parent div without having to use margin. I'm trying to get it in the regular way which is position:relative on parent and position:absolute on nested. It's not working though, anybody know why?
HTML
<div class="header">
<div class="logo">
<img src="/images/logo.png" width="96" height="82">
</div>
<div id="nav">
Portfolio
About
Contact
</div>
<div id="headerPro">
</div>
</div>
CSS
.header {
position:relative;
background-color: #2C2E31;
border-bottom: #242426 2px solid;
height: 182px;
}
.logo {
text-align: center;
padding-top: 35px;
}
#nav {
position:absolute;
bottom: 0;
width: 100%;
text-align:center;
text-decoration:none;
font-size:20px;
font-family:raleway-regular;
}
#nav a {
border-bottom:#FFFFFF 2px solid;
color:#FFFFFF;
text-decoration:none;
margin-left: 8px;
margin-right:8px;
}
#headerPro {
position:absolute;
float:right;
width:100px;
height:100px;
background-color:red;
}
It's hard to tell what exactly you want it to look like, but maybe I got you right:
I revised your HTML code to use ul for the nav which is best practice:
<div class="header">
<div class="logo">
<img src="/images/logo.png" alt="logo"/>
</div>
<ul id="nav">
<li>Portfolio</li>
<li>About</li>
<li>Contact</li>
</ul>
<div id="headerPro">
</div>
</div>
With that your css code could look like that:
.logo > img {
display: inline-block;
width: 96px;
height: 82px;
}
#nav {
position:absolute;
list-style-type: none;
bottom: 0;
width: 100%;
text-align:center;
text-decoration:none;
font-size:20px;
font-family:raleway-regular;
}
#nav > li {
display: inline;
}
#headerPro {
position:absolute;
top: 35px; /* assuming you want this to line up with the logo */
right: 0;
width:100px;
height:100px;
background-color:red;
}
Here is a demo.
See this fiddle
Example
I have made two changes added a float:left to the logo css:
.logo {
float:left;
}
and removed the position:absolute from the header pro css
Your div is flowing outside the header block because of the logo div, if you make that float left (as I have done in the fiddle) the Red Div will move up.
It would help if you could explain exactly where you want the #HeaderPro div..
Apparently the browser positions your div#headerPro just below the previous(sibling) div. If you want it to be part of the parent div, add top:2% to position the red div in the top right corner of the black div.
#headerPro {
position:absolute;
float:right;
width:100px;
height:100px;
background-color:red;
top: 1%;
}