HTML div with a background - html

I'm making a website (Although I know nothing about HTML & Photoshop).
Its quite a challenge for me and I'm pretty happy with what I got so far.
Now I want to make boxes / floating squares on the site.
So I wanted to do this by using a the div but I have no clue how :#
<div id="div1" style="background-image: url(../bg_content_middle.png);height: 129px">
HELLO IS THIS A BOX?
</div>
I have this in my style.css:
#div1 {Background: url("bg_content_middle.png");}
bg_content_middle.png is a 1 pixel high "bar" which I want between top and bottom.
And thats not even working :(
Please help me.

You're mixing in-line CSS with external CSS rules. The inline style with ../bg_content_middle.png is overriding the other background image url of bg_content_middle.png. You only need to define it once.
In this case you could go for a pure CSS solution:
<div id="div1">HELLO I AM A BOX ^_^</div>
#div1 {
background-color: #900;
border: #f33 1px solid;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
}
Please don't number your divs though, call them something relevant like <div id="content">.
Hope that helps

1) Make the B in background lower-case
2) Is the image in the same directory as style.css? If not, you'll have to link to the correct directory.

well, if all you want your div to have a backround, you can have something as simple as this example from this tutorial:
<body>
<div style="background: green">
<h5 >SEARCH LINKS</h5>
<a target="_blank" href="http://www.google.com">Google</a>
</div>
</body>

First of all, you only need to define this particular style once, but inline styles (styles within the tag's <style> attribute.) take precedence. You should remove the inline style in this case, since it's redundant and double check your image paths just in case. Remember that css paths can be document relative, in which case they refer to the location of the css file, and are not relative to the HTML page.
If it's one pixel high you might want to set the repeat property as well. put this in the element's CSS:
background-repeat: repeat-y;
And set a width equivalent to the image width.

You need to set the position : absolute in your css. From there you can use top, left and height to position and size your tags

Related

HTML Background Auto-Resizing

I am attempting to set an image as the background and have it auto-resize and auto-center when the window changes size. Right now I have the auto-resize and auto-center working perfect, but I have no clue how to make it my background image. I had to replace all opening and closing symbols with the PLUS (+) symbol. My current code is as follows:
<div style="text-align: center;">
<img src="amazing.jpg" style="max-width: 100%; height: auto;" alt="Epoxy Flooring of NY" />
</div>
Any suggestions to make it the background instead of just a picture taking up the whole screen? I need the words on top of it, not under it.
Welcome to the stackoverflow-community :)
Just use the background-image-property instead of an <img>-tag.
<div style="background-image:url('amazing.jpg')">
<!-- your text here -->
</div>
For more information See here and here.
Note:
If you use background-image instead of <img> you will not see anything unless you give the <div> a height, by either filling it with text or/and setting it's height of, for example, 100px.
There is two ways to do it one using the css background img property and the other using the HTML img tag.
https://jsfiddle.net/pdhgLap8/
Basically what you need to add to use background images is
background-image: url("https://i.imgur.com/SebQr4d.jpg");
background-size: contain;
background-repeat: no-repeat;
This will set the background image
make it so it is only as large as the div it is in
and make it so it doesn't repeat to fill the div

How to change the Text on the image?

Below is the image, where I have text on the image. I am wondering on how the text on the Image can be changed. Actually someone else wrote the code and I am not getting. Please Help me out Friends.
And this is the code which is working on this.
<div class="TabsV">
<div id="Tab0" class="TabV Selected" style="height: 86px;">
<a style="background-position: -8px -12px; padding-bottom: 70px;" href="javascript: SelectTab(0)"></a>
</div>
<div id="Tab1" class="TabV" style="height: 116px;">
<a style="background-position: -40px 0px; padding-bottom: 100px;" href="javascript: SelectTab(1)"></a>
</div>
<div class="TabVEmpty" style="height: 50px;"></div>
</div>
It looks like the text is part of the image.
So you need to edit the actual images and change the text there.
If you look at the stylesheet used in that page you will find something similar to
.TabV a{
/*in here you will see the url of the image being used
background:...
or background-image: url('..');
*/
}
It looks like the image itself contains text and it is applied via the TabV class - notice how the background-position coordinates changes between one tab and the other.
If you look in your CSS file, you should see something like:
.TabV
{
background-image: url(...)
}
What you need to do, therefore, is to manipulate the existing image used as background and add the text you want to that image. Then you need to modify the background-position of the corresponding anchor element. One way to do that with jQuery is:
$('#Tab0').attr("background-position","-16px 20px;"); //-16px and 20px are just an example
Where #Tab0 is the css selector for the first tab. #Tab1 would be the css selector for the second tab... "#<something>" maps to id="<something>" in the html markup.
The technique itself is called CSS sprites. You can read more about this technique here.
You can not! You must edit those image files in an image editor. The text from the tabs isn't coded in the html code.

Issue lining bottom shadow up with banner image

