On my website www.drivkrets.se I´m trying to insert a symbol (orange lines) before my headings using CSS :before. I´have been able to insert the image in the right size but now I would like to vertical align the symbol image with the text. When the heading is on one line or three lines I doesn´t look good. I´ve tried different variations of code but none of them works.
Does anyone have any idea how I should do this?
The headings that suppose to have this symbol before I´ve named ".specialrubrik". Now I´m using the code:
.specialrubrik:before {
content:url('http://www.drivkrets.se/wp-content/uploads/2017/03/orange-
marker-e1490098005864.png');
float: left;
margin-right: 12px;
display: inline-block;
vertical-align: middle;
height: 100%;
}
Best regards
Peter
This is a CSS question and has nothing to do with WordPress. You don't want to float inline-block elements, and vertical-align only works with display: inline-block elements.
.example-heading:before {
display: inline-block; /* no floats! 'middle' only works with inline-block */
content:url('http://www.drivkrets.se/wp-content/uploads/2017/03/orange-marker-e1490098005864.png');
vertical-align: middle;
margin-right: 12px;
}
<h2 class='example-heading'>Example heading</h2>
Thanks for your idea #sheriffderek. I still don´t get it right.
I´ve changed the code now and trying to use the :before on h2 instead.
h2:before {
content:url('http://www.drivkrets.se/wp-content/uploads/2017/03/orange-
marker-e1490098005864.png');
margin-right: 12px;
display: inline-block;
vertical-align: middle;
height: 100%;
}
h2 {
text-align: left;
display: -webkit-inline-box;
vertical-align: middle;
}
It works when I have a short heading but if the heading is two or three rows it looks strange. Example: "Kunskap och uppfinningsrikedom till era elsystem". Do you know how I can make all of the text to flow right of the symbol?
Peter
Related
I have a page with tab navigation at the top (page here; tabs are 'Production,' 'Story and Development,' etc). I would like to ensure the row of tabs are horizontally centered on the page. How can I accomplish that? If I'm not mistaken, it's currently a tad off center.
By following the instructions on the W3 Schools page on CSS centering, I came close by setting:
display: block;
margin: auto;
width: 99%;
But I'm not sure if that's the proper/best solution. Is there a solution that does not require setting width: 99%?
If it matters, the site has been built with WordPress.
Thanks.
You have two ways you could approach this:
The text-align: center Method
.ut-nav-tabs li {
display: inline-block;
float: none;
vertical-align: top;
}
.ut-nav-tabs li:last-child {
margin-right: 0px;
}
.ut-nav-tabs {
text-align: center;
}
This works only if you declare text-align: center on the containing parent - the parent element must be a block element. The nested children elements must be inline block elements (e.g: display: inline-block) with no float rules declared on them, floats will negate any attempt to horizontally center align elements this way, and most other ways.
The display: flex Method
.ut-nav-tabs {
display: flex;
justify-content: space-around;
}
.ut-nav-tabs li {
float: none;
margin-right: 0px;
}
This is the "new kid" on the block and the "hot fix" for any alignment issue concerning CSS these days, I would hazard to say it is the "jQuery" of CSS now.
Anyway, it is for good reason, flex-box rules allows you to specify general alignment (horizontally and vertically) and lets the browser do all the calculations for precise positioning - this is also why is a popular responsive solution too.
Browser Compatibility: A heads-up though, flex-box has poor or very limited support for legacy browsers, older browsers may give you unexpected results, so you should use this with caution in production code if that will be a concern.
I think this way is better :
.ut-nav-tabs {
width: 100%;
text-align: center;
}
.ut-nav-tabs li {
width: 179px;
float: none;
display: inline-block;
zoom: 1;
vertical-align: middle;
}
I have 3 spans inside a div.
<div class="align">
<span class="a">Title</span>
<span class="b">Someinfomation</span>
<span class="c">Toright</span>
</div>
for making the c class to align vertically, I have to use margin-top to fix it
however, for IE7 looks differently.
Here is online sample: http://jsfiddle.net/wZmGQ/
Yes, I want IE7 works as well.
If someone could help me with a better solution?Thanks
Solution is shown below, for someone who looks for IE7 solution
Got the answer from float: right in IE7 dropping to a new line
Try to small change markup: place items with a float before items
without it (from the same row). It should help.
Whenever you float an element, you are implicitly declaring display:block. So when you write the following code:
.some-element {
display: inline-block;
float: right;
}
... is the same exact thing as doing this:
.some-element {
display: inline-block;
display: block;
float: right;
}
... but I realize that doesn't help you much. Check out this fiddle, sorry I can't test in IE7 at the moment, but see if this helps get you in the right direction:
http://jsfiddle.net/ryanwheale/wZmGQ/3/
Essentially this:
.align{
border: 1px solid black;
line-height: 35px; /* larger than your largest font size */
}
.a, .b, .c {
vertical-align: middle;
}
Create an ie only stylesheet. http://css-tricks.com/how-to-create-an-ie-only-stylesheet/
Hello a small problem here that im struggling to fix. Tried vertical-align with no joy and have ran out of ideas.
You can see why frontpage blocks HERE
The title below the picture is sitting towards the top of that area when the title only takes up one line. I was hoping to make it appear in the middle of that area between the picture and the group title below. Could anyone suggest anything?
Thanks
ul.views-fluid-grid-items-center li.views-fluid-grid-item {
background: none repeat scroll 0 0 black;
position: relative;
}
li.views-fluid-grid-item .views-field-title {
padding: 0 4px;
}
As I marked, all the black part in your website are fixed in height, just use display: table-cell along with vertical-align: middle and you are good to go
li.views-fluid-grid-item .views-field-title a {
color: #AAAAAA;
display: table-cell;
height: 40px; /* Fix appropriate height here */
vertical-align: middle;
}
You could add line-height: 37px; to li.views-fluid-grid-item .views-field-title a
but then you would have to cut off the text from going onto two lines..
Edit: I'll leave this on here for reference but I prefer Mr. Alien's answer
I am trying to align div and all my efforts using float and margins didn't bring what I want. So I thought this is the right place
basically looping the below in Foreach:
<div class="comment_name">#Html.displayName</div>
<div class="comment_time">#Html.formattedDateTime(item.dTime.Value)</div>
<div class="comment_body">#item.displayComments</div>
and am trying to display like the below text:
Dispaly Name , 11 Feb 2013: User entered comment.
What should be the CSS to make it work?
Updated after Span answer
Span worked. But am having issues if the length of comment is long. am getting like below
Dispaly Name , 11 Feb 2013:The example will show you how to implement a read-only grid. This article tries to answer the following question
but which should be
Dispaly Name , 11 Feb 2013:The example will show you how to implement a read-only grid.
this article tries to answer the following question
You can use float: left on every div and clear: left; for the first one;
Demo: http://jsfiddle.net/9mfR8/
div {
border: 1px solid red;
float: left;
}
.comment_name{
clear: left;
}
Or you can use display: inline-block; for the three divs and enclose them in a container div (that is display: block by default and will force a "new line"),
Personally I would say use <span>s instead of <div>s as they are already inline elements:
<span>#Html.displayName</span>
<span>#Html.formattedDateTime(item.dTime.Value)</span>
<span>#item.displayComments</span>
If you want to stick to <div>s use:
display: inline;
or if the single containers have for example a fixed width:
display: inline-block;
Edit
To achieve the result in your updated question, you can use this:
HTML
<span>Dispaly Name,</span>
<span>11 Feb 2013:</span>
<span> The example will show you how to implement a read-only grid. This article tries to answer the following question.
</span>
CSS
span {
vertical-align: top;
}
span:last-child {
display: inline-block;
width: 400px;
}
DEMO
http://jsfiddle.net/jkZeZ/
The following should achieve what you require:
.comment_name {
display: inline-block;
}
.comment_time {
display: inline-block;
}
.comment_body {
display: inline-block;
}
I have a Span tag containing a IMG tag and another Span tag.
I would like the inner Span tag to be aligned to the left and the IMG tag to be centrally aligned plus I want both the tags to be vertically aligned in the middle, and I can't seem to get this right...
This is how it looks (It's blue because the outer Span tag is marked in FireBug to show that it's stretching the entire surface):
As you can see in the image, both tags are centred and they are also aligned in the top of the container, I don't want either of this.
This is the markup:
This is the current CSS of the tags:
.v-button-wrap {
height: 100%;
display: block;
padding: 6px 15px 0 9px;
vertical-align: middle;
line-height: normal;
text-align: center;
}
.v-icon {
margin-left: auto;
margin-right: auto;
vertical-align: middle;
line-height: normal;
text-align: center;
}
.v-button-caption {
text-align: left;
line-height: normal;
vertical-align: middle;
}
I left out the CSS that isn't relevant for my problem, colors, font-specs and such. Needless to say I'm no ace at CSS. And I've looked up several guides covering the problem, but I've only managed to find examples where the entire content of a div is centered, and that's not what I want.
Does anyone with good CSS knowledge see the problem in my code? Or have another solution to solve my problem..?
Thanks!
EDIT: Here's a screen shot of the entire layout due to request. Sorry I have to blur some things... but they are in either case not important. =)
EDIT2: I did manage to solve my problem using the following CSS:
.v-button-details-panel-header .v-button-wrap {
height: 100%;
text-align: inherit;
padding: 0px;
}
.v-button-details-panel-header .v-button-wrap .v-button-caption {
display: table-cell;
position: relative;
text-align: left;
}
.v-button-details-panel-header .v-button-wrap .v-icon {
display: table-cell;
position: relative;
top: 12px;
margin-left: auto;
margin-right: auto;
}
I'm sure the advice dgvid proposed would have been good for a static layout. But since the panels and horizontally stretched buttons move depending on expansion and collapsing that wasn't a fitting solution.
You might need to set the CSS display property of both your img and span.v_button_caption to inline-block.
See also this article: Understanding vertical-align, or "How (Not) To Vertically Center Content"
As for another technique to achieve the desired result: If you know the height of the container element and you know the height of the element to be centered (and unfortunately from the CSS you've posted, it does not appear that you do), then you could
Give the container element CSS property `position: relative'
Give the element-to-be-centered CSS property position: absolute
Set the CSS top property of the element-to-be-centered to (containerHeight / 2) - (centeredEltHeight / 2).