The contents below the search bar are meant to be shown after the users enter some text. Currently the style is down to what I'm aiming for.
However when I display the search results, it pushes the container following the search bar, as illustrated by my picture:
What can I do that the search results display and just overlap everything below it without pushing other elements downwards?
Here is my HTML:
<div id="search-bar" class="box">
<h1 class="horizontal-header">SEARCH THE DATABASE</h1>
<div id="search-wrapper">
<input name="query" id="name" class="big-search" placeholder="champion, item, spells..." />
<div id="search-results">
<a href="#">
<div class="item">
<img src="http://images4.wikia.nocookie.net/__cb20091218194710/leagueoflegends/images/0/0f/JaxSquare.png" alt="" />
<div class="info">
<p class="name">Jax</p>
<p class="description">Champion</p>
</div>
</div>
</a>
<a href="#">
<div class="item">
<img src="http://images4.wikia.nocookie.net/__cb20091218194710/leagueoflegends/images/0/0f/JaxSquare.png" alt="" />
<div class="info">
<p class="name">Jax</p>
<p class="description">Champion</p>
</div>
</div>
</a>
<a href="#">
<div class="item">
<img src="http://images4.wikia.nocookie.net/__cb20091218194710/leagueoflegends/images/0/0f/JaxSquare.png" alt="" />
<div class="info">
<p class="name">Jax</p>
<p class="description">Champion</p>
</div>
</div>
</a>
</div>
</div>
</div>
And my CSS (written with LESS):
#search-bar {
width: 636px;
height: 35px;
#search-wrapper {
float:left;
margin-left: 13px;
#search-results {
z-index:999;
position:relative;
a {
display:block;
.item:hover {
background-color:#282828;
}
.item {
overflow: hidden;
background-color: #171717;
padding: 2px;
cursor:pointer;
margin-bottom:1px;
img {
float: left;
width: 35px;
}
.info {
float: left;
margin-left: 8px;
.name {
color: white;
margin: 0;
}
.description {
color: white;
margin: 0;
}
}
}
}
}
}
}
Use CSS's Absolute Positioning. Unlike Relative Positioning, Absolute Positioning removes the item from the flow of the document (ie keeping it from pushing other things down.)
Just remember, something that's absolutely positioned is positioned relative to it's nearest positioned parent - so whatever container the absolute positioned items are in (in your case) should be set to position:relative;
Info on all kinds of positioning: http://www.w3schools.com/css/css_positioning.asp
Give position:absolute to your .item DIV. Write like this:
.item {
position:absolute;
}
Related
I am trying to achieve facebook alike image cover as follow, but unable to achieve desire effect. This is the css that i have try. As you all can see, the div content does not position correctly.
.profile {
position: relative;
}
.profile-cover img{
width: 100%;
}
.profile-photo {
position: absolute;
left: 20px;
bottom: -60px;
}
.profile-info {
padding-right: 120px;
}
<div class="profile">
<div class="profile-cover">
<img src="http://dummyimage.com/1200x300/000/fff" />
</div>
<div class="profile-details">
<div class="profile-photo">
<img src="http://dummyimage.com/100x100/eee/000" />
</div>
<div class="profile-info">
Profile info here
</div>
</div>
</div>
<div>
Remaining content here
</div>
I am not exactly sure if you wanted this because you just say the "the div content does not position correctly", but I'm quiet sure it's that.
So, if not, tell me.
Using the absolute positioning gets out of the flow the element. So, the next ones continues as if this element didn't exist. That's why the others were showing under this absolute element.
For next time, please precise which DIV by using its id, a class name or anything that we can know for sure the one you are talking about.
.profile {
position: relative;
}
.profile-cover img{
width: 100%;
}
.profile-photo {
display: inline-block;
margin-top: -60px;
margin-left: 20px;
}
.profile-info {
display: inline-block;
padding-right: 120px;
}
<div class="profile">
<div class="profile-cover">
<img src="http://dummyimage.com/1200x300/000/fff" />
</div>
<div class="profile-details">
<div class="profile-photo">
<img src="http://dummyimage.com/100x100/eee/000" />
</div>
<div class="profile-info">
Profile info here
</div>
</div>
</div>
<div>
Remaining content here
</div>
This is how I would do it ...
.profile {
margin-bottom: 15px;
}
.profile-cover img {
width: 100%;
}
.profile-photo {
display: inline-block;
margin-left: 20px;
margin-top: -24px;
}
.profile-info {
display: inline-block;
position: relative;
top: -25px;
left: 10px;
}
<div class="profile">
<div class="profile-cover">
<img src="http://dummyimage.com/1200x300/000/fff" />
</div>
<div class="profile-details">
<div class="profile-photo">
<img src="http://dummyimage.com/100x100/eee/000" />
</div>
<div class="profile-info">
Profile info here<br>
More info here
</div>
</div>
</div>
<div>
Remaining content here
</div>
I have the following html code:
<div class="text-center">
<div class="row">
<div class="col-md-6">gdshdhfdhfdhfd</div>
<div class="col-md-6"><img src="http://image.com/img.png" alt="cat"></div>
</div>
<h4>header.</h4>
<p>hey there</p>
<div class="paddown">
<a class="btn btn-default" name="close" id="close" >Close</a>
</div>
</div>
And I would like to add any text (e.g. <span id="txt">lorem ipsum</span>)on the picture, let's say around 30-40px from the bottom, so it's visible in front of the cat's picture. Is it possible in bootstrap without using absolute positioning?
Here is my fiddle: http://jsfiddle.net/2wujw71x/3/
The general idea to this approach is to wrap the image in a containing element that will take on the size of the image itself. You also include the overlay element inside the wrapper element.
Apply position: relative; to the wrapper element and apply position: absolute; to the overlay element. The relative positioning on the wrapper element prevents the absolutely positioned element from being positioned outside of the wrapper element which happens to be the same size as our image. We now have a "viewport" for the overlay element that is the same size as the image and positioned over the image.
<div class="container">
<div class="row">
<div class="col-md-6">
<p>
Lorem Ipsum
</p>
</div>
<div class="col-md-6">
<span class="overlay-wrapper">
<img class="img-responsive" src="http://maxcdn.thedesigninspiration.com/wp-content/uploads/2012/01/Just-A-Cat-Playing-The-Violin-l.jpg" alt="Cat"/>
<div class="text-overlay">
Caption
</div>
</span>
</div>
</div>
</div>
.overlay-wrapper {
position: relative;
display: inline-block;
}
.text-overlay {
position: absolute;
width: 80%;
background: rgba( 0, 0, 0, .5 );
top: 75%;
left: 10%;
color: #fff;
text-align: center;
}
#media( min-width: 300px ) {
.text-overlay {
padding: 1em 0;
top: 65%;
}
}
#media( min-width: 550px ) {
.text-overlay {
padding: 2em 0;
}
}
http://jsfiddle.net/o2cjkyow/
I've included some media queries in my example so you can see a demonstration on how to adjust various properties at various viewport sizes for fine-tuning.
Here's my JSFiddle from the comments.
You can use the img-thumbnail class as a base with some minor adjustments, then set your text overlay rules in another class.
See working example in Snippet at Full Page.
html,
body {
margin-top: 50px;
}
.img-thumbnail.overlay {
position: relative;
border: none;
margin: 0;
padding: 0;
}
.img-thumbnail.overlay .caption {
position: absolute;
top: 45%;
left: 0;
margin: 0;
padding: 10px 15px 0 15px;
width: 100%;
color: #fff;
background: rgba(0, 0, 0, 0.3);
}
.img-thumbnail.overlay .caption2 {
position: absolute;
top: 45%;
left: 0;
margin: 0;
padding: 10px 15px 0 15px;
width: 100%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="container text-center">
<div class="row">
<div class="col-md-6">
<div class="img-thumbnail overlay">
<img src="http://maxcdn.thedesigninspiration.com/wp-content/uploads/2012/01/Just-A-Cat-Playing-The-Violin-l.jpg" alt="" class="img-responsive">
<div class="caption">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
</div>
</div>
</div>
<div class="col-md-6">
<div class="img-thumbnail overlay">
<img src="http://maxcdn.thedesigninspiration.com/wp-content/uploads/2012/01/Just-A-Cat-Playing-The-Violin-l.jpg" alt="" class="img-responsive">
<div class="caption2">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
</div>
</div>
</div>
</div>
</div>
I suggest using relative positioning instead of absolute, that way your position is always relative to the image and its container.
.my-floating-text{
position: relative;
top: 110px;
left: 0px;
}
And in your html:
<div class="text-center">
<div class="row">
<div class="col-md-6"><div class="my-floating-text">gdshdhfdhfdhfd</div><img src="http://maxcdn.thedesigninspiration.com/wp-content/uploads/2012/01/Just-A-Cat-Playing-The-Violin-l.jpg" alt="cat" />
</div>
</div>
<h4>header.</h4>
<p>hey there</p>
<div class="paddown">
<a class="btn btn-default" name="close" id="close" >Close</a>
</div>
</div>
http://jsfiddle.net/2wujw71x/5/
You can try with position:absolute;
HTML:
<div class="text-center">
<div class="row">
<div class="col-md-6 aclass">
<div class="auto">
gdshdhfdhfdhfd
</div>
</div>
<div class="col-md-6">
<img src="http://maxcdn.thedesigninspiration.com/wp-content/uploads/2012/01/Just-A-Cat-Playing-The-Violin-l.jpg" alt="cat"></div>
</div>
<h4>header.</h4>
<p>hey there</p>
<div class="paddown">
<a class="btn btn-default" name="close" id="close" >Close</a>
</div>
</div>
CSS:
.aclass {
position: absolute;
left: 50%;
}
.auto {
position:relative;
top:50px; /*position to top*/
left:-50%;
z-index:9999;
color:#fff;
}
DEMO
The text always is center! :)
Just want to post an alternative approach, with figure and figcaption. The two elements aren't neccessary, but they do make it nice and semantic. The solution itself still exists in CSS. Using padding and an absolute bottom allows the container to scale with multiple lines of text.
HTML
<figure>
<img src="http://maxcdn.thedesigninspiration.com/wp-content/uploads/2012/01/Just-A-Cat-Playing-The-Violin-l.jpg" alt="cat">
<figcaption>This is cat, playing violin</figcaption>
</figure>
CSS
figure {
position: relative;
display: inline-block;
}
figcaption {
background: rgba(255,255,255,0.3);
box-sizing: border-box;
bottom: 0;
font-weight: bold;
width: 100%;
padding: 10px;
position: absolute;
z-index: 10;
}
http://jsfiddle.net/2wujw71x/10/
Description of Problem:
I'm attempting to arrange the kittens in a star-like pattern with 3 DIV "rows." I would like for the first top row's kitten to be centered on the page (easy enough); the second (or '#middle') row to have their cats left-aligned and right-aligned, respectively; and the third ('#bottom') row to have its cats aligned similar to the second row, but slightly indented on both sides. Again, like a star.
I know the float property essentially makes the element(s) absolutely positioned, which collapses the bottom two rows' height, so that's probably not the right answer. But I've also tried text-align and futzing with margins. My brain is fried. What am I doing wrong?
Fiddle:
http://jsfiddle.net/k97CG/1/
HTML Structure:
<div id="top">
<div id="container1" class="containers">
<div id="cat1">
<img src="http://placekitten.com/g/125/125" />
</div>
</div>
</div>
<div id="middle">
<div id="container2" class="containers">
<div id="cat2">
<img src="http://placekitten.com/g/125/125" />
</div>
</div>
<div id="container3" class="containers">
<div id="cat3">
<img src="http://placekitten.com/g/125/125" />
</div>
</div>
</div>
<div id="bottom">
<div id="container4" class="containers">
<div id="cat4">
<img src="http://placekitten.com/g/125/125" />
</div>
</div>
<div id="container5" class="containers">
<div id="cat5">
<img src="http://placekitten.com/g/125/125" />
</div>
</div>
</div>
CSS Structure:
.containers {
position: relative;
width: 125px;
height: 125px;
}
#top, #middle, #bottom {
position: relative;
width: 100%;
border: 1px solid red;
}
#container1 {
margin: 0 auto;
}
#container2 {
float: left;
}
#container3 {
float: right;
}
#container4 {
float: left;
}
#container5 {
float: right;
}
Is there a reason you can't just place them all in one div, then position them with CSS?
<div>
<img id="img01" src="img1">
<img id="img02" src="img1">
<img id="img03" src="img1">
<img id="img04" src="img1">
<img id="img05" src="img1">
</div>
then
div {
position:relative;
width:100%;
height:100%;
}
div img {
position:absolute;
}
#img01 {
top:x;
left:y;
} etc
As a rule, you shouldn't rely on HTML for visually styling content unless you have no other option. That's what CSS is for.
Is this the one you are looking for:
#top, #middle, #bottom {
position: relative;
width: 100%;
border: 1px solid red;
clear:both;
}
DEMO
I have Products which has images in maximum 100px size. It means: width is 100px, height is small than 100px, or height is 100px, width is small than 100px. One side is always 100px.
I need to show product image on the right, name and price on the bottom left of that image. it is structure in different cases what I need:
I tried this:
<table style="width: 100%;">
<tbody>
<tr>
<td style="height: 100px; ">
<a href="#Url.Action("Details", "Product", new { id = Model.Id })" >
<img src="#Url.Content("~/Images/" + Model.Image)" style="float:right;" alt="" />
<b style="margin-top: 15%; float: right;">
<label>#Model.Price</label>
<br />
<label>#Model.Name</label>
</b>
</a>
</td>
</tr>
</tbody>
</table>
But this work only for 100px height. margin-top: 15%; is static. When image height is 50px, 60px etc.. it should change.
How can I do this? its not important to use a table. You can advice any elements to do this.
EDIT:
I added one more <td> side by side and put price and name into first <td> and image into second <td>.
Now I need to set <td> width like inner element's size. If image width in <td> is 90px, to set <td> width to 90px. Is it possible?
As already mentioned using table is not the way you should do it. But you can use CSS to simulate something like a table, although I have to mention that this won't work in ie7 or below:
The CSS
.list li {
height:100px;
border:5px solid #000;
margin-bottom:5px;
width:100%;
display:table;
}
.list li div {
display:table-cell;
vertical-align:middle;
overflow:hidden;
}
.list li div a {
display:table;
width:100%;
}
.list li a span {
display:table-cell;
overflow:hidden;
width:100%;
vertical-align:bottom;
}
.list li a span b {
display:block;
padding-right:5px;
float:right;
}
.list img {
float:right;
}
The HTML
<ul class="list">
<li>
<div>
<a href="#" >
<span>
<b>#Model.Pricexyz<br />#Model.Name</b>
</span>
<img src="http://placekitten.com/g/100/100" alt="" />
</a>
</div>
</li>
<!-- add other elements here -->
</ul>
You can find a demo here.
Here's what I came up with. Notice the dummy fields enclosed in brackets, change them to reflect your backend data.
Tables are no good because your columns can be of different widths. Your last scenario would require you to detect the height of the image or extract it (assuming you've saved it somewhere) and adding a class to the item container.
<style type="text/css">
.products-container > .item {
height: 100px;
}
.products-container > .item.image-height-60 {
padding: 20px 0;
height: 80px;
}
.products-container > .item > .column {
float: right;
height: 100px;
}
.products-container > .item > .column.info-column {
position: relative;
}
.products-container > .item > .column.info-column > .inner {
position: absolute;
bottom: 0;
right: 0;
}
.products-container img {
/* dummy image dimensions */
/*width: 60px;
height: 100px;*/
vertical-align: bottom;
}
.products-container .clear {
clear: both;
}
</style>
<div class="products-container">
<div class="item">
<!-- Image column comes first because it's pushed to the right using float: right -->
<div class="column image-column">
<a href="[link]" >
<img src="[image_src]" alt="Image for [name]" />
</a>
</div>
<div class="column info-column">
<div class="inner">
<span>[price]</span> <br />
<span>[name]</span>
</div>
</div>
<div class="clear"></div>
</div>
<!-- Example where image is assumed to be 60 pixels tall. -->
<!-- Notice I've added the class 'image-height-60' -->
<div class="item image-height-60">
<div class="column image-column">
<a href="[link]" >
<img src="[image_src]" alt="Image for [name]" />
</a>
</div>
<div class="column info-column">
<div class="inner">
<span>[price]</span> <br />
<span>[name]</span>
</div>
</div>
<div class="clear"></div>
</div>
</div>
---HTML
<div id="story">
<div id="individual">
<img src='uploads/1231924837Picture.png'/>
<h2>2009-01-14</h2>
<h1>Headline</h1>
<p>stroy story etc stroy story etc stroy story etc</p>
</div>
<br />
<div id="storynav">
<a href='home.php?start=0'>1</a>
<a href='home.php?start=1'>2</a>
<a href='home.php?start=2'>3</a>
<a href='home.php?start=3'>4</a>
<a href='home.php?start=4'>5</a>
<a href='home.php?start=5'>6</a>
<a href='home.php?start=6'>7</a>
<a href='home.php?start=7'>8</a>
<a href='home.php?start=8'>9</a>
</div>
</div>
---CSS
#story img{
border: none;
float: right;
display: inline;
padding: 10px;
margin-top: 30px;
}
#story{
width: 600px;
height: inherit;
background-color:black;
margin-left: 34px;
margin-bottom: 3px;
}
#individual{
background-color: #000000;
clear:both;
}
#storynav{
font-size: 10px;
text-align: center;
}
(source: bionic-comms.co.uk)
The above code and css is giving me a headache because, as the picture shows, the div background color gets confused when i add images in. This is dynamic content but i thought it would be easier to show the static html. Can any one tell me what i am doing wrong? The background color should cover the picture as well. Thanks!
EDIT
Thanks for that. It is something i had previously tried but it doesn't do anything. I have also tried a spacer in there as well and that doesn't do anything. Flummoxed!
You are setting the image to float right which means that the container div cannot work out it's actual height. You need to clear the floated element which essentially lets the container know how large the image actualy is.
You will need to add an element with the style clear: both; underneath the img tag in your HTML, preferably at the end of the div like so:
<div id="story">
<div id="individual">
<img src='uploads/1231924837Picture.png'/>
<h2>2009-01-14</h2>
<h1>Headline</h1>
<p>stroy story etc stroy story etc stroy story etc</p>
</div>
<br />
<div id="storynav">
<a href='home.php?start=0'>1</a>
<a href='home.php?start=1'>2</a>
<a href='home.php?start=2'>3</a>
<a href='home.php?start=3'>4</a>
<a href='home.php?start=4'>5</a>
<a href='home.php?start=5'>6</a>
<a href='home.php?start=6'>7</a>
<a href='home.php?start=7'>8</a>
<a href='home.php?start=8'>9</a>
</div>
<div class="clear"></div> <-- add this here
</div>
And add the class:
.clear
{
clear: both;
}
Read that: http://www.quirksmode.org/css/clearing.html
In short, try this:
---HTML
<div id="story">
<div id="individual">
<img src='uploads/1231924837Picture.png'/>
<h2>2009-01-14</h2>
<h1>Headline</h1>
<p>stroy story etc stroy story etc stroy story etc</p>
</div>
<br />
<div id="storynav">
<a href='home.php?start=0'>1</a>
<a href='home.php?start=1'>2</a>
<a href='home.php?start=2'>3</a>
<a href='home.php?start=3'>4</a>
<a href='home.php?start=4'>5</a>
<a href='home.php?start=5'>6</a>
<a href='home.php?start=6'>7</a>
<a href='home.php?start=7'>8</a>
<a href='home.php?start=8'>9</a>
<div class="clear"></div>
</div>
</div>
---CSS
#story img{
border: none;
float: right;
display: inline;
padding: 10px;
margin-top: 30px;
}
#story{
width: 600px;
height: inherit;
background-color:black;
margin-left: 34px;
margin-bottom: 3px;
}
#individual{
background-color: #000000;
clear:both;
}
#storynav{
font-size: 10px;
text-align: center;
}
.clear {
clear: both;
}