I am trying to line this bottom shadow up as in the top shadow but I cannot seem to get the firgured out. The only time it collapses is when I remove the line-height or font-size much further down in the css file using Developer Toolbars but of course this affects everything else too. Here's my basic html structure:
<div class="banner-image">
<div class="banner-image-wrapper">
<div class="shadow-top"></div>
<a class="header-image">
<img />
</a>
<div class="shadow-bottom"></div>
</div>
</div>
On the tag, if I remove the font-size and line-height, everything collapses nicely on itself but I cannot seem to force this just on the tag.
I know this is going to be a ridiculous issue once it's been solved.
Thanks!
The answer is actually pretty simple, you just need to use some clever positioning & take advantage of the parent's box-model:
.banner-image{
position:relative;
}
.shadow-bottom{
position:absolute;
height: x;
bottom: -x;
}
Here's the formula you need:
Take the height of the bottom shadow ( some value x )
Then make sure the parent of that element has a position of 'relative' (~important~)
Make the position of the bottom shadow 'absolute'
Position it at the bottom minus the value of it's height ( -x )
Here's a jsFiddle illustrating the effect: http://jsfiddle.net/k7CmJ/
I know this is old, but for anybody else looking for an answer to this, where absolute positioning won't work, setting display:block on the img tag will get rid of that space:
.header-image > img {
display:block;
}
Normally an image is an inline block, and because it's inline, white-space around it is preserved.
Here is the problem: http://jsfiddle.net/3Kd3f/
And here is the exact same code, only with display:block added to the img tag: http://jsfiddle.net/3Kd3f/1/

Why doesn't padding-bottom in div tag work?

I have a <div> and I want to put the text 10px from bottom border of the `. However, it doesn't work for me. Following is the code.
<div id="title" style="height:35px;border-bottom:thin solid rgb(65,31,30);margin-left:14px;padding-bottom:10px;font-size:18px;font-weight:thicker">Hello, world!
</div>
remove your height:35px style. that contradicts what you are trying to do. it has a 35px height plus an additional 10px bottom padding.
check out this jsFiddle. i hope it makes sense to you.
I have experiences with this sort of stuff in the past. This is just the case in some browsers and especially if you had overflow-y: scroll; enabled in the style. Your syntax looks good and I have tried it. even with or without that semi-colon at the end, it would still work fine since you are styling it inside the div as an attribute itself.
The way I see it if this is not your entire code please be aware of overflow: scroll; it code be overwriting your style.
or try running it with other browsers.
or you could restructure your code to make sure the padding works like this:
<div id="title" style="height:35px;margin-left:14px;font-size:18px;font-weight:thicker">Hello, world!<div style="border-bottom:thin solid rgb(65,31,30);padding:10px"> </div>
</div>:
by just adding another div within that div

Containing a text in an oval shaped area

I have a html page which looks like the following:
I want to display some text on the left pane, but the problem is that the text should be inside the oval shaped area only. How do I achieve this? Note that the oval shaped image is the background image, however if required, I can also use a <img> tag for it if it would help. One lame way is to use <p> tags with padding, but that is not an efficient way, so kindly suggest some good methods.
EDIT: HTML:
<div id="leftStage" class="rounded-corners">
<div id="questionDisp" align="center">
</div>
</div>
CSS:
#leftStage {
position: relative;
width: 34%;
height:86%;
float: left;
}
#questionDisp {
display:none;
}
JS: (When the appropriate function is called: )
$("#questionDisp").fadeIn(1000);
$("#questionDisp").html(quesArr.q1); //data read from xml
EDIT: What I need is a div or something above the oval background, & the text should fit in it. I am getting the text from an xml file, so it is not that I have a fixed text size to be displayed
There's actually a pure CSS/XHTML code generator on csstextwrap that does exactly what you want.
EDIT:
The concept here is to float <div>'s on either side of your text so that your content is forced to "flow" in between them. By setting the width of your floated <div>'s, you can create a wide variety of cascading "stencils."
See concept illustrated here: fiddle
If it is background-image then use the position:absolute with proper margins (top and left), and set the width less than that the oval background-image. Then display property 'block'.
Maybe you could try the jQuery plugin Text Fill
also see: https://stackoverflow.com/a/688362/753676
I removed my answer since only the left float worked.
If you paste this code: it'll show you exactly how it works. I did a border-radius instead of creating a circle png.
<div style="width:250px;height:230px; border-radius:125px;background:#efefef;padding-top:20px; text-align:center">
The code for my<br /> fix isn't pretty but it should<br />work It's not automatic, but it<br /> does the job that you need it<br /> to do.
</div>
You have not shared any HTML, The working code is with some assumption
The HTML is,
<div id="main">
<div class="text">This is text</div>
</div>​
Where div with classtext is the text container.
The CSS for same will be,
#main{
background-image:url('http://i.stack.imgur.com/bw2HK.png');
height:563px;
width:691px;
}
#main .text{
color:#FF0000;
width:240px;
text-align:center;
top:100px;
border:1px solid;
float:left;
position:absolute;
}
​Here .text is the class that represent the text styling. The main part is position:absolute;. This will set the text div position to absolute. Now you can move the div above image div using top and left styles.
Please do review working example here
P.S. The border, color and other styles can be changed as per your need.