I have a web page with an image and title with a description and I want to put another column next to the image and title and text with the same structure.
I have this
echo '<div class="gamedes">';
echo '<img class="miniaturas" src="recursos/miniaturas/coster.png" </img>';
echo '<a class="gamede" href="game.php?name='.$row['name'].'">'.$row['name'].'</a><br>';
echo '<div class="description"><script>document.write("'.$row['description'].'".substring(0,120) + "<br>");</script></div><br><br><br><br>';
echo '</div>';
And this css
.miniaturas {
display: inline;
border-radius: 10px;
float: left;
}
.description {
font-size: 15px;
background-color: #A4A4A4;
display: inline;
border-radius: 3px;
margin-left: 5px;
width: 10%;
}
.gamede{
font-size: 20px;
font-weight: bold;
display: inline;
margin-left: 5px;
}
I want yo put the same structure image, title and description next to the first
I try to put a width to the description but it doesn't work.
Its like this http://jsfiddle.net/Ninjacu/t9r9S/4/
And I want to out the second image next to the first like in two columns
It seems you want something like this:
img | img
title | title
des | des
echo '<div class="gamedes">';
echo '<img class="miniaturas" src="recursos/miniaturas/coster.png" />';
echo '<a class="gamede" href="game.php?name='.$row['name'].'">'.$row['name'].'</a><br />';
echo '<div class="description"> <script> document.write("'.$row['description'].'".substring(0,120)"); </script><br /></div><p>';
echo '</div>';
css:
.gamedes{
width:20%;
float:left;
}
.description{
width:100%;
overflow:hidden;
}
This should work.Give width to the div containing the structure so everything you put inside that div will fall in place.
I'm assuming the question stems from two things - your current layout isn't quite working correctly and you are interested in adding another column to the existing layout. I adjusted your original code and removed the php (it isn't relevant for a layout question), then applied a table-row and table-cell based layout via css (not using an actual table tag). One other thing I did was I used div tags for layout rather than trying to force layout on specific tags such as the "a" tag. Doing this you end up with the following html:
<!-- This is a row -->
<div class="gamedes">
<!-- this is a column -->
<div class="miniaturas"><img src="//upload.wikimedia.org/wikipedia/commons/thumb/5/51/Google.png/800px-Google.png" /></div>
<div class="gamede">Text for the link</div>
<div class="description">This is a somewhat longer description here probably up to 120 characters</div>
</div>
In the css the key pieces are:
.gamedes { display: table-row; }
.miniaturas { display: table-cell; }
/* etc */
To see the whole thing running, take a look at this JSFiddle: http://jsfiddle.net/hPLNK/4/
So, given this layout, all you have to do to add a new column now is add a new <div> inside of the "gamedes" and set the css display style to table-cell!
Final Note - The original code you provided had a few other issues that I fixed. A <script> tag is for including javascript. You seem to want to include text. An image tag can't have a </img> inside of it. Avoid using <br/> to force a height on a div or area. Instead use css based layouts.
Small PHP Example
In case you need some help getting the PHP back into this example, my recommendation is to put the php code inline. You end up with something like:
<div class="miniaturas"><img src="<? echo($imageUrl); ?>" /></div>
I made the assumption here that your image link is stored in "$imageUrl", but you get the idea. The nice thing about putting php inline like this is it reads a little more cleanly and editing the html becomes much easier. Best of luck!
Related
I am outputting two tables inline with a parent div just surrounding the content with a border. Both tables are output from a form submission that then generates the tables and outputs them using PHP. When the tables output, both are inline, however, they are outside of the bottom border of the parent div. I want them to both be output and be within the parent div's border but I can't seem to do it. I've tried using display, overflow and height properties but nothing seems to work. The following is my code and current output.
Code in HTML body:
<div class="main-body">
<form id="formFilter" method="POST" action="portal.php">
<label for="dateInp">Search a Date:</label>
<input type="date" name="dateInp" value="yyyy-mm-dd" min="2022-01-01" max="2030-12-31">
<input type="submit">
</form>
<?php
//Run function to create table if user has applied filter. If not then to load all data.
if(isset($_POST['dateInp'])) {
echo filterTable($conn);
} else {
echo createTable($conn);
}
?>
</div>
PHP function called that generates and returns tables:
External stylesheet code for parent div:
.main-body {
border-style: solid;
padding: 20px;
margin: 10px;
width: 80%;
margin: auto;
height: auto;
}
This is the output i'm getting:
I need both tables to just be within the border that it is currently displaying outside of, but I can't figure out how to do that. Any help is very appreciated thank you!
I have tried using:
display:inline-block;overflow:scroll;height: fit-content;
Nothing seems to work for me. I was hoping that the content would be output within the border instead it is just outside of it, with the top of the table bordering the bottom width of the parent that it should be within.
I have this code below to display author name under post titles, but how would I assign a class to it so I can change its style using css, like its color and font size etc?
<?php the_author_posts_link(); ?>
the_author_posts_link actually echoes an anchor tag of this form
John.Smith
The simplest way of formatting it is probably to wrap it in a div say which has a unique class which you can style in the Wordpress backend at Appearance>Cusomize
<div class="myAuthorStyle"><?php the_author_posts_link(); ?></div>
A simple example of styling:
.myAuthorStyle a {
color: magenta;
text-decoration: none;
font-size: 2em;
display: inline-block;
}
<div class="myAuthorStyle">John.Smith</div>
How can I color the first word using CSS when I have div tag for the title?
<div class="head-logo"> <? echo $siteName ?> </div>
CSS
.head-logo{
text-align:center;
color:#000000;
font:normal 22px Tahoma;
margin: 0px 10px 20px 60px;
}
You can use php explode
<div class="head-logo">
<?
$title = explode(" ", $siteName, 2);
echo '<span style="color: #FF0000">'.$title[0].'</span> '.$title[1]);
?>
</div>
You can do it this way:
<div class="head-logo">
<?
$title = explode(" ", "My title here");
echo '<span class="firstWord">'.$title[0].'</span>'.substr(implode(" ", $title), strlen($title[0]));
?>
</div>
.head-logo{
text-align:center;
color:#000000;
font:normal 22px Tahoma;
margin: 0px 10px 20px 60px;
}
.firstWord{color: red;}
Okay, so there are ways to do this with JS, and some tricky CSS workarounds.
Here's why it doesn't work:
There is no "::first-word" pseudo class, since in a code language, one 'word' is a pretty half-baked definition. So the way I have always done this is with <span>...</span> tags, but I see you are using PHP to echo your website name, so you may be able to do something along the lines of this using the ::first-line pseudo element, then making the pseudo a block and picking it's length that way:
CSS:
display:block;
Width:40-100px; /* just enough for one word, depends on font size */
Overflow:visible; /* so longer words don't get clipped.*/
float:left; /* so it will flow with the paragraph. */
position:relative; /* for typeset adjustments. */
CSS to increase size of first word
This is a JS solution, that essentially replaces adds a span class in your tag and lets you change how many letters are there.
JS:
$(function() {
$('h2').each(function(){
$(this).html( $(this).text().replace(/(^\w{5})/,'<span>$1</span>'));
});
});
Style half of a word, sentence, etc
fiddle:
http://jsfiddle.net/3gMK3/
The fiddle, CSS, and JS is not mine, just something I found while researching
I am using WAMP. I want to take background image URL from my database and want to show this in div class 'box'. I tried it by followed way but couldn't succeed. the last background image is appearing on each box while I want to show different images. Code I am using is
<?php
$feild_set = get_all_feilds();
while($feild = mysql_fetch_array($feild_set)) {
$url = $feild['background_image_url'];
echo "<style>
.box {
width: 300px ;
height: 100px;
background-image: $url;
background-visibility: visible;
border: 1px #00FF33;
margin-bottom: 10px;
display: inline-table;
margin-right: 10px;
}
</style>";
echo "<div class=\"box\">";
echo "<a href=\"content.php?feild=" . $feild['id'] . "\" ><block_holder>{$feild['menu_name']}</block_holder></a>";
echo "</div>";
}
?>
Thanx in advance
Try this:
<?php
echo "
<style>
.box {
width: 300px ;
height: 100px;
background-visibility: visible;
border: 1px #00FF33;
margin-bottom: 10px;
display: inline-table;
margin-right: 10px;
}
</style>";
$field_set = get_all_feilds();
while ($field = mysql_fetch_assoc($field_set)) {
echo '
<div class="box" style="background-image:'.htmlspecialchars($field['background_image_url']).';">
<a href="content.php?feild='.htmlspecialchars($field['id']).'">
<block_holder>'.htmlspecialchars($field['menu_name']).'</block_holder>
</a>
</div>';
}
?>
What have I done?
Placed the declaration of the .box CSS class outside the loop so it is only output once
Changed mysql_fetch_array() to mysql_fetch_assoc() as it is less confusing and more efficient
Removed the background-image: property from the .box class
Added a background-image: property to an inline style= attribute for each div and wrapped the URL of the image in url() (this has been undone as it seems the URLs are stored in the database with this already done
Passed data from the database through htmlspecialchars() before outputting it
Corrected the spelling of feild to field where it can be done without breaking the rest of your code
Some general indentation and quote tidying and readability fixes
As it was, your CSS .box class was declared more than once. Because of the cascading nature of CSS, only the values used in the last declaration would have been used - each declaration of a property overrides the last, which is why you were only seeing the last image. You also would not need to declare those details more than once - the whole idea of a class is that you can declare it once and use it multiple times. If you want element-specific properties, use IDs or inline styles (preferably IDs, but I have used inline styles here for simplicity).
I am trying to add the new twitter button to one of my Wordpress templates. For an example, see here: http://johnkivus.com/2010/08/12/if-you-build-it/. I want the text aligned with the top edge of the button instead of the button. The code section that puts the twitter button in place is as follows:
<div class="postmeta">
<p>Tweet<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script> <?php _e("Filed under", 'studiopress'); ?> <?php the_category(', ') ?> · <?php _e("Tagged with", 'studiopress'); ?> <?php the_tags('') ?></p>
</div>
the CSS for postmeta is:
.postmeta {
font-size: 11px;
text-transform: uppercase;
margin: 0px;
padding: 5px 0px 0px 0px;
border-top: 1px solid #333333;
}
.postmeta p {
margin: 0px;
padding: 0px;
display: inline-block;
}
I'm far from an expert in CSS, so I've only tried the following things:
- adding "vertical-align: text-top;" to the css
- adding "display: inline-block;" & "vertical-align: top;"
- and, as a complete flyer, style='vertical-align: top' to the button.
What would be the easiest way to get the text aligned with the top of the button?
UPDATE
Based on a suggestion from thomasrutter, I added a style to both the button and the text. This gets me much closer to what I want, however, the elements processed via PHP commands are still showing up aligned with the bottom of the image. The link is the same to see the current state of things: http://johnkivus.com/2010/08/12/if-you-build-it/ however the code is not as follows:
<div class="postmeta">
<p>Tweet<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script> <span style="vertical-align: middle"><?php _e("Filed under", 'studiopress'); ?> <?php the_category(', ') ?> · <?php _e("Tagged with", 'studiopress'); ?> <?php the_tags('') ?></span></p>
</div>
You need to give both elements next to each other the same value for the vertical-align property.
In this case, where you are aligning a button with some text and the button is a different height to the text, I'd recommend vertical-align: middle which will need to be set on both the button and the text beside it (not on the containing block element, but on the actual inline elements including the button and the span of text beside it).
I don't predict that vertical-align: top would have the effect you desire, but you can certainly try it: you need to add that property to both the button and a span around the text that is beside it.