html image auto adjust size of div - php

The number of checkboxes can extend to like 40. If that happends, the scroll bar works and you can scroll to the right.
But i want that the image also adjust itself to that length.
So right now if i scroll to the right the image automatically stops.
Also when there are only 2 checkboxes, i want the train to be that smal. (So i just want the image to adjust to the length of the checkboxes.
The code is:
<div id="axle_bogie_border">
<!--This is the train image-->
<img src="Images/axle_train.png" alt="train">
<!--The show axles are the number of checkboxes (Filled in by a user)-->
<div id="show_axles">
<?php
$_POST['number_of_axles'];
if(isset($_POST['number_of_axles'])){
for($i=0; $i<$_POST['number_of_axles']; $i++){
echo "Axle " . "$i " . "<input type='checkbox' name='axles[$i]'>";
}
}
?>
</div>
</div>
And the CSS:
#axle_bogie_border {
border: 2px solid black;
width: 98%;
height: auto;
overflow-x: scroll;
overflow-y: hidden;
white-space: nowrap;
display: inline-block;
}
#axle_bogie_border img {
width: 100%;
height: 200px;
}
The show axles div has no content yet.
This is a example of how it looks now:
And as you can see the train does not continue after a certain length.

I think you should slice the train image into an engine and a carriage image and then define the carriage-image as background-image of #axle_bogie_border with background-repeat:repeat-x.
http://www.w3schools.com/cssref/pr_background-repeat.asp
Maybe this is helpful: CSS multiple Background Images both repeat-x

Related

Using PHP shortcode in HTML style="" CSS

I'm not sure if this is possible but I'll ask anyway...
I'm trying to use the PHP shortcode in Advanced Custom fields
<?php the_field('charitynumber'); ?>
for our client to enter a number on the back end between 1-100. This will effect the height of a div showing/hiding an image based on a overall goal number for a charity. I'm thinking of setting it up like
<div style="<?php the_field('charitynumber'); ?>"><img src="/img_here.jpg"></div>
But cannot think of how to do it or an alternative way.
You need to put the shortcode in a valid style attribute. That means outputting the style name and appending the appropriate units. Also, if the_field() returns a string, you need to echo it.
<div style="height: <?php echo the_field('charitynumber'); ?>%;"><img src="/img_here.jpg"></div>
Give this a shot - you can
<div class="progress">
<div class="fillBar" style="height:calc(100% - <?php the_field('charitynumber'); ?>);"></div>
<img src="/img_here.jpg">
</div>
Then from there, you just need to style the bar. My example below has the progress bar locked to the bottom, and when you land on the page the progress bar will animate from the top down until it stops at the current percentage.
.progress{
position: relative;
width: 50px;
height: 200px;
}
.progress img{
width: 50px;
height: 200px;
position: absolute;
z-index: 1;
}
.progress .fillBar{
width: 50px;
bottom: 0;
height: 200px;
transition: height 0.3s ease-out;
}

How to generate a layer of different color over an image?

