I have a style set out for a div class, for some html that is loaded from this text file.
content.txt
<div class="container">
<main class="content">
<strong>Paragraph Title</strong> <br>
Lots of text that actually goes here.
</main><!-- .content -->
</div><!-- .container-->
In fact, the text between the <strong> tags doesn't look any different that the rest of that text.
CSS
<style type="text/css">
#auto-slideshow {
position:relative;
z-index:1;
overflow:hidden;
margin:0 auto;
height:300px;
border:2px solid #333333;
box-shadow:0 0 5px 0 #000;
-webkit-box-shadow:0 0 5px 0 #666;
}
#auto-slideshow img {
height: 100%;
width: 25%;
position:absolute;
margin-left: 32.5%;
z-index:1;
opacity:0;
-webkit-transition:opacity .8s linear;
}
#auto-slideshow img.show {
opacity:1;
}
.content {
border-right: solid 1px #999999;
}
</style>
HTML
<div class="middle">
<?php
echo file_get_contents( "modules/content.txt" ); // get the contents, and echo it out.
?>
<?php
echo file_get_contents( "modules/leftSidebar.txt" ); // get the contents, and echo it out.
?>
<?php
echo file_get_contents( "modules/rightSidebar.txt" ); // get the contents, and echo it out.
?>
</div><!-- .middle-->
And here is what shows up when I inspect the element
Update
I increased the size of the border to crazy amounts (100px) and found that the text is wrapping around what should be the border, but it's still not showing the border.
Check your stylesheet. In the inspect element panel, it shows that the padding property is defined two different times, one in line 113, and the second one in 162. Remember that css uses the last definition, so you should:
Specify your rules after line 162
Remove the rules in line 162
Use the !important tag in the first definition so it uses that one instead
Any of these should work
Related
thanks for assisting.
I'm having an issue in which my DIV class named box-2 is only applying itself to the title of the section, even though I closed it around the entire code. I'm very new to PHP, so I'm wondering if there is something I'm overlooking.
<div class="box-2 shadow">
<?php if (get_field('highlights')) { //Sub speciality ?>
<div itemprop="Restuarant Highlights">
<h3 class="content-title">Highlights</h3>
<ul>
<?php $terms = get_field('highlights'); ?>
<?php foreach ($terms as $term){ ?>
<li><div class="sl-highlights"><span class="icon-ok-circled"><?php echo $term->name; ?></span></div></li>
<?php } ?>
</ul>
</div>
</div>
<div class="clearboth"></div>
<?php } ?>
I need the box-2 class to be applied to everything, as it spaces out the entire section for me.
EDIT: This pulls the data from a taxonomy, and displays it like:
Bananas Apples Pears Lemons Grapes
Peaches Strawberrys
Here is the CSS:
.box-2 {
width: 100%;
border-top: 1px solid rgba(0,0,0,.05);
margin-bottom: 7px;
padding: 12px 0 3px 0;
}
.sl-highlights {
float: left;
margin-right: 4%;
font-size: 14px;
min-width: 135px;
line-height: 25px;
}
.content-title {
font-size: 18px;
color: #444;
padding-bottom: 9px;
font-weight: bold;
font-family: 'HelveticaNeue','Helvetica Neue',Helvetica,Arial,sans-serif;
}
Thank you very much for any and all help!
Anytime you apply a float style to an element, you remove it from the normal document flow; basically, the element doesn't reserve the space it normally would. Since that's what normally defines the height of it's container, the container tends to collapse to the height of the next element that is in the normal flow.
In your case, since all of the elements that have content are floated, box-2 collapses to a zero height. If you want it to still contain the floated elements, add an overflow: auto; rule to .box-2.
You can simplify your markup a bit by eliminating the <div> elements that currently have the sl-highlights class and instead apply the class to the <li> elements. I'd probably add a display: block rule too, since technically it's invalid to have a block-level element (the <h3> tags) inside an inline element (the <li> element).
I am retrieving a list of products from a database and want to display them all in a rows of 3 columns not using a table though. So I want 3 divs to be displayed side by side. then below.
<div class="productindividualdisplay">
<div class="productphoto">
<img src="http://3.bp.blogspot.com/-_xP-UUa4D0c/UfAo1eYxURI/AAAAAAAAAT4/xsibNtxZceQ/s320/Books.jpg" alt="Smiley face" width="250" height="250"></p>
</div>
<div class="producttitle">
<?php echo $row['title'] ?>
</div>
<div class="productprice">
<?php echo "<div id='productrrp'> €" . $row['rrp'] . "</div>";
if(is_null($offeringprice)) {
echo "Not Available";
} else {
echo "€" . $offeringprice['price'];
}
?>
</div>
That is my code but it is just displaying the divs below each other. Is it possible so it fills up the row before starting another one?
Try using display: inline-block; on the divs's css.
A <div> is a block-level element. Block-level elements, like <h1>, <p>, <table> etc. will (by default) span the entire width of their parent elements, so they can't be positioned next to eachother.
You can change this behavior, however, using the following CSS rule:
div.column {
display: inline-block;
}
This will render the <div>s as inline blocks.
Now you can give it a certain width so that three divs fit into a row. Do note that, when you leave whitespace between two <div> elements, there will be some visual whitespace. If you give all div's a width of 33.333333333%, the extra whitespace will cause their combined width to exceed 100%, so the third div will move to the next line.
You can simply prevent this by making sure there is no whitespace between the HTML elements:
<div class="column">
<p>Some contents here</p>
</div><div class="column">
<p>As you can see, no whitespace between the two div elements.</p>
</div>
Of course you can then use margins to control whitespace manually:
div.column {
display: inline-block;
width: 30%;
margin-right: 3.33333333%;
margin-bottom: 10px;
}
You might wanna take a look at this article: Using inline-block to Display a Product Grid View (it uses <li>s instead of <div>s, but the idea is essentially the same)
Here's a FIDDLE
<div class="product-wrapper">
<div class="productindividualdisplay">
<div class="productphoto">
<img src="http://3.bp.blogspot.com/-_xP-UUa4D0c/UfAo1eYxURI/AAAAAAAAAT4/xsibNtxZceQ/s320/Books.jpg" alt="Smiley face" width="250" height="250">
</div>
<div class="producttitle">
Product Title
</div>
<div class="productprice">
<span>$100</span>
</div>
</div>
...more products...
</div>
.product-wrapper {
width: 960px;
padding: 10px;
}
.productindividualdisplay {
background: #fff;
display: inline-block;
width: 260px;
margin: 5px 5px 15px 5px;
padding: 10px;
text-align: center;
border: 1px solid #999;
box-shadow: 0 5px 6px -3px #333;
}
.productphoto {
width: 95%;
margin: 10px auto;
border-bottom: 1px solid #999;
}
.producttitle a {
font-size: 18px;
text-decoration: none;
}
.productprice {
font-size: 18px;
font-weight: 600;
}
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
?>
The image below explains what I am trying to achieve.
I need to show a user's car picture with the name under it. Each image/name pair should be in a DIV so as a user adds more cars, they move to the next line or page. Ideally the DIVs should be centered, more as a matter of aesthetics.
Using DOMPDF, I am generating a PDF from an HTML layout.
Unfortunately, DOMPDF's support for float is bad, even in the new 0.6.2 beta. I wonder if this layout I am proposing could be done without float. DOMPDF also does not support unordered lists.
I have tried some solutions using tables, but this also isn't good since DOMPDF does not allow cells to spill over to the next page.
I am using PHP 5/ codeigniter, and DOMPDF 0.5.2 (stable).
Any suggestions on how to get this layout are greatly appreciated!
Here is the code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
img {width: 150px; height: 150px;}
h1 {font-size: 3em; text-align: center;}
h2 {text-transform: uppercase; width: 150px; text-align: center;}
div {margin: 10px; width: 150px;}
</style>
</head>
<h1>My Cars</h1>
<?php foreach ($cars as $row): ?>
<div>
<img src="<?php echo $row->cars_picture; ?>" />
<h2><?php echo $row->cars_name; ?></h2>
</div>
<?php endforeach; ?>
</html>
Thanks to #rkw and #manyxcxi for helping out.
At the end the only way of doing this without hacks was to use mpdf instead of DOMPDF.
I have the impression mpdf is a much better library, with better documentation. It has partial support for float, but it works very nicely and does exactly what I needed above.
If the boxes are all fixed width and you know the width of your PDF, then you can calculate the boxes per row and use a spacer div on the left of the bottom row to give you the offset you're looking for.
Without using float, you would have to use instead of : http://jsfiddle.net/AxZam/40/
relevant css:
body {
width:800px;
}
#content {
margin: 0px auto;
width: 600px;
text-align: center;
}
img {
width: 150px;
height: 150px;
}
h1 {
font-size: 3em;
}
.cars {
text-transform: uppercase;
width:150px;
display:block;
position:absolute;
top:0px; left:0px; }
span {
margin: 10px;
position: relative;
}
relevant html section:
<div id='content'>
<h1>My Cars</h1>
<span>
<img />
<span class='cars'>car</span>
</span>
...
</div>
I am trying to get a div that resides in a container div to scale the container divs height when the div inside the container gets taller. When the height of the div inside the container gets taller than the container itself it just moves past the bottom of the container. I want the container to scale with the contained div. How do I do this in CSS?
Graham. What you describe is the default behavior of a DIV, or any block element for that matter. e.g. for the following HTML:
<style type="text/css">
dl { margin: 0; padding: 0;}
#container {
background-color: blue;
padding: 5px 5px 5px 5px;
}
#inner {
background-color: red;
}
</style>
<div id="container">
<div id="inner">
<dl>
<dt>Stuff</dt>
<dd>Blah blah blah</dd>
<dt>Foobar</dt>
<dd>Bazquux</dd>
</dl>
</div>
</div>
You will get the following rendered HTML:
(source: rackspacecloud.com)
The situation you describe when the container div doesn't expand to contain the inner div occurs when you have floated the inner div. Floating, by definition, breaks a block element out of the constraints of it's containing element. Applying "float: left;" to your #inner element gives the following:
(source: rackspacecloud.com)
The solution is to add a block level element at the bottom of the containing div that clears the floated element. This causes the containing div to wrap around this new block level element, and thus your floated elements as well.
e.g.
<style type="text/css">
dl { margin: 0; padding: 0;}
#container {
background-color: blue;
padding: 5px 5px 5px 5px;
}
#inner {
background-color: red;
float: left;
}
</style>
<div id="container">
<div id="inner">
<dl>
<dt>Stuff</dt>
<dd>Blah blah blah</dd>
<dt>Foobar</dt>
<dd>Bazquux</dd>
</dl>
</div>
<div style="clear: both;"></div>
</div>
This will give output identical to the first image.
Obviously, this can be a tedious thing to add to the bottom of your container divs if you do a lot of floating.
Using CSS2 you can do this with a simple class definition (and a hack for IE of course):
<style type="text/css">
dl { margin: 0; padding: 0;}
#container {
background-color: blue;
padding: 5px 5px 5px 5px;
}
.clearfix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
* html .clearfix {height: 1%;}
#inner {
background-color: red;
float: left;
}
</style>
<div id="container" class="clearfix">
<div id="inner">
<dl>
<dt>Stuff</dt>
<dd>Blah blah blah</dd>
<dt>Foobar</dt>
<dd>Bazquux</dd>
</dl>
</div>
</div>
Simply add the clearfix class to any of your container divs that contain floated elements. Note the "* html" is the hack required by IE.
You just need to give height property by percent such as:
percent { display:block:height:100%; } as your div stands in html:
<div class="percent"></div>
Simply add
overflow: auto;
to the outer div.
If you mean "scale" as in just simply expanding, perhaps I read your description as the container div having a height of, say, 500px, and the contained divs will push this out more if they grow too large. In that case, perhaps you can use min-height instead?
min-height: 500px;
If you mean "scale" as in the container div is 500x500px, the contained takes up an initial height of 200px that expands to 400px with more content, which pushes the container div to 1000x1000px (akin to zooming/enlarging), then that might be more complicated.