I am attempting to create a bucket in HTML and CSS by placing a header image on top of a bottom image. When i do this in dreamweaver, there is no gap between the two objects. However, when I upload it to a server, a gap develops between the two images. Any help or suggestions?
<div class="wrapBucketInnerLeft">
<div class="bucketLeft">
<h2 class="bucketHeader"><img src="images/bucket_header_text_basic.png" width="212" height="36" alt="Basic Plan" /></h2></td></tr>
<div class="bucketDetails">
<ul>
<li>Feature 1</li>
<li>Feature 2</li>
<li>Feature 3</li>
<li>Feature 4</li>
</ul>
<div class="bucketBottom">
<p class="cost">$1.95</p>
<img class="button" src="images/button_bucket.png" width="117" height="42" alt="Learn More" /></div>
</div>
</div>
<!--Bucket 2-->
<div class="bucketRight">
<h2 class="bucketHeader"><img src="images/bucket_header_text_economy.png" width="212" height="36" alt="Basic Plan" /></h2>
<div class="bucketDetails">
<ul>
<li>Feature 1</li>
<li>Feature 2</li>
<li>Feature 3</li>
<li>Feature 4</li>
</ul>
<div class="bucketBottom">
<p class="cost">$1.95</p>
<img class="button" src="images/button_bucket.png" width="117" height="42" alt="Learn More" /></div>
</div>
</div>
</div>
CSS:
.bucketHeader {
background-image:url(images/bg_header_bucket.png);
background-repeat:no-repeat;
background-position:top center;
height:46px;
margin:0px 0px 0px 0px;
padding:14px 0px 0px 18px;
}
.bucketDetails {
background-image:url(images/bg_bucket.png);
background-repeat:no-repeat;
background-position:top center;
height:278px;
margin:0px 0px 0px 0px;
padding:0px;
}
.bucketBottom p.cost {
font-size:28px;
font-weight:bold;
color:#335191;
margin:0px 0px 6px 0px;
padding:0px;
}
.bucketBottom{
text-align:center;
}
a img.button {
border:none;
}
well i know what is it! padding of .bucketHeader
.bucketHeader {
background-image:url(images/bg_header_bucket.png);
background-repeat:no-repeat;
background-position:top center;
height:46px; // here reduce the height of this div until the gap between them is removed, i think it should be 28px
margin:0px 0px 0px 0px;
padding:14px 0px 0px 18px; // here you see you have given padding of 14px of both top and bottom, this increases the height of div magically which you can't see because your image has background-repeat:no-repeat
}
Why are you using background-image? Do you see how the header and bottom images have like a pixel offset on the right side like this? Why don't you use div's with the images in them instead and don't put position:relative; top:0px to get the job done. You can put whatever text you want within a div with higher z-index ontop of the divs with the images and ofset top:-(whatever the height of the other div is)px or left:(whatever the width is)px?
Just a thought.
Cheers!
Related
I'm just playing around with a html webpage. Can any of you guys help me understand why my image is extending the container boundaries to the right?
https://codepen.io/Braindead16/pen/gRPZxe
click link for full code and to see what I mean about the image.
<div class="container">
<div class="jumbotron">
<h1 class="text-center"><em>Title</em></h1>
<div class="text-center image-box">
<img class="text-center img-responsive border"
src="https://www.sitebuilderreport.com/assets/facebook-stock-up-
446fff24fb11820517c520c4a5a4c032.jpg" alt="whatever">
<h2 class="image-text">this text decribes the image</h2>
</div>
I have tried applying a class to the image that has display: block; and margin: 0 auto;
I've also tried applying bootstrap columns to the image and its div, but nothing has made the image central.
By default img width and height are set to auto and using the true width/height of the image
Solution:
set the width to 100% (which is 100% of the parent width) will scale
the image to fit into the div container.
body {
margin-top: 30px;
}
.title-img {
width: 100%;
}
.image-text {
color: grey;
font-style: italic;
font-size: 20px;
}
.border {
border-style: solid;
border-color: grey;
border-width: 2px;
border-radius: 5px;
}
.image-box {
background-color: rgb(170, 170, 256);
padding: 10px;
border-radius: 10px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" />
<body>
<div class="container">
<div class="jumbotron">
<h1 class="text-center"><em>Title</em></h1>
<div class="text-center image-box">
<img class="text-center img-responsive border title-img" src="https://www.sitebuilderreport.com/assets/facebook-stock-up-446fff24fb11820517c520c4a5a4c032.jpg" alt="whatever">
<h2 class="image-text">this text decribes the image</h2>
</div>
<div class="row">
<div class="col-xs-12 col-sm-10 offset-sm-1 col-md-8 offset-md-2">
<h3>time-line or info</h3>
<ul>
<li>point 1</li>
<li>point 2</li>
<li>point 3</li>
<li>point 4</li>
<li>Depending on how much writing I have in these points effects how much I'd offset them. For points around this length this offset works.</li>
<div class="col-xs-12 col-sm-6 offset-sm-3 col-md-4 offset-md-4">
<li>Shorter Points</li>
<li>More central</li>
</ul>
</div>
<p>Wow, what a load of useless info. If you want more click here
</div>
</div>
</div>
</body>
<p class="text-center">dis page is coded by me</p>
I have (jsfiddle):
<body>
<div id="navbar">
<ul class="nav">
<li class="nav_left"><a class="nav" href="#">Home</a></li>
<li class="nav_left"><a class="nav" href="#">Support</a></li>
<li class="nav">
<form class="nav" method="post" action="action.php?do=search">
<input class="search_bar" type="text" name="search_input" />
</form>
</li>
<li class="nav_right"><a class="nav" href="#">Login</a></li>
<li class="nav_right"><a class="nav" href="#">Register</a></li>
</ul>
</div>
</body>
And I have:
html, body {height:100%;margin:0;padding:0;font-size:12px;}
body {background:#F1F1F1;}
#navbar {
width:100%;
padding:5px 0;
overflow:auto;
background:#34495e;
border-bottom:solid 1px #222;
text-align:center;
}
ul.nav {
margin:0;
padding:0;
list-style-type:none;
}
li.nav_left, li.nav_right, li.nav {padding:0 5px;}
li.nav_left {float:left;}
li.nav_right {float:right;}
li.nav {}
I would like to be able to align li.nav to the center without using text-align or margin as I have both float:left and float:right in use, so the float:right would be pushed out of line if they are used.
Hope you can help, thanks.
Use absolute positioning:
html, body {height:100%;margin:0;padding:0;font-size:12px;}
body {background:#F1F1F1;}
#navbar {
position:relative;
width:100%;
height:50px;
padding:5px 0;
overflow:auto;
background:#34495e;
border-bottom:solid 1px #222;
}
ul.nav {padding:0;list-style-type:none;}
li.nav_left, li.nav_right {padding:0 5px;}
li.nav_left {float:left;}
li.nav_right {float:right;}
li.nav {
background-color:green;
width:200px;
height:30px;
position:absolute;
margin:-15px 0 0 -100px;
top:50%;
left:50%;
text-align:center;
}
You need to rearrange your html code:
<body>
<div id="navbar">
<ul class="nav">
<li class="nav_left"><a class="nav" href="#">Home</a></li>
<li class="nav_left"><a class="nav" href="#">Support</a></li>
<li class="nav_right"><a class="nav" href="#">Login</a></li>
<li class="nav_right"><a class="nav" href="#">Register</a></li>
<li class="nav">
<form class="nav" method="post" action="action.php?do=search">
<input class="search_bar" type="text" name="search_input" />
</form>
</li>
</ul>
</div>
</body>
The above code is positioning the LEFT side of li.nav in the middle of #navbar. By using half of the width of li.nav as negative margin, the entire element is positioned in the exact center.
Just a quick example how it could work. You could also make container elements around nav_left and and nav_right and use position:absolute there as well. Inside the container element you can use float for the nav_left and nav_right elements.
http://jsfiddle.net/jCCL7/5/
In your CSS, it is a best to practice to use a "wrapper/container div".
Place all your div inside this wrapper div
.wrapper {
width: 500px;
margin: 0 auto;
}
So your HTML structure should look (not necessary exact) like this.
<body>
<div class="wrapper">
<div class="header">
<div class="content">
<p>"HelloWorld"</p>
</div>
</div>
</div>
</body>
The code above will display all your HTML content on the center of your page.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Fluid width with equally spaced DIVs
I am trying to put footer elements which are texts. I was trying to have equal distance between texts elements.
<nav>
<ul>
<li><a>Item Reg</a></li>
<li><a>Item Sm</a></li>
<li><a>Item Very Long</a></li>
<li><a>Item Reg</a></li>
</ul>
</nav>
Here is an image explaining the scenario I want to implement. Left and right elements are always aligned to left and right respectively.
How can I do it with css and html. NOTE: CSS3 is allowed.
One way would be to use percentage points for widths.
ul {
width: 100%;
}
ul li {
display: table-cell;
width: 25%;
text-align: center;
}
You ca use a padding-left for each <li> something like this:
li{
position:relative;
float:left;
padding-left:20px;}
Assuming you have a fixed number of elements simply use :
ul{
padding:0 20px 0 20px;
width:100%;
}
li{
display:inline;
float:left;
width:25%;
}
<ul>
<li>One</li>
<li>Two</li>
</ul>
You can achieve it in this way
<div class="footer">
<div style="width:200px; float:left;">
<ul style="list-style:none">
<li>1</li>
<li>2</li>
</ul>
</div>
<div style="width:200px; float:left;">
<ul style="list-style:none">
<li>1</li>
<li>2</li>
</ul>
</div>
<div style="width:200px; float:left;">
<ul style="list-style:none">
<li>1</li>
<li>2</li>
</ul>
</div>
<div style="clear:both"></div>
</div>
I have an area on my page #topLeft which has a minimum height set to it.
Within #topLeft I have a section #heroBanners that I wish to anchor to the bottom of #topLeft - using position:absolute; bottom:0;
At first this works fine, however when #topLeft should expand it is not and the heroBanner section simply overlaps the content above it.
I am assuming the problem is called by mixing a min-height with absolute positioned content?
Any ideas how to get round this, code below:
<div id="topLeft">
<div class="linksBox">
<ul>
<li>Item 1</li>
<li>Item2 </li>
<li>Item 3</li>
<li>Item4 </li>
</ul>
</div>
<div id="#heroBanners">
</div>
</div>
#topLeft {margin:0 27px 27px 0; width:478px; min-height:378px; *height:378px; *margin-bottom:22px; position:relative;}
#heroBanners {bottom:0; position:absolute;}
It would be quite easy if you put both blocks or divs in a new div and set its style to {bottom:0; position:absolute;} instead of heroBanners.
<div id="parent">
<div id="topLeft">
<div class="linksBox">
<ul>
<li>Item 1</li>
<li>Item2 </li>
<li>Item 3</li>
<li>Item4 </li>
</ul>
</div>
<div id="#heroBanners">
</div>
</div>
</div>
#topLeft {margin:0 27px 27px 0; width:478px; min-height:378px; *height:378px; *margin-bottom:22px; position:relative;}
#parent {bottom:0; position:absolute;}
I want to have my list (nav) align to the center of an image (logo). I tried using vertical-align: middle;, but I couldn't get it to work when I floated the images left and right.
Here's my code:
HTML:
<div id="head">
<img id="logo" src="logo.png" />
<ul id="nav">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div>
CSS:
#head {
margin-top: 2px;
width: 100%;
}
#logo {
float: left;
}
ul#nav {
float: right;
}
ul#nav li {
display: inline;
list-style-type: none;
}
I took all the vertical-align: middle;'s from where I put them (I tested it in each element, even though it was only supposed to be applied to #logo, from what I've read.)
Anyways, any help would be appreciated.
Vertical-align:middle aligns the median of child element to the median of parent element. If all child elements have float:left, then the parent has a height of 0px and hence its median is above the child elements.
So, you might add a <br style='clear:both' /> after your menu and the DIV will finally get its vertical size.
table with single row comes handy here.
<div id="head">
<table>
<tr>
<td>
<h1>Fluid Heading</h1>
</td>
<td style="width: 5%">
<img id="logo" src="logo.png" />
</td>
<td style="width: 5%">
<ul id="nav">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</td>
</tr>
</table>
</div>
CSS:
.head td { vertical-align: middle; }