I'm doing a grid with several elements in the sidebar of a WordPress site.
Each element of the grid is an image with a label below.
My goal is to have an image change:
the normal state of the image is to be green (#66be2c), then to the passage of mouse cursor will change it in the original image.
I tried using two physical images for the two states and overlaying them when needed. But this solution is very wasteful... load two different image files is not a good thing.
There's a way to achieve the same effect in a more efficient manner?
This is a part of my page code:
<td style="width: 150px; text-align: center;">
<p style="color: #66be2c;">
<img src="mydomain.com/aaa/wp-content/uploads/2015/08/GreenImage.png" style="width:50px; height:50px" onmouseover="this.src='mydomain.com/aaa/wp-content/uploads/2015/08/OriginalImage.png';" onmouseout="this.src='mydomain.com/aaa/wp-content/uploads/2015/08/GreenImage.png';">
</p
<p style="color: #66be2c;">.NET</p>
</td>
SOLUTION:
The correct way to do this is creating a Vector Image.
What you need is an image editor (such as Adobe Illustrator or others) and a C compiler (in particular two libraries for xslt)
These are two links that may be useful: SVG-Stacking_Guide and GitHub-SVG-Stacking-Download
I hope this can be of help to others who have the same problem.
It's a bad approach,
I'm not an expert in CSS or design but i think you should do :
<div class='overlay'></div>
<img src="mydomain.com/aaa/wp-content/uploads/2015/08/OriginalImage.png" style="width:50px; height:50px">
</div>
And put a class in CSS like this :
.overlay { background-color: your_color; }
.overlay:hover { background-color: transparent; }
You can overlay a DIV with a lesser opacity on to the image, and then register the hover such that the covering div fades away and the real image appears.
<div class='cover'></div>
<img id='your-image' />
The CSS for the image would be as such:
.cover{
position: absolute;
top: 0;
left: 0;
opacity: .7;
background: green;
/* additional transition effects */
-webkit-transitions: all .3s;
-moz-transitions: all .3s;
transitions: all .3s;
}
.cover:hover{
opacity: 0;
}
Note that the covering div and the image should be in the same containing div relative to each other.
You could use the ::before selector to achieve this. This would mean not using any extra markup, and no javascript either. You'd really benefit from not using that inline css either. Take a look at CSS :: Before
HTML:
<table>
<tr>
<td>
<p>
<img src="mydomain.com/aaa/wp-content/uploads/2015/08/GreenImage.png" class="image">
</p
<p>.NET</p>
</td>
</tr>
</table>
CSS:
td {
width: 150px;
text-align: center;
}
td p {
color: #66be2c;
}
.image {
width:50px;
height:50px;
position: relative;
}
.image::before {
content: "";
position: absolute;
height: 50px;
width: 50px;
top: 0;
left: 0;
background: green;
}
.image:hover::before{
display: none;
}
Basically, this targets your image with a class of .image and puts a 50 x 50px box on top of it with a green background. When you then move your mouse over it, it gets rid of the box.
You can see this working in this fiddle

A grid gallery view using css only, with same width different height

i am working on a grid view for image gallery
this is what i did so far but there are still vertical spaces between some of the photos
CSS:
#container{
background-color:transparent;
top: 60px;
left:8%;
height:100%;
border:1px solid ;
width: 82.19%;
position:absolute;
outline: 0;
}
.box {
background-color:#3e3e3e;
border:1px solid #bebebe;
margin: 6px 3.5px;
width:362px;
display:block;
float:left;
border-radius:3.6px;
}
.box:nth-child(2n + 0) {
float: right;
}
how i am applying it:
<div id='container'>
<?php
(some php & mysql here)
echo "<div class='box'><img src='pictures/$image' width='360' ></div>";
</div>
?>
i can't figure out the proper css to create a grid view with no extra vertical spaces.
images have varying heights fixed width, the space i m talking is that space which is not letting grid structure to form properly the vertical distance b/w some photos is alot more than it should be
Is there anybody who can help me?
NOTE: Don't suggest any jquery plugins i want to use pure css

CSS display divs below each other after screen gets to 700px

I have this HTML:
<div class="dashboard_wrap">
<div>orders</div>
<div>porting</div>
<div>contact</div>
</div>
that displays 3 divs, here is the CSS:
.dashboard_wrap {
padding:10px;
}
.dashboard_wrap div {
border-left:1px solid black;
padding:10px;
width: 50%;
height:200px;
margin-bottom:50px;
overflow-y:scroll;
float: left;
}
.dashboard_clear:after {
content: "";
display: table;
clear: both;
}
#media all and (max-width: 700px) {
div.wrap div {
width: 100%;
float: none;
}
}
I am using PHP so only certain users can see certain divs. If a user can only see the first 2 divs, how can i make them 50% each rather than 40%?
There is no need to use php or javascript for this. You can use basic html and css for this.
You can check the html fiddle for this: http://jsfiddle.net/4WaX4/1/
All the css which you need is this:
.dashboard_wrap {
display:table;
min-width:500px;
background:#00ff00;
}
.dashboard_items {
display:table-row;
}
.dashboard_items div{
display:table-cell;
border:1px solid #ff0000;
}
#media all and (max-width: 700px) {
div.dashboard_items div {
width: 100%;
display:block;
}
}
And the html looks as follows:
<div class="dashboard_wrap">
<div class="dashboard_items">
<div>orders</div>
<div>porting</div>
</div>
</div>
<div class="dashboard_wrap">
<div class="dashboard_items">
<div>orders</div>
<div>porting</div>
<div>contact</div>
</div>
</div>
Very simpel and quick. When you resize the result window in jsfiddle you see that the divs become 100% relative to the outer div (500px).
I hope this is the solution youre looking for...
You can specify the class of the wrapper based on the number of items inside.
CSS classes for each variant will handle the style automatically.
If however the number of divs can extend beyond expected numbers, then dynamic inline styles may be your solution.
<div class="dashboard_wrap has3">
<div>orders</div>
<div>porting</div>
<div>contact</div>
</div>
<div class="dashboard_wrap has2">
<div>orders</div>
<div>porting</div>
</div>
<style>
.dashboard_wrap div {
border-left:1px solid black;
padding:10px;
height:200px;
margin-bottom:50px;
overflow-y:scroll;
float: left;
}
.dashboard_wrap.has2 div {
width: 50%;
}
.dashboard_wrap.has3 div {
width: 33%;
}
</style>
When the page gets rendered, only two divs will be visible. What you need to do is use a client-based language i.e. javascript or jQuery, to manipulate what is visible on screen.
Use a simple check to see what divs are visible or use php to generate a value which you can hide in the page to make it easier to resize the divs like:
<input type='hidden' id='divs_visible' value='" . $divs_visible ."' />
then using jQuery:
$(document).ready(function() {
var divsvis = $("#divs_visible").val();
if(divsvis == 2)
{
// resize the divs
}
});
EDIT
You can also render all the divs, then using jQuery and the value you've placed in the hidden input, you can simply hide the div you do not need with:
$("#div_to_be_hidden").hide();

