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>
Related
I want to align the image to left, then its title then the text below it.
Here is the screenshot of what I want to make.
I have made DIV for each content. I dont know if its okay to do that.
I made it, because I ll have more control for individual content.
But I havent ben able to do so.
.howtocontainer {
height: 1985px;
width: 1121px;
background-image: url("//azlily.bex.jp/eccube_1/html/template/default/img/howto/background.png");
}
.firstsection {
/*background: rgb(255,255,255,0.3);*/
background: grey;
height: 200px;
position: relative;
top: 300px;
margin: 0 40px 0 40px ;
}
.firstpic {
padding-top: 20px;
}
.firstsecbanner {
float: right;
margin-right: 500px;
margin-top: -15px;
}
<div class ="howtocontainer">
<div class="firstsection">
<div class="firstpic">
<img src="https://images.pexels.com/photos/462118/pexels-photo-462118.jpeg?auto=compress&cs=tinysrgb&h=350">
</div>
<div class="firstsecbanner">
<img src="https://images.pexels.com/photos/462118/pexels-photo-462118.jpeg?auto=compress&cs=tinysrgb&h=350">
</div>
<div class="firstsectext">
お好みの量(目安はピンポン玉大です)を手に取って、パートナーの性感帯を指の腹や手のひらで優しくマッサージ<br>
してください。<br>
最初は背中や首筋、そして胸などと、段々と敏感な部分へ伸ばしていくと、ヌルヌルと滑る感覚が気持ちよく、エロ<br>
ティックな気分を高めることができます。<br><br>
性感帯は塗った部分が敏感になり、ただ触れるだけでも極上の気持ち良さ。<br>
シュチュエーションに合わせてラブローションの香りを変えたりしながら楽しみ方を<br>
見つけてください。
</div>
</div>
<div class="secondsection"></div>
<div class="thirdsection"></div>
</div>
All I did was Included image and text in one DIV
But gave a class to image by <img class="class" src"path" >
Then I did float:left to .img class.
There are 2 key points that you should notice about using float:
Float container should be set a specific width (absolute or relative width)
clear all floating items
You should change your HTML structure a little bit, and add some CSS styles:
.firstpic {
float: left;
width: 300px; /*this width is equal with its image's width */
}
.description {
float: left;
width: calc(100% - 300px);
}
/* Clear floating item */
.firstsection::after {
display: table;
content: "";
clear: both;
}
<div class="firstsection">
<div class="firstpic">
<img src="the-image-on-left-side">
</div>
<div class="description">
<div class="firstsecbanner">
<img src="the-title-image-on-top">
</div>
<div class="firstsectext">
お好みの量(目安はピンポン玉大です)を手に取って、パートナーの性感帯を指の腹や手のひらで優しくマッサージ<br>
してください。<br>
最初は背中や首筋、そして胸などと、段々と敏感な部分へ伸ばしていくと、ヌルヌルと滑る感覚が気持ちよく、エロ<br>
ティックな気分を高めることができます。<br><br>
性感帯は塗った部分が敏感になり、ただ触れるだけでも極上の気持ち良さ。<br>
シュチュエーションに合わせてラブローションの香りを変えたりしながら楽しみ方を<br>
見つけてください。
</div>
</div>
</div>
Please add absolute URL instead of relative URL to see your pictures.
Hope this helps.
A disadvantage of using floats is that it disturbs the natural document flow. You may want to consider an alternative using flexbox.
.firstsection {
display: flex;
}
.firstpic {
width: 300px;
/*this width is equal with its image's width */
}
.description {
width: calc(100% - 300px);
}
<div class="howtocontainer">
<div class="firstsection">
<div class="firstpic">
<img src="//azlily.bex.jp/eccube_1/html/template/default/img/howto/01.jpg">
</div>
<div class="description">
<div class="firstsecbanner">
<img src="//azlily.bex.jp/eccube_1/html/template/default/img/howto/firstsecbanner.png">
</div>
<div class="firstsectext">
お好みの量(目安はピンポン玉大です)を手に取って、パートナーの性感帯を指の腹や手のひらで優しくマッサージ<br> してください。
<br> 最初は背中や首筋、そして胸などと、段々と敏感な部分へ伸ばしていくと、ヌルヌルと滑る感覚が気持ちよく、エロ
<br> ティックな気分を高めることができます。
<br><br> 性感帯は塗った部分が敏感になり、ただ触れるだけでも極上の気持ち良さ。
<br> シュチュエーションに合わせてラブローションの香りを変えたりしながら楽しみ方を
<br> 見つけてください。
</div>
</div>
</div>
<div class="secondsection"></div>
<div class="thirdsection"></div>
</div>
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 know there a many of these about but for some reason I keep failing to implement them.
So I need the content in the class .infobox to be in the middle of the div. So I need it aligned vertical and horizontally.
I have put ALL my code below as some of the "fixes" I tried worked but caused the layout to move and so on. So hopefully you guys can get it aligned without causing the layout to break.
Fiddle is at the bottom. On a side note if you have any tips on how to neaten the layout code please do let me know. But the main problem is aligning the content.
HTML:
<div id="con">
<div id="box">
<div id="header"><h1>Test</h1></div>
<div id="left">
<div class="infobox">Test: <br /> <input /> </div>
<div class="infobox">Test: <br /> <input /> </div>
<div class="infobox">Test: <br /> <input /> </div>
<div class="infobox">Test: <br /> <input /> </div>
</div>
<div id="right">
<div class="resultbox">
<ul>
<li>Test <br />Test</li>
</ul>
</div>
<div class="contactbox">
<ul>
<li>Phone Number: <br /> 00000 000000</li>
<li>Email: <br /> test#Test.com</li>
</ul>
</div>
</div>
</div>
</div>
CSS:
div {
outline: 1px solid #000;
}
#box {
width: 580px;
height: 300px;
}
#header {
height: 15%;
background: url(http://us.123rf.com/400wm/400/400/mechanik/mechanik1112/mechanik111200003/11665900-vector-cartoon-semi-truck.jpg) no-repeat;
background-size:80px 40px;
background-position:right top;
}
#left {
width:70%;
height: 85%;
float: left;
}
#right {
width:30%;
height: 85%;
float: right;
}
.infobox {
width: 50%;
height: 50%;
float: left;
text-align: center;
}
.resultbox {
width: 100%;
height: 50%;
}
.contactbox {
width: 100%;
height: 50%;
font-size: 12px;
}
.contactbox ul, .resultbox ul {
margin: 0;
}
.contactbox li, .resultbox li {
list-style: none;
}
DEMO HERE
What I have tried:
Tried to use padding-top and padding-bottom - This seemed to not align it correctly and then I couldn't get the layout to sit correctly.
Also looked into using position: relative and position: absolute but I have never been too good with them and couldn't manage to get the content to sit where I wanted it to.
I took the liberty of manipulating you mark-up a bit and added an extra div to achieve the output.
Fiddle
HTML
<div class="infobox">
<div class="cent">Test:
<br />
<input />
</div>
</div>
CSS
.infobox > .cent {
outline: 1px solid #0F0;
vertical-align: middle;
margin-top:20%;
}
Whats happening here??? : since your content div infobox has the styling, to give a different set of styling to inner content(which is not floating), you have to use a them under a child div for display!
add margin:0 auto; to #box
like so: http://jsfiddle.net/c82DU/2/
You could take a look at this site, it explains a bit about tables.
The layout u are using looks like a table, so why not use tables? easier text aligning
http://www.w3schools.com/html/html_tables.asp
I have tried everything to get a div of dynamic width (highlightsContainer) to center within its parent. I think it has something to do with the fact that this div takes up 100% of the parent container width, no matter what I do.
I have tried to set it to inline-block, but that does not fix it. Dev Tools still shows it as taking up 100% of the parent container width. The children of .highlightsContainer are not forcing it to this width.
Here is my markup:
<div class="highlightsContainerWrapper">
<div class="highlightsContainer">
<a href="#video">
<div class="highlightEntry">
<img src="../img/portfolio/lr/lr-highlight-1.png" />
<div class="highlightLabel">Mobile Site</div>
</div>
</a>
<a href="#email">
<div class="highlightEntry">
<img src="../img/portfolio/lr/lr-highlight-2.png" />
<div class="highlightLabel">Video Gallery</div>
</div>
</a>
<a href="#social">
<div class="highlightEntry">
<img src="../img/portfolio/lr/lr-highlight-3.png" />
<div class="highlightLabel">jQuery Modals</div>
</div>
</a>
<a href="#blog">
<div class="highlightEntry">
<img src="../img/portfolio/lr/lr-highlight-4.png" />
<div class="highlightLabel">SEO</div>
</div>
</a>
</div>
</div>
And my CSS:
.highlightsContainerWrapper {
float: left;
}
.highlightsContainer {
display: inline-block;
margin: 0 auto;
}
.highlightEntry {
width: 18%;
margin: 3% 1%;
float: left;
position: relative;
overflow: hidden;
border: 1px solid #fcfbe7;
}
You can do something like this:
.highlightsContainerWrapper {
float: left;
width: 100%;
text-align: center;
}
Works for dynamically generated content. You won't have to set a width on .highlightsContainer
Working jsFiddle demo
To add to the previous comment, this could also work as well without having to have the width be 100 percent each time if you don't want it to be.
.highlightsContainerWrapper {
float: left;
text-align:center;
}
Then you can make the width whatever you want it to be.
Hoped that helped you center the div
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;
}