I put three HTML-elements in a row using inline-block: 2 images linking to external websites (green boxes in the image below) and one div-tag with a search-form an a language selection.
The problem is now, that next to the images - on their right sides - there is also a hidden link. To make it visible I set text-decoration:underline and a blue background in active mode (see image).
How can I limit the a href to only the images?
HTML code looks like that:
<div id="logo">
<a href="http://website1.example">
<img src="image1.gif">
</a>
<a href="http://website2.example">
<img src="image2.gif">
</a>
<div id="headermodules">
<form class="search" method="post" action="index.php">
<input type="text" value="Suchen...">
</form>
<div id="languageselection">
<ul class="languageselection">
<li id="active_language">
Deutsch
</li>
<li>
<a href="http://localhost:81/en/">English
</li>
</ul>
</div>
</div>
<span style="width: 100%;"></span>
</div>
The CSS looks like that:
#logo
{
position: relative;
height:129px;
text-align: justify;
z-index: 0;
border-top: 0px solid #000;
}
#logo img
{
display: inline-block;
vertical-align: middle;
}
#logo span
{
width: 100%;
height: 0;
display: inline-block;
}
#headermodules
{
display: inline-block;
vertical-align: middle;
}
You should have the a elements styled to inline-block and not the img. The img should be display: block. I think that should do it.
#logo a { display: inline-block; }
#logo img { display: block; }
Related
I checked a few posts here and managed to keep the text align in the middle of my user's icon, the question here is: as you can see if his name is too long it goes to the other line.
I was wondering if theres a way to reajust and keep the whole name in the middle of the icon?
Thanks in advance
here's my html:
<li class="user">
<a href="#"><img class="img-circle online" src="http://placehold.it/50">
<span>Nome do Usuário</span></a>
</li>
and my css:
.chat-list > li.user {
display: inline-table;
height: 50px;
margin-bottom: 5px;
width: 100%;
}
.user span {
display: inline-table;
margin-left: 8px;
width: 69%;
word-break: normal;
}
Try this
HTML:
<li class="user">
<a href="#"><img class="img-circle online" src="http://placehold.it/50">
<span>Nome do Usuário</span></a>
</li>
CSS:
.chat-list > li.user {
height: 50px;
margin-bottom: 5px;
width: 100%;
display:block;
}
.user a {display:table;text-align:left;}
.user a img {display:table-cell;width:50px;}
.user span {
display: table-cell;
margin-left: 8px;
width: 69%;
word-break: normal;
vertical-align:middle;
}
JSFiddle: http://jsfiddle.net/jdfx/La996vye/
TL:DR - Set the parent to display:table, and set the children as display:table-cell then add vertical-align:middle to your span.
I have done something similar on my website and solved it by applying this to the text:
span {
display:table-cell;
vertical-align:middle;
}
For this to work your parent tag needs to be shown as a table so:
a {
display:table;
}
http://jsfiddle.net/gk2dfngc/
I'm really struggling to achieve clean code whilst trying to get the layout I want.
My current code isn't behaving with other floating divs on the page and the bottom section with text and buttons are not displaying inline and are forcing other elements out of position.
JSFiddle: http://jsfiddle.net/XXe4L/
I've tried various rehashings of my code but can't figure it out and am at the point where I'm starting to pull my hair out.
I'm trying to acheive a layout similar to this wireframe - https://wireframe.cc/UTHU1d.
I've copied my latest code below, minus the bottom div with text and button because I've not been able to get that anywhere near right.
CSS:
.sceneItem { clear:both; display: block; margin: 0 auto; width: 100%; }
.scenePart { display: block; width: 100%; height: 360px; float: left; }
.imgLink { margin: 0; position: relative; }
.largeImage { display: block; width: 648px; height: 360px; float: left; }
.previewImage { width: 318px; height: 180px; display: block; margin-bottom: 3px; float: left; }
.previewImage a.imgLink { }
.img { display: inline; }
and HTML:
<li class="sceneItem">
<div class="largeImage scenePart">
<a href="" class="imgLink" title="">
<img src="24361_01_01.jpg" class="img" alt=""></a>
</div>
<div class="previewImage scenePart">
<a href="" class="imgLink" title="">
<img src="24361_01_01.jpg" class="img" alt=""></a>
</div>
<div class="previewImage scenePart">
<a href="" class="imgLink" title="">
<img src="24361_01_02.jpg" class="img" alt=""></a>
</div>
</li>
I am guessing that if your floats are interfering with each other, you might try creating a block formatting context for your floated images as follows:
.box {
width:970px;
overflow: auto;
}
By doing this, any elements following will not interact with the floated images.
Note: Without the additional page elements, I can't say for sure what the problem is.
I have the following Html Markup in my website:
<div id="header">
<div class="flyoutMenuButtons visible-phone">
<i class="icon-reorder icon-3x"></i>
<i class="icon-reorder icon-3x"></i>
</div>
<div id="logo_and_search">
<a id="logo" href="/" title="abc">
<img src="abc.png" height="40" width="136">
</a>
</div>
</div>
I would like the logo to be diaplayed in center for all device widths.
What style shall I apply to the "#logo" element in order make it display in center for all devices other than desktops and tablets?
use like this:
a#logo{
display: block;
text-align: center;
}
a#logo img{
display: inline-block;
}
something like this but if you give fiddle example it be fine
#logo_and_search {
width:100%;
}
#logo {
display: block;
margin: 0 auto;
}
#logo {
display: block;
width:136px; /* the same as the logo*/
margin: 0 auto;
}
I have the following div:
<div style="height: 200px">
Click to View
</div>
I want to click anywhere of the div tag and want to activate the tag means in short I want to click on the Div to navigate the link. How can I do that?
Update
I have to update my question:
I can not define the exact height of my <div>
I have to use 100% for height for <a>
My revised code is like that:
<div>
abc<br><br>
Click to View
</div>
This should do the trick for you
div {
height: 200px;
}
div a {
display: block;
height: 200px;
}
See it working here on jsfiddle
Make a Javascript function which calls the Link and attach it on the OnClick event of the DIV Element.
Or try something like:
<div id="Idhere" onclick="window.location = 'Link here'">
text here
</div>
Remove the div.
Click to View
then...
a.bigAnchor { display: block; height: 200px; }
You can try something like this:
.link {
width: 300px;
height: 200px;
background: #fc0;
}
.link a {
display: block; /* link as block element */
text-align: center;
height: 100%; /* height for all div */
color: #666; /* link color */
}
<div class="link">
Link
</div>
CHANGE THE ORDER
<a href="#">
<div style="height: 200px">
Click to View
</div>
</a>
Note: <div> inside <a> is legal is HTML5
try to change the anchor css:
a.block{display:block;height:200px;}
<div style="height: 200px">
<a class="block" href="#">Click to View</a>
</div>
a {
display: inline-block;
width: 100%;
height: 100%;
}
You can expand a to any parent you want using CSS:
<div id="parent">
<a href="#">
<span aria-hidden="true" class="expand"></span>
My Link
</a>
</div>
<style>
div#parent {
display: relative;
}
.expand {
display: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
</style>
So here is my markup. Solution has to work dynamically for a single line or double line in the span. So it should be css that can be added to each of these and work fine. From looking on the internez this seems to be impossible. Please prove me wrong.
<ul style="text-align:center; list-style-type: none;">
<li style="width: 200px">
<a href="http://www.bing.com" style="display: block; height:35px; background: Black;">
<span>Vertical Align This Text</span>
</a>
</li>
</ul>
<ul style="text-align:center; list-style-type: none;">
<li style="width: 200px">
<a href="http://www.bing.com" style="display: block; height:35px; background: Black;">
<span>Vertical Align This Text With Double Line As Well</span>
</a>
</li>
</ul>
This works for me:
<ul style="text-align:center; list-style-type: none;">
<li style="width: 200px; display: table">
<a href="http://www.bing.com" style="display: table-cell; height:35px; background: Black; vertical-align: middle; text-align:center">
<span>Vertical Align This Text</span>
</a>
</li>
</ul>
<ul style="text-align:center; list-style-type: none;">
<li style="width: 200px; display: table">
<a href="http://www.bing.com" style="display: table-cell; height:35px; background: Black; vertical-align: middle; text-align:center">
<span>Vertical Align This Text With Double Line As Well</span>
</a>
</li>
</ul>
CSS code for convenience:
ul {
list-style-type: none;
}
li {
width: 200px;
display: table;
}
a {
display: table-cell;
height: 35px;
background: black;
vertical-align: middle;
text-align: center;
}
Since your containing <a> have a set height value, you can use the ol' line-heighttrick of setting it to the same value, in this case:
a {
height:35px;
line-height:35px;
}
This will only work, though, if your <span> isn't wider than your <li>. In the case with the double line, you'd need to set the <line-height> to half the <a>'s height (35px height divided by 2 lines), so around 17px. If you had three lines, it would work with 35px/3 ~ 11px. But as you can imagine, it will look smooshed at one point.
So depending on the content you might have to with the relative/absolute positioning, a smaller font, or just less content ;)
Give your <li> and <a> the following CSS properties
li{
position:relative;
}
a{
position:absolute;
top:50%;
margin-top:-17px; /*negative half of your <a> tag height */
}
Check working example at http://jsfiddle.net/r4Wsx/