Can a line be centered around specific text using only css? - php

I want to have php generated navigation bar. It will consist of a left side with a list of links to the directories below the current one, a link to the index of the current directory, and the right side with a list of links to directories directly inside the current one.
tester1 > tester2 | index | tester4a tester4b
I would like to center this navigation bar around 'index', regardless of the length of the left or right. I know I could pad the arrays to equal length within the php that generates it, but I'm interested in whether or not I could do this with html and/or css.

Pretty easily actually. You may need to play with the widths to fit your context, but pretty straight forward.
<div class="main">
<div class="left">
stuff in here
</div>
<div class="center>
INDEX
</div>
<div class="right">
stuff in here too
</div>
</div>
CSS:
.main {
width: 410px;
text-align: center;
}
.main > div {
display: inline-block;
}
.left {
width: 175px;
text-align: right;
}
.center {
width: 50px;
text-align: center;
}
.right {
width: 175px;
text-align: left;
}
.main > div > * {
display: inline;
}
Fiddle HERE

Or you can try faking "float:center"

Related

div is misaligned when contents are put inside it

hi im pretty new to doing front-end stuff i have this div that contains this mini divs inside it when it only have a p tag input here is how it looks like
but when i added my code for its contents, the div misaligned
and now it looks like this
so fare here is the codes im working with
<div id="tabular" style="display:none">
#foreach($NSAdata as $list)
<div class="divcont">
<p>Filename :</p>{{$list->filename}}
</div>
#endforeach
</div>
.divcont
{
background-color: pink;
display: inline-block;
width: 300px;
height: 150px;
margin-bottom: 1%;
margin-right: 1%;
}
#tabular
{
height: 28.125em !important;
overflow-y: auto;
}
any idea what im doing wrong? or to improve my code?
Adding vertical-align: top; to your inline blocks should fix it.
.divcont {
...
display: inline-block;
vertical-align: top;
}
The reason is the default value of vertical-align is baseline, when your content inside the inline blocks has different length/height, that causes the mis-alignment.
Inline-block elements are whitespace dependent, which means spaces in your HTML are spaces on screen.
Try and remove the extra blank line at the start of your #foreach loop.
Also add white-space: nowrap; to the #tabular parent div

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

CSS how to align text inside sidebar

Well, I have sidebar but text(in my case tables) inside sidebar are not aligned like I want.
From one .php I call another inside sidebar, like this:
<div id="sidebar2"> <?php include("tiket.php");?></div>
Here is it CSS of sidebar:
#sidebar2 {
width: 240px;
float: right;
padding: 40px;
background: #264988;
color: #e1d2c7;
margin: 5px;
text-align:justify;
}
An this is how it looks:
How to put text on the left of the sidebar?
It would help a lot if you gave us the complete source code of the sidebar, or told us where it was located.
I think that the reason why the text is not aligned to the left is because you put in text-align:justify;. Remove that line.
#sidebar2 {
width: 240px;
float: right;
padding: 40px;
background: #264988;
color: #e1d2c7;
margin: 5px;
}
What justify does is spread the text out evenly, which can be unhelpful if you don't have much text.
You can nest with CSS3
#sidebar2 table {
text-align: left;
}
you can read more about it over here
https://www.w3schools.com/css/css_combinators.asp

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
?>

Scaling a Container div with the contained divs height

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.

Categories