I have a custom html box within Joomla with the following
<span style="color: #FFFFFF; font-size: 1em; padding-top:5px;">
<p style="float: right; display: inline-block; white-space: nowrap; margin-bottom: 5px;"><img src="/images/telephone_call_contact.png"> 0000000000</p>
<br>
<p style="float: right; display: inline-block; white-space: nowrap;"><img src="/images/email_envelope.png"> contact#email.co.uk</p>
<br>
<p style="float: right; display: inline-block; white-space: nowrap;"><img src="/images/shop_open.png"> Open 7 Days 5:00pm-11:00pm </p>
</span>
This works fine. However, when the browser is resized down to a certain level one will come undone until you resize even further.
Similarly, at another dimension they'll also not align properly.
Does anyone know why this behaviour is occurring?
EDIT: As Antonio suggested, adding clear:both to p in the CSS partially resolved this issue. Now the issue occurs only on the first line (when it didn't before)
Add clear:both to your p css rules
example.
I think that adding a clear:right should solve your issue, but I can't be so sure as the images in your snippet do not load.
<span style="color: #FFFFFF; font-size: 1em; padding-top:5px;">
<p style="float: right; display: inline-block; white-space: nowrap; margin-bottom: 5px;"><img src="/images/telephone_call_contact.png"> 0000000000</p>
<br>
<p style="float: right; display: inline-block; white-space: nowrap;clear:right;"><img src="/images/email_envelope.png"> contact#email.co.uk</p>
<br>
<p style="float: right; display: inline-block; white-space: nowrap;clear:right;
"><img src="/images/shop_open.png"> Open 7 Days 5:00pm-11:00pm </p>
</span>
You would better forget using inline styles for your markup, as it has SEO downsides. instead use an external stylesheet.
Also, your markup has some problems, so you'd better do it like this:
.details{
text-align: right;
background-color: #744C27;
}
.details span{
display: inline-block;
vertical-align: middle;
color: #FFFFFF;
font-size: 1em;
white-space: nowrap;
}
.icons{
width: 32px;
height: 32px;
margin-right: 20px;
background-repeat: no-repeat;
}
.phone{ background-image: url( 'images/telephone_call_contact.png' ) }
.email{ background-image: url( 'images/email_envelope.png' ) }
.shop{ background-image: url( 'images/shop_open.png' ) }
<div class="details">
<div><span class="icons phone"></span><span>0000000000</span></div>
<div><span class="icons email"></span><span>contact#email.co.uk</span></div>
<div><span class="icons shop"></span><span>Open 7 Days 5:00pm-11:00pm</span></div>
</div>
Related
I'm currently working on an old website that was created with some old crappy WYSIWYG editor. I'm new to web-dev and still trying to get my head around positioning elements properly. My current issue is, from what I have read, using absolute positioning is BAD, but how would you change this?
So this is the old code:
<div id="wb_Text1"
style="margin:0;
padding:0;
position:absolute;
left:187px;
top:24px;
width:83px;
height:147px;
text-align:left;
z-index:1;
border:0px #C0C0C0 solid;
overflow-y:hidden;
background-color:transparent;
">
<div style="font-family:'.Helvetica Neue DeskInterface';font-size:15px;color:#000000;">
<div style="text-align:left">
<span style="font-family:Arial;font-size:43px;color:#FFFFFF;">
<strong>W</strong>
</span>
</div>
<div style="text-align:left">
<span style="font-family:Arial;font-size:43px;color:#FFFFFF;">
<strong>A</strong>
</span>
</div>
<div style="text-align:left">
<span style="font-family:Arial;font-size:43px;color:#FFFFFF;">
<strong>C</strong>
</span>
</div>
</div>
And what I have come up with to replace it is:
HTML
<div class="logo-ul">
<ul>
<li>W</li>
<li>A</li>
<li>C</li>
</ul>
</div>
CSS
.logo-ul {
list-style-type: none;
color: white;
font-size: 2em;
z-index:24;
float: right;
margin-right: 80%;
}
Which looks fine until you collapse the window and it falls apart :( lol.
You can see what I'm doing here http://media.wacmotorcycles.co.uk/
How should I be writing this please?
Thanks.
Try changing #logo to
#logo {
max-width: 165px;
max-height: 171px;
margin: 0.75em 0;
float: left;
}
And, .logo-ul to
.logo-ul {
list-style-type: none;
color: white;
font-size: 2em;
z-index: 24;
float: left;
}
There is nothing inherently wrong with absolute positioning. If used incorrectly, it can have unexpected results when working with responsive layouts.
In your specific case, the W A C might be better implemented as part of the logo image itself rather than text. It's not offering any semantic or SEO benefit to include the letters in a list. Short of that, this is one way to implement what I think you're after:
.logo {
height: 6rem;
padding-left: 50px;
}
.logo-letter {
display: block;
height: 2rem;
}
<div class="logo">
<span class="logo-letter">W</span>
<span class="logo-letter">A</span>
<span class="logo-letter">C</span>
</div>
I have a link with main title and description, and I would like to wrap the description line according to the width of the first line. Can I achieve that by using only CSS?
I have following code:
<a href="http://google.com">
<span class="ht">Oficiální stránky</span>
<span class="hb">Podívejte se na oficiální web festivalu</span>
</a>
https://jsfiddle.net/kybernaut/9uh24zns
Desired output:
Note: there will be more links in the line with different width of the first bold title.
Here's sneaky way of achieving this effect.
.limit {
border: 1px solid red;
display: table;
width: 1%;
}
.ht {
color: black;
font-size: 24px;
font-weight: bold;
white-space: nowrap; /* stop text wrapping */
}
.hb {
color: #555;
font-size: 18px;
display: block;
}
<a href="http://google.com" class="limit">
<span class="ht">Oficiální stránky</span>
<span class="hb">Podívejte se na oficiální web festivalu</span>
</a>
You could try the CSS table + table-caption solution.
.container {
display: table;
}
.hb {
display: table-caption;
caption-side: bottom;
}
<a class="container" href="#">
<span class="ht">FIRST LINE</span>
<span class="hb">second line some example content here</span>
</a>
jsFiddle
You may use
word-wrap property but None of the major browsers support the text-wrap property.
.ht {
color: black;
font-size: 24px;
font-weight: bold;
display: block;
}
.hb {
color: #555;
font-size: 18px
}
#wrapDiv{
width: 190px;
word-wrap: normal
}
<div id="wrapDiv">
<a href="http://google.com">
<span class="ht">Oficiální stránky</span>
<span class="hb" >Podívejte se na oficiální web festivalu</span>
</a>
</div>
You can also refer, it's same as How to word wrap text in HTML?
I have been looking everywhere for help on this issue with Css layout width I have been running into.
Whenever I float a div to the right its width won't automatically adjust to the total width of its children. I have observed this effect on all common browsers (Firefox, Chrome and IE11/Edge). What happens is that the last child will just be displayed bellow all the others which is what I do not want.
Here is the css and html I have been using.
https://jsfiddle.net/xqpf9s95/2/
*
<div id="header-container">
<div id="header-top-container">
<div id="header-logo">
<a href="/GlobalImagens/pages/imagens.xhtml?categoria=ultima-hora">
<img src="../resources/images/logo_globalimagens.jpg" alt="Global Imagens"></a>
</div>
<div class="header-top-right-corner">
<form id="language" name="language" method="post" action="/GlobalImagens/pages/imagens.xhtml" enctype="application/x-www-form-urlencoded">
<input name="language" value="language" type="hidden">
<div id="newsletter" class="newsletter">
Subscrever Newsletter
</div>
<div style="float: right; padding-left: 6%;">
<script type="text/javascript" src="/GlobalImagens/javax.faces.resource/jsf.js.xhtml?ln=javax.faces&stage=Development"></script>
<a href="#" style="text-decoration:none; " onclick="mojarra.jsfcljs(document.getElementById('language'),{'language:j_idt31':'language:j_idt31','localeCode':'en'},'');return false">
<img src="../resources/images/flag_uk.jpg" border="0"></a>
</div>
<div style="float: right;">
<a href="#" style="text-decoration:none;" onclick="mojarra.jsfcljs(document.getElementById('language'),{'language:j_idt35':'language:j_idt35','localeCode':'pt'},'');return false">
<img src="../resources/images/flag_pt.jpg" border="0"></a>
</div>
<input name="javax.faces.ViewState" id="j_id1:javax.faces.ViewState:0" value="215900126811062761:3093351618596041247" autocomplete="off" type="hidden">
</form>
</div>
<div id="admin-container">
<div>
<span class="admin-menu1" style="padding-left: 1.5%;">Iniciar Sessão
</span>
<span class="dotted-separator"></span>
<span style="padding-left: 1.5%;">Registo
</span>
<span class="admin-menu3"><a href="/GlobalImagens/pages/entrar.xhtml">
<img src="../resources/images/bt_minhaconta.jpg" title="A Minha conta" alt="A Minha conta"></a>
</span>
<span class="dotted-separator"></span>
<span class="admin-menu4"><a href="/GlobalImagens/pages/entrar.xhtml">
<img src="../resources/images/bt_carrinho.jpg" title="Meu carrinho" alt="Meu carrinho"></a>
</span>
</div>
<div>
<div align="right">
<span style="color: #83266f; padding-right: 5px;">Não pode adquirir imagens</span>(detalhes)
</div>
</div>
</div>
</div>
/*tables header*/
.admin-menu1 {
padding-right: 1.5%;
}
.dotted-separator {
border: none;
border-left: 1px dotted #83256f;
color: #fff;
/* background-color:#dadada;
height:17px;
width:0%;
margin: 0%; */
}
.admin-menu2 {
padding-left: 10px;
background: url(../images/background_dot.jpg) no-repeat right;
}
.admin-menu-logged-in-3 {
padding-left: 1.5%;
}
.admin-menu3 {
/* width: 75px; */
}
.admin-menu4 {
/* width: 28px; */
}
/*******************************HEADER*******************************/
#header-container {
/* height: 180px; */
/* float: left; */
}
#header-top-container {
/* width: 983px; */
/* height: 100px; */
/* float: left; */
}
#header-logo {
padding-top: 1%;
float: left;
}
#header-logo img {
border: none;
border-style: none;
}
.newsletter {
float: left;
padding-top: 1%;
}
.header-top-right-corner {
float: right;
padding-top: 1%;
width: 11%;
}
#admin-container {
padding-top: 1%;
font-size: 10px;
clear: right;
float: right;
box-sizing: border-box;
}
#admin-container a {
text-decoration: none;
color: #493641;
}
#admin-container a:hover {
text-decoration: underline;
}
*
And my issue is with the div "#admin-container".
How do I fix this so as to make that div auto adjust to the correct width and display without breaking its children elements?
Cheers and thank you.
EDIT: I have editted the code as asked by #Dzijeus. As I have commented, the images don't matter for the issue. My issue is with why the width won't auto adjust on the '#admin-container' to fit all its children.
Thanks for updating the code, it was better, but still far from a minimum verifiable example. A minimum example is when you strip as much as you can from the code while still reproducing the problem.
In your case, if you had done the exercise, you would probably have come to something like this:
<div id="admin-container">
<span class="admin-menu1">Iniciar Sessão</span>
<span>Registo</span>
<span>A Minha conta</span>
<span>Meu carrinho</span>
</div>
.admin-menu1 {
padding-right: 1.5%;
}
#admin-container {
clear: right;
float: right;
}
And you would immediately have seen the interest of doing this, AND solved the problem. Because from here, it is easy to notice that the problem is coming from using a relative padding. Switch to for example padding-right: 2px, and the display is now as you expected it.
As a general rule, padding and margin does not apply to inline elements such as span. To apply padding or margin you should use display: block or display: inline-block
So this is actually more of a question why that is and not how I fix it. I could easily make a hack and just give the middle two strings classes that position them correctly, but I would like to know why that is and how I can properly fix it.
Heres an image to show what I mean. All 4 divs have the same code, just different images and text, still the middle two have the "XXXX players" on a different position.
Heres my html and css code:
.lp-popular {
height: 705px;
}
.lp-popular .title {
margin-top: 91px;
margin-left: 457px;
}
.lp-popular .game {
display: inline-block;
width: 240px;
height: 383px;
background-color: rgba(8, 9, 11, 0.5);
margin-top: 35px;
margin-left: 6px;
margin-right: 6px;
}
.lp-popular .game .heart {
float: left;
margin-top: 21px;
margin-left: 20px;
}
.lp-popular .game span {
float: left;
margin-left: 12px;
margin-top: 10px;
font-weight: 500;
font-size: 18px;
color: #ffffff;
}
.lp-popular .game p {
float: left;
margin-left: 15px;
font-family: Arial;
font-weight: normal;
font-size: 14px;
color: rgba(255, 255, 255, 0.5);
}
<div class="lp-popular">
<img class="title" src="img/lp_popular_header.png">
<div align="center">
<div class="game">
<img src="img/lp_popular_game_lol.png">
<img class="heart" src="img/lp_popular_heart_full.png">
<span>League of Legends</span>
<p>4000 Spieler</p>
</div>
<div class="game">
<img src="img/lp_popular_game_dota.png">
<img class="heart" src="img/lp_popular_heart_empty.png">
<span>DotA 2</span>
<p>4000 Spieler</p>
</div>
<div class="game">
<img src="img/lp_popular_game_csgo.png">
<img class="heart" src="img/lp_popular_heart_empty.png">
<span>CS:GO</span>
<p>4000 Spieler</p>
</div>
<div class="game">
<img src="img/lp_popular_game_hs.png">
<img class="heart" src="img/lp_popular_heart_empty.png">
<span>Hearthstone</span>
<p>4000 Spieler</p>
</div>
</div>
</div>
Thanks in advance!
Add the following line of CSS to clear the floats of the game title:
.lp-popular .game p {
clear: both;
}
why the middle images have different location for 'XXXX players': reason is pretty simple. note that first and last images have string length of 17 characters including space [League of Legends] and 10 characters [Heartstone] which fills up the the whole width available for that row. but in case of middle images, the string lenght is 6 [DOTA 2] and 5 [CS:GO] which is not enough to fill that top row. Hence the next text/string comes up to fill this gap and there-hence you get the 'XXXX players' on the same row instead of second row despite of having same css rules for them.
Fix: as #Ryan and #Akatosh have already given suggestion on how to fix this i.e.
.lp-popular .game p {
clear: both;
// clear: left;
}
I have a collection of divs as rows that can be variable width as they are inside a resizable container. The div contains text that I want to have a hanging indent. This works fine except in this example the first line is pushed underneath the red label when the width is too low.
When .wrapper is 450px everything is displayed properly. When it's 250px you can see how things break. I always want the longtextthatwraps span to be on the same line as the red label.
Here's a live example/fiddle and the source is as follows:
HMTL (there is no whitespace between .prefix and .part but for readability...):
<div class="wrapper">
<div class="padded excludes">
<div class="parts first">
<span class="prefix">Quisques: </span>
<span class="segment level-0">
<span class="part text">longtextthatwraps incorrectly (0000-0000)</span>
</span>
</div>
<div class="parts">
<span class="segment level-0">
<span class="part text">consectetur adipiscing (0000-0000)</span>
</span>
</div>
<div class="parts">
<span class="segment level-0">
<span class="part text">quisque non mauris sed:</span>
</span>
</div>
<div class="parts">
<span class="segment level-1">
<span class="part list-item">hendrerit (0000-0000)</span>
</span>
</div>
<div class="parts">
<span class="segment level-1">
<span class="part list-item">non mauris sed (0000-0000)</span>
</span>
</div>
<div class="parts">
<span class="segment level-1">
<span class="part list-item">lorem ipsum dolor (0000-0000)</span>
</span>
</div>
</div>
</div>
CSS:
.wrapper {
width: 250px;
background: #c3dff5;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
}
.padded {
padding-left: 20px;
}
.parts {
padding-left: 80px;
}
.parts.first {
padding-left: 0;
}
.prefix {
color: #D12;
font-weight: bold;
min-width: 80px;
display: inline-block;
}
.level-0,.level-1 {
display: inline-block;
padding-left: 5px;
text-indent: -5px;
outline: 1px dotted #f0f;
}
.level-1 {
padding-left: 20px;
}
Help appreciated
Hmmm, I believe I have a CSS solution to your problem, though I'm sure there are other ways out there to get the behaviour you're looking for.
For .prefix, I gave the style:
.prefix {
display: table-cell;
}
And then I added another definition:
.parts.first .level-0 {
display:table-cell;
}
I hope this is what you're looking for! Here's the updated JSFiddle to show you what it results in. If this isn't your objective, please let me know and I'll be happy to help you further!
What if you remove the first class, move the span.prefix out of div.parts and add a position: absolute to it?
JsFiddle
Update (css only)
For a css-only solution remove the first class, give a position: absolute to span.prefix and specify left position, for example left: 25px. This seems to work in IE7, too.
Updated JsFiddle
Use position:absolute; and margin-left.
.first > .prefix{
position: absolute;
left:10px;
}
.first > .level-0{
margin-left:80px;
}
Lines 17-24 of this fiddle
I created a simplified version that will float each section, one to right and section to left and gives them a percent unit. Try to add your indent levels.
<div class="wrapper">
<div class="left">
<span class="red">Quisques: </span>
</div>
<div class="right">
<span class="level">consectetur adipiscing (0000-0000)</span>
<span class="level">quisque non mauris sed:</span>
<span class="level">consectetur adipiscing (0000-0000)</span>
</div>
</div>
CSS
.wrapper {
width: 250px;
background: #C3DFF5;
overflow: hidden;
padding: 12px;
}
.red {
color: red;
font-weight: bold;
}
.left {
float: left;
width: 30%;
}
.right {
float: right;
width: 70%;
}
.level {
display: block;
outline: 1px dotted #FF00FF;
}
Live demo http://jsbin.com/apaqop/1/
Please see this Demo
You have to add in CSS like
.wrapper {
width: auto;
background: #c3dff5;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
min-width:250px;
float:left;
}