HTML overflow:hidden doesn't format text correctly

I'm working on a website for an American Football team. They have these newsitems on their front page which they can manage through a CMS system. I have a problem with alligning the text inside those news items. Two of the news items look like this:
As you can see, the right newsitem text are displayed nicely. But the left cuts it off really bad. You can only see the top half of the text at the last sentence. I use overflow: hidden; to make sure the text doesn't make the div or newsitem bigger. Does anyone have any idea how to solve this through HTML and CSS or should I cut it off serverside with PHP?
Here's my code (HTML):
<div class="newsitem">
<div class="titlemessagewrapper">
<h2 class="titel" align="center"><?php echo $row['homepagetitel']; ?></h2>
<div class="newsbericht">
<?php echo $row['homepagebericht']; ?>
</div>
</div>
<div class="newsfooter">
<span class="footer_author"><?php echo get_gebruikersnaam_by_id($row['poster_id']); ?></span> <span class="footer_comment">Comments <span>todo</span></span>
Lees meer
</div>
</div>
And here is the CSS:
.newsitem{
float: left;
height: 375px;
width: 296px;
margin: 20px 20px 0px 20px;
background-color: #F5F5F5;
}
.newsitem .titel{
color:#132055;
font-size:1.2em;
line-height:1.3em;
font-weight:bold;
margin:10px 5px 5px 5px;
padding:0 0 6px 0;
border-bottom:1px dashed #9c0001;
}
.titlemessagewrapper{
height: 335px;
overflow: hidden;
}
.newsitem .newsbericht{
padding:5px 5px 5px 5px;
font-size: 0.8em;
margin-bottom: 5px;
}
.newsitem .newsfooter{
width: 100%;
height: 25px;
background-color: #132055;
margin: 0px auto;
font-size: 0.8em;
padding-top: 5px;
margin-top: 10px;
border: 1px solid #9c0001;
}
You should not rely on the user to enter <cut> !
User Input = error
What if the user forgets to enter <cut>? Will your news item now look unprofessional?
What would be the point of a user creating a news item to find that some of it was cut off?
If the div can only fit a fixed string length you should validate the max length of the news item Input body instead of relying on <cut>. This can be simply achieved using maxlength attribute.
<textarea id="userinput" maxlength="150">Enter your news</textarea>
If you do use <cut> you should also add in overflow: hidden; to ensure that the content is not unprofessionally displayed if no cut tag is present.
If you want to display the all text and keep the div the same fixed height
Replace
overflow: hidden;
with
overflow:auto;
(Scroll bar won't appear when content is smaller than the div)
Otherwise validate the length of the string / content in your div or remove the CSS height attribute to allow all the content appear with no scroll bars.
Hope this helps
Remove the height attribute on the .titlemessagewrapper. Its this height attribute which is causing the cut off.
If you want the boxes to remain the same height: Take the whole string, perform substr and save in a new variable and echo that.
Eg.
<?php
$str = "abcdefghijkl";
$new_strsubstr($str, 0, 8); // abcdef
// will return abcdefhi
?>

Categories