I want to set several div's in succession, but find it unnecessary to copy the code again and again. How it is possible for me to put 5 times the same div's behind the other in a more effective way than I've described here?
HTML:
<div class="procduct">
<div class="image">
<img src="http://i.stack.imgur.com/rOVDt.jpg"/>
</div>
<div class="overlay"></div>
</div>
<div class="procduct">
<div class="image">
<img src="http://i.stack.imgur.com/rOVDt.jpg"/>
</div>
<div class="overlay"></div>
</div>
<div class="procduct">
<div class="image">
<img src="http://i.stack.imgur.com/rOVDt.jpg"/>
</div>
<div class="overlay"></div>
</div>
<div class="procduct">
<div class="image">
<img src="http://i.stack.imgur.com/rOVDt.jpg"/>
</div>
<div class="overlay"></div>
</div>
CSS:
.procduct {
margin: 5px;
padding: 5px;
height: 150px;
width: 150px;
border: 1px solid #F00;
float: left;
}
.image {
z-index: -1;
position: absolute;
}
.overlay {
padding-top: 65px;
padding-left: 17px;
display:none;
}
.procduct:hover .overlay {
display:block;
}
.procduct:hover .image {
opacity:0.00;
}
.clear {
clear: both;
}
http://jsfiddle.net/ghac101/hvpn4/
Unfortunately there is no way with vanilla HTML production to magically reduce the work required. You can, however, use a framework like HAML to reduce some of the repetitiveness.
For example, the code:
<div class='content'>Hello, World!</div>
in HAML, can become:
.content Hello, World!
It's not exactly what you're looking for, per se, but it is probably as close as you'll get. The bottom line is you can't cut corners with writing HTML this way. You could use another language like JavaScript or PHP to create or duplicate HTML elements as you need them, however.
There sure is:
<?php
$numberofdivs = 5;
for ($i=1;$i<$numberofdivs;$i++) {
echo '<div class="procduct">
<div class="image">
<img src="http://i.stack.imgur.com/rOVDt.jpg"/>
</div>
<div class="overlay"></div>
</div>';
}
?>
Hope this helps.
Related
I'm sorry if I'm not using the correct terminology, I'm new to this. I want to stack two divs side by side horizontally, the image and the message content. I have coded a messaging UI.
It all worked fine until I wanted to ad the users image next to the message. I have tried adding display: inline-block; to both divs (the image and message content) but that didn't help.
I'm not sure what else I can do, unless I just use bootstraps grid system, which seems overkill.
https://codepen.io/anon/pen/pxZygr
clear:both; prevents elements from floating next to one another. Your style rule .message-holder .message-to { clear: both; } is affecting the elements you want to display inline. Here's a helpful readup I found on floats and clear: both.
One way I can think of this working would be to have each value implemented as a table element. Something like...
<table>
<td>
<div class="message-image pull-right">
<img src="http://placehold.it/40x40">
</div>
</td>
<td>
<div class="message-content message-to">
Hey man, how was your day after?
</div>
</td>
</table>
Wherever you have class message-holder, add class d-flex
html,
body {
height: 100%;
}
.messages-wrapper {
padding: 20px 20px 0px 20px;
height: 100vh;
}
.pull-right {
float: right !important;
}
.message-holder .message-to {
float: right;
clear: both;
}
.message-content {
max-width: 300px;
padding: 12px 15px 12px 15px;
border-radius: 3px;
margin-bottom: 10px;
}
.message-image {
clear: both;
}
.message-image img {
width: 40px;
border-radius: 100%;
}
.message-picture img {
width: 20px;
height: 20px;
}
.message-to {
background-color: #161616;
color: #fff;
float: right;
}
.message-from {
background-color: #ebebeb;
float: left;
}
<link rel="stylesheet" type="text/css" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" type="text/css">
<div class="messages-wrapper">
<div class="message-holder d-flex">
<div class="message-image pull-right">
<img src="http://placehold.it/40x40">
</div>
<div class="message-content message-to">
Hey man, how was your day after?
</div>
</div>
<div class="message-holder d-flex">
<div class="message-image pull-right">
<img src="http://placehold.it/40x40">
</div>
<div class="message-content message-to">
Can you also bring your charger when you come round?
</div>
</div>
<div class="message-holder d-flex">
<div class="message-image">
<img src="http://placehold.it/40x40">
</div>
<div class="message-content message-from">
It was alright, I'll tell you all about it later! No problem, I'm on my way now.
</div>
</div>
<div class="message-holder d-flex">
<div class="message-image">
<img src="http://placehold.it/40x40">
</div>
<div class="message-content message-from">
ffff
</div>
</div>
<div class="message-holder d-flex">
<div class="message-image pull-right">
<img src="http://placehold.it/40x40">
</div>
<div class="message-content message-to">
Hey man, how was your day after?
</div>
</div>
</div>
I know there are dozens of similar questions and some of them have helped me get to this point but I can't see any rhyme or reason to this error.
I've tagged an image with the id HeaderGradient and I'm trying to set it's size in the css file but it's not working. When I inspect the element in Firefox there is no mention of my css file. I'm using the Bootstrap framework. What am I doing wrong?
body {
#HeaderGradient {
width: 80%;
height: 141px;
}
}
<div class="row">
<div class="col-sm-4"></div>
<div class="col-sm-4">
<div class="panel-heading">
<img class="img-responsive" src="images/logo.png" id="Logo" alt="EP Logo">
<img class="img-responsive" src="images/header_gradient.png" id="HeaderGradient" alt="Gradient Image">
</div>
</div>
<div class="col-sm-4"></div>
</div>
You are using invalid CSS code for this, It should be
#HeaderGradient {
width: 80%;
height: 141px;
}
#HeaderGradient {
width: 80%;
height: 141px;
}
<div class="row">
<div class="col-sm-4"></div>
<div class="col-sm-4">
<div class="panel-heading">
<img class="img-responsive" src="images/logo.png" id="Logo" alt="EP Logo">
<img class="img-responsive" src="images/header_gradient.png" id="HeaderGradient" alt="Gradient Image">
</div>
</div>
<div class="col-sm-4"></div>
</div>
It's not a valid CSS syntax update the syntax as follows to get #HeaderGradient within body tag.
body #HeaderGradient{
width: 80%;
height: 141px;
}
You have the ID selector in the wrong place. Instead of:
body {
#HeaderGradient{
....
}
}
Move the selector outside:
body {
....
}
#HeaderGradient{
....
}
If you want to use that kind of CSS syntax you need to use a CSS preprocessor. Check out LESS or SASS
How to align the below image and box in same row? Image on left and box on right with some space between them.
<div id="slideshow" >
<div id="changeimage">
<img class="image" src="bafdf1f214f5a800c95ef301234c254a.iix"/>
</div>
<div id="newsbox">
<span class="label label-danger">Latest News</span>
<div class="group-box">
<div class="grey-group">
<span>Notes:This is a box</span>
</div>
</div>
</div>
</div>
Like #ntgCleaner said: "there's about 20 ways to skin that cat."
This might be one way to achieve this:
#slideshow {
display: flex;
}
.group-box {
margin-top: 50px;
}
<div id="slideshow" >
<div id="changeimage">
<img class="image" src="//thumb7.shutterstock.com/display_pic_with_logo/260389/347420135/stock-photo-top-view-of-architect-drawing-on-architectural-project-347420135.jpg"/>
</div>
<div id="newsbox"><span class="label label-danger">Latest News</span>
<div class="group-box">
<div class="grey-group">
<span>Notes:This is a box</span>
</div>
</div>
</div>
</div>
You can use "float" or "display: inline-block" css selectors to set your elements this way. I belive this simple example will help:
<style>
#slideshow{
border: 1px solid black;
width: 100%;
}
#changeimage{
float: left;
background: blue;
width: 40%;
}
#newsbox{
float: left;
background: red;
width: 40%;
}
#separator {
width: 20%;
height: 100px;
float: left;
background: green;
}
.clear{
clear: both;
}
</style>
<div id="slideshow" >
<div id="changeimage"><img class="image" src="http://www.w3schools.com/html/pic_mountain.jpg"/></div>
<div id="separator"></div>
<div id="newsbox"><span class="label label-danger">Latest News</span>
<div class="group-box">
<div class="grey-group">
<span>Notes:This is a box</span>
</div>
</div>
</div>
<div class="clear"> </div>
</div>
And here is working example:
https://jsfiddle.net/ej53b8x2/
If you want to set elements in row maybe you should use some framework like bootstrap or foundation?
I have this on my page. i wanted the container divs to align at the center. so i gave display:inline-block. but it didn't work. why is this happening? is there a way to display the containers as inline-block elements so that they appear exactly at the center?
<div id="container">
<div id="definition">
<p>Nothing</p>
</div>
<div id="image">
<img src="img1.jpg" />
</div>
</div>
<div id="container">
<div id="definition">
<p>Nothing</p>
</div>
<div id="image">
<img src="img1.jpg" />
</div>
</div>
<div id="container">
<div id="definition">
<p>Nothing</p>
</div>
<div id="image">
<img src="img1.jpg" />
</div>
</div>
css
#container {
vertical-align:top;
}
#image {
height:30%;
width:30%;
position: absolute;
overflow: hidden;
}
#definition {
width: 30%;
height: 30%;
position: absolute;
background-color: red;
}
Using display: table and display: table-cell this code will centre the divs on the page: Fiddle. Hopefully this is the effect you want.
I have the following html:
<div class="wrapper">
<h1>Ipods</h1>
<div class="main-topright-bottom">
<h1>Related Products</h1>
<div>Check items to add to the cart or select all.</div>
<div class="relatedproduct">
<div class="relatedproductimage">
<img src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcR-YiokcA1U38PFCbIYklGbbqu-4E7gj6p-c4txmJjZxblroYu40A" />
</div>
<div class="relatedproducttext">
<div class="relatedproductheading">A red ipod nano.</div>
<div class="price">$140.00</div>
<div class="addtowishlist">Add to Wishlist</div>
</div>
</div>
<div class="relatedproduct">
<div class="relatedproductimage">
<img src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcR-YiokcA1U38PFCbIYklGbbqu-4E7gj6p-c4txmJjZxblroYu40A" />
</div>
<div class="relatedproducttext">
<div class="relatedproductheading">A blue ipod nano.</div>
<div class="price">$140.00</div>
<div class="addtowishlist">Add to Wishlist</div>
</div>
</div>
</div>
</div>
and css:
.wrapper { background: blue; }
.relatedproduct { clear: both; }
.relatedproductimage { float: left; }
.relatedproducttext { float: left; }
I want to know how come the blue background does not extend to the bottom div.
What am I doin wrong?
http://jsfiddle.net/johngoche99/C9NKP/2/
Thanks.
Floats aren't contained by default. You make it do this by floating the wrapper too, or giving it an overflow property.
.wrapper {
overflow: hidden;
}
jsfiddle demo
Read http://colinaarts.com/articles/float-containment/ for another (better) alternative if you don't want to hide overflow as a side-effect.
More information at https://developer.mozilla.org/en-US/docs/Web/CSS/Block_formatting_context
change
.wrapper { background: blue; }
To
.wrapper { background: blue;overflow:hidden;}