CSS logo changes its position when text length increases - html

This is my code which is working fine but when i change my headline2text to "Sale Price $25 . This is a sample text. $244" then auto logo image changes its position. I do not want logo to change its position but it should remain on its place and should not be affected by the headline2Txt. How to fix this issue?
<div id="wrapper">
<div id="mainContainer">
<p class="copyrights" id="copyrights"></p>
<div>
<img id="Image_Car" src="http://i.share.pho.to/25a090ef_c.png" />
</div>
<div id="headlineText">
<p id="headline1Txt" >Sample bag1</p>
<p id="headline2Txt" >Sale Price $25 </p>
</div>
<div id="disclaimer" >
Details*
</div>
<div id="Image_logo">
<img id="Imglogo" src="http://i.share.pho.to/93578bd4_o.png" />
</div>
<div >
<button class="btn btn-primary" type="button" id="ctaBtn"><div id="fadeIn" > Learn More Now </div></button>
</div>
</div>
#Image_logo img
{
position:relative;
width:140px;
height:30px;
top:-3px;
left:390px;
}
</div>

I may not understand what you're asking, but I think the lack of a float is throwing you. Adding some css like this..
<style>
#Image_logo img {
width:140px;
height:30px;
}
#wrapper {
float:left;
}
</style>
...should work. It should be in a separate .css file of course.

You have position: relative; on #Image_logo img yet you try to position it the "absolute way". Try to change your CSS like this:
#Image_logo img {
position:absolute;
width:140px;
height:30px;
top:40px;
left:390px;
}

Try giving your #Image_logo img position: absolute instead of relative, then modify top, left etc. Then it should be always in the same place;

Related

How can I prevent Division tags in HTML to disort

this is my first question and I hope I would get some help here.
I have made this HTML page that has 5 DIV's mainly:
Header
Content
Footer
Content contains
Left
Right
The Left and Right Div's float on Left and right respectively.When I put something content div with an H1 tag the div's get somewhat disorted and I get a approx. 10px space between the header and content section, somewhat like this:
Disorted
However the original one should be:
Original
<body>
<a target="_blank"><div id="main" >
<div id="header" >
<a style="color:#000000" href="home.html">Home</a>
<a style="color:#000000" href="about.html">about</a>
<a style="color:#000000" href="Our customers.html">Our Customers</a>
<a style="color:#000000" href="Career.html">Careers</a>
<a style="color:#000000" href="Contact us.html">Contact us</a>
</div>
<div id="content">
<div id="left" ></div>
<div id="right" ></div>
Home
</div>
<div id="footer">
<a style="color:#FFFFFF" href="home.html">Privacy Policy</a>|
<a style="color:#FFFFFF" href="Feedback.html">Feedback</a>|
<a style="color:#FFFFFF" href="disclaimer.html">Disclaimer</a>|
<a style="color:#FFFFFF" href="Manadatory.html">Manadatory Disclosure</a>|
<a style="color:#FFFFFF" href="sitemap.html">Site Map</a>|
</div>
</div></body>
Here is my CSS Code:
#main
{
height:900px;
background-color:#000000;
}
#header
{
height:100px;
background-color:#00FF00;
padding:70px;
padding-right:70px;
font-size:30px;
text-align:center;
background-image:url(Images/text3.jpg);
padding: 50px;
}
#content
{
height:700px;
background-color:#FFFFFF;
}
#left
{
float:left;
height:700px;
background-color:#FF0000;
width:150px;
background-image:url(Images/navbar2.jpg);
}
#right
{
float:right;
height:700px;
background-color:#FF0000;
width:150px;
background-image:url(Images/navbar2.jpg);
}
#footer
{
padding:50px;
padding-right:70px;
font-size:20px;
text-align:center;
height:100px;
background-image:url(Images/footer.jpg);
}
Fixing position of the div's using position hasn't helped. Thanks for any help in advance :)
Right click and inspect element on your browser and check the divs. You should see what's happening to it. Most likely it will be some default styling that's giving some margins. That's why most people use some kind of reset.css as a clean base. I imagine the default css is applying margins to the <p> and <h1> tags.
Maybe try adding something like:
h1 {
margin:0;
}
Obviously you could specify only certain margins rather than all or .content h1{} to just apply styling to the headers within the content block.

Height works in pixels, not in percentages

I am trying to create a simple menu using the following html setup:
<div class="container">
<div class="container-cell">
<a href="play.html">
<div class="menu-option no-margintop">
<div class="play-icon">
<span class="helper"></span><img src="./img/icon_1.png"/>
</div>
<div class="menu-text"><span>Play</span></div>
</div>
</a>
<a href="index.html">
<div class="menu-option">
<div class="play-icon">
<span class="helper"></span><img src="./img/icon_3.png"/>
</div>
<div class="menu-text"><span>Highscore</span></div>
</div>
</a>
<a href="index.html">
<div class="menu-option">
<div class="play-icon">
<span class="helper"></span><img src="./img/icon_2.png"/>
</div>
<div class="menu-text"><span>FAQ</span></div>
</div>
</a>
</div>
</div>
In the process of creating this, I made a switch from hard pixels to percentages. Whereas the pixel version of setting hights works, it does not seem to work in percentages. The hight for one particular class, menu-option, does not seem to get picked up by the browser.
I have been searching for a while, and the only solutions I came across, was setting a height to both the body and html (100%). I have also set a height to any of the container-elements.
See css below:
html, body{
height:100%;
}
.container {
display:table;
width:100%;
height:70%;
}
.container-cell {
display:table-cell;
vertical-align: middle;
height:100%;
}
.menu-option{
width:90%;
margin-left:5%;
border-radius:10px;
background-color:rgba(17,23,28,0.2);
height:6.94%;
margin-top:5%;
font-size:150%;
}
Why is the browser not picking up on the height in percentage and how can make it use the height in percentage?
Add display: inline-block; to your menu-option class for the height property to work. Something like this:
.menu-option{
display: inline-block;
width:90%;
margin-left:5%;
border-radius:10px;
background-color:rgba(17,23,28,0.2);
height:6.94%;
margin-top:5%;
font-size:150%;
}
Here's a jsfiddle of the above: https://jsfiddle.net/AndrewL32/e0d8my79/17/

How to place text over the image?

I want to place text over the image like the following picture shows :
HTML that I wrote is :
<body>
<div class="image_holder">
<img src="bg2.jpg" />
<div class="overlay"> </div>
</div>
<div>NHS SUB</div>
</body>
CSS :
.image_holder {
position:relative;
float:left;
}
.overlay {
position:absolute;
top:0;
background-color:rgba(34,70,118,0.7);
width:100%;
height:100%;
}
The text will automatically go after the image. What should I do to place the text over the image ?
Try this
<div class="image_holder">
<div class="overlay">NHS SUB</div>
</div>
Style
.image_holder{
background:url('img.jpg');
}
Another Way
<div class="image_holder">
<img src="img.jpg"/>
<div class="overlay">NHS SUB</div>
</div>
STYLE
.img_holder{
position:relative;
}
.img_holder img{
postion:absolute;
z-index:-1;
}
.overlay{
z-index:1;
}
Your div class's look like they should infact be ID's. ID's are unique where as class's are used across numerous elements.
Although your nested div approach will work when applying the correct styles, a more semantic (and less markup) would be using Ben's approach - code:
<div class="mydiv" style="background-image:url('bg2.jpg');">overlay text here</div>
<div>NHS SUB</div>

Position image + text together?

How would I go about placing my text at the center of an image, this is what it looks right now: http://gyazo.com/442aa9f927c1c1ee505435c2422f7322.png
and this is how I want it to be: http://gyazo.com/bc3bb2d0472a1c963d4ac00081065461.png
This is my current code:
<p><img src="http://findicons.com/files/icons/941/web_design/32/page_text.png" /> Some random text</p>
I would really appreciate if someone could help me out with this.
try to insert the image inside a div and put the text on it like this:
<div class="img">
<p>your text</p>
</div>
css:
.img{
background: url('http://findicons.com/files/icons/941/web_design/32/page_text.png') no-repeat;
height:100%;
}
DEMO
After you can mode your text where you want
If you don't want to use the image like a background and you want only to put text at the center of your element try this:
<div class="container">
<img src="http://findicons.com/files/icons/941/web_design/32/page_text.png" />
<span>your text</span>
<br style="clear:both;" />
</div>
css
.container{
width:100%;
height:100px;
}
.container span{
line-height:30px;
float:left;
}
.container img{
float:left;
}
DEMO2
Demo:
http://jsfiddle.net/5ser6/1/
<div class="thingy">
<img src="http://findicons.com/files/icons/941/web_design/32/page_text.png" alt="" />
<p>Text</p>
<br style="clear:both;">
</div>
* {font-family:arial}
.thingy img {float:left;}
.thingy {height:32px;float:left;}
.thingy p {float:left;margin:0 0 0 10px;padding:0;line-height:32px;}
If your framework has a clearfix, you don't need the clear:both, just put a clearfix on the outer div.

Image not aligning to center in a left aligned div

Below is my code :
<div id="footer">
<div id="left_footer">
<div id="img_left" align="center">
<img src="separator_bar.jpg" align="middle"/>
</div>
</div>
<div id="right_footer">
<div id="img_right" align="center">
<img src="separator_bar.jpg" align="middle"/>
</div>
</div>
</div
CSS:
#footer {
width:500px;
position:relative
}
#left_footer{
float:left;
}
#right_footer{
float:right;
}
I am trying this code but my image is not aligned to center its always aligned to left in left footer and to right in right footer. Please suggest !
I would approach the layout like this:
http://jsfiddle.net/yWmZ5/1/
HTML
<div id="footer">
<div id="left_footer">
<img src="http://placekitten.com/100/100" />
</div>
<div id="right_footer">
<img src="http://placekitten.com/100/100" />
</div>
</div>
CSS
#footer { width:500px; position:relative; overflow:hidden; }
#left_footer{ width:250px; float:left; text-align:center; background:orange; }
#right_footer{ width:250px; float:right; text-align:center; background:yellow; }
Make sure you strip all styling (eg - align, etc) out of your HTML and put it in your CSS.
Try this style:
#footer > div{width:50%}
your div#left_footer and div#right_footer need to have some width, in order to display the content in the middle
change your corresponding css to this:
#left_footer{
text-align:center;
float:left;
width:50%;
}
#right_footer{
float:right;
width:50%;
}
see this fiddle