In my first div container, I added a heading 1 tag, gave a border bottom a color of my desire, and added font awesome icon in the middle.
As you can see I had to give a background color on the font awesome to make it appear transparent. but now I have a background image on the second box so I am struggling to achieve the same thing.
How can I do the same on my other div box without affecting the background image
visibility as well as the border bottom from the heading 1?
div.container{
background-image: url(http://az616578.vo.msecnd.net/files/2016/04/09/6359580807140768861266757027_Never-Study-Hard-The-Art-of-Studying-Smart.jpg);
background-size: cover;
background-position: 50%;
}
div{
height: 100px;
}
h1.widget_title_1{
font-size: 25pt;
display: inline-block;
margin: 0;
margin-top: 35px;
padding-bottom: 9px;
border-bottom: 1px solid #898989;
position: relative;
}
h1.widget_title_1:after {
position: absolute;
font-family: fontawesome;
display: block;
margin-left: 58px;
margin-top: -7px;
padding: 0 5px;
font-size: 24pt;
color: black;
content: '\f107';
font-weight: 300;
background-color: white;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<div class="container-1">
<h1 class="widget_title_1">
heading 1
</h1>
</div>
<div class="container">
<h1 class="widget_title">
heading 1
</h1>
</div>
I suggest you to use font-awesome icons along-with tag as here I have used i tag, it get's easy to align icon i.e. at center of that div tag, just by using text-align:center. Then you can use pseudo selector :before and :after on h1 tag and add that border. Scale to and fro on this jsFiddle and see border doesn't get's attached at certain screen resolution.
.container-1 {
height: 100px;
display: inline-block;
overflow: hidden;
}
.container-1 > .widget_title_1 {
font-size: 25pt;
margin: 0;
display: inline-block;
position: relative;
}
.container-1 > .fa {
font-size: 24px;
display: block;
height: 30px;
text-align: center;
}
.container-1 > .widget_title_1:before {
content: "";
position: absolute;
width: 50%;
height: 2px;
background: #111;
bottom: -38%;
left: 0;
margin-left: -10px;
}
.container-1 > .widget_title_1:after {
content: "";
position: absolute;
width: 50%;
height: 2px;
background: #111;
bottom: -38%;
margin-right: -10px;
right: 0;
}
.container {
background-image: url(http://az616578.vo.msecnd.net/files/2016/04/09/6359580807140768861266757027_Never-Study-Hard-The-Art-of-Studying-Smart.jpg);
background-size: cover;
background-position: 50%;
height: 100px;
overflow: hidden;
}
.container > .widget_title {
font-size: 25pt;
margin: 0;
display: inline-block;
position: relative;
}
.container > .fa {
font-size: 24px;
display: block;
height: 30px;
width: 138px;
text-align: center;
}
.container > .widget_title:before {
content: "";
position: absolute;
width: 50%;
height: 2px;
background: #111;
bottom: -38%;
left: 0;
margin-left: -10px;
}
.container > .widget_title:after {
content: "";
position: absolute;
width: 50%;
height: 2px;
background: #111;
bottom: -38%;
margin-right: -10px;
right: 0;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<div class="container-1">
<h1 class="widget_title_1">
heading 1
</h1>
<i class="fa fa-angle-down"></i>
</div>
<div class="container">
<h1 class="widget_title">
heading 1
</h1>
<i class="fa fa-angle-down"></i>
</div>
Use :before :after for div for the line.
Create a span tag with the font awesome as shown below.
div.container{
background-image: url(http://az616578.vo.msecnd.net/files/2016/04/09/6359580807140768861266757027_Never-Study-Hard-The-Art-of-Studying-Smart.jpg);
background-size: cover;
background-position: 50%;
}
div{
position: relative;
height: 100px;
}
h1.widget_title_1{
font-size: 25pt;
display: inline-block;
margin: 0;
margin-top: 35px;
padding-bottom: 9px;
border-bottom: 1px solid #898989;
position: relative;
}
span:after {
position: absolute;
font-family: fontawesome;
display: block;
margin-left: 58px;
margin-top: -7px;
top:40px;
padding: 0 5px;
font-size: 24pt;
color: black;
content: '\f107';
font-weight: 300;
background-color: transparent;
}
div.container:after{
content: "";
position: absolute;
height: 5px;
border-bottom: 1px solid black;
top: 45px;
width: 60px;
}
div.container:before{
content: "";
position: absolute;
height: 5px;
border-bottom: 1px solid black;
top: 45px;
left:90px;
width: 60px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<div class="container-1">
<h1 class="widget_title_1">
heading 1
</h1>
</div>
<div class="container">
<h1 class="widget_title">
heading 1
</h1>
<span></span>
</div>
Related
I am trying to position a div over another by using position: relative; & position: absolute;. I have made use of this successfully previously in the project, however it isn't given the desired outcome/working on the second use of it. All it is doing is displaying the second div under the first.
HTML
<header>
<img class="header-img" src="https://i.pinimg.com/222x/ec/c6/f2/ecc6f20889bba2976601a3abb029183c.jpg">
<div class="header-text left"> ToKa Fitness</div>
</header>
<div>
<div class="offer"></div>
<div class="sign-in"></div>
</div>
CSS
header {
width: 100%;
height: 120px;
position: relative;
border: 2px black solid;
}
img.header-img {
width: 122px;
height: 122px;
position: absolute;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
text-align: center;
}
div.header-text {
width: 100%;
position: absolute;
padding-top: 42px;
font-family: articulat-cf, sans-serif;
font-style: normal;
font-weight: 700;
font-size: 30px;
text-align: center;
}
div.offer {
width: 100%;
height:30px;
position: relative;
border: 2px green solid;
}
div.sign-in {
width: 120px;
height: 30px;
position: absolute;
top: 132px;
right: 4px;
border:2px red dashed;
}
I am aiming for the smaller red div to go on top of the green div above it to the far right. I have tried using top and right to assist with positioning it but to no obvious effect on the program.
position absolute places an element relative to its parent's position. if you want to set the position of div.sign-in absolute, it should have a parent with "relative" position
<header>
<img
class="header-img"
src="https://i.pinimg.com/222x/ec/c6/f2/ecc6f20889bba2976601a3abb029183c.jpg"
/>
<div class="header-text left"> ToKa Fitness</div>
</header>
<div>
<div class="offer"><div class="sign-in"></div></div>
</div>
and CSS file:
header {
width: 100%;
height: 120px;
position: relative;
border: 2px black solid;
}
img.header-img {
width: 122px;
height: 122px;
position: absolute;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
text-align: center;
}
div.header-text {
width: 100%;
position: absolute;
padding-top: 42px;
font-family: articulat-cf, sans-serif;
font-style: normal;
font-weight: 700;
font-size: 30px;
text-align: center;
}
div.offer {
width: 100%;
height:30px;
position: relative;
border: 2px green solid;
}
div.sign-in {
width: 120px;
height: 30px;
position: absolute;
right: 0;
border:2px red dashed;
}
can you add screenshot of how it looks like?
When minimized and scaled to different positions some the text and background shift to different spots making text shift off the screen or on top of other text or links.
body,
html {
margin: 0;
padding: 0;
}
.gamepage {
position: relative;
height: 100vh;
width: 100vw;
background-size: 100%;
}
/* tabbar */
.header {
position: sticky;
top: 0px;
left: 0px;
height: 10vh;
width: 100%;
background: url("https://www.waukeepubliclibrary.org/sites/default/files/Event%20Images/Teen%20Events/MurderMystery_TopBanner-1024x265.jpg") no-repeat 50% 50%;
background-size: cover;
z-index: 2;
}
#home {
position: absolute;
top: 0px;
left: 0px;
border-style: groove;
}
#how2play {
position: absolute;
top: 0px;
left: 47px;
border-style: groove;
}
#character {
position: absolute;
top: 0px;
left: 137px;
border-style: groove;
}
/* link format */
a:link,
a:visited {
color: white;
text-decoration: none;
font-weight: bold;
}
/* background */
.background {
positon: absolute;
background: url("https://imagevars.gulfnews.com/2021/07/05/shutterstock_1016099710-1625487358677_17a7698bad7_large.jpg") no-repeat;
height: 100%;
width: 100%;
top: 72px;
left: 8px;
background-size: cover;
z-index: 1;
}
#title {
color: white;
position: absolute;
top: 90px;
left: 5px;
font-size: 35px;
font-family: Courier New;
}
#text {
color: white;
position: absolute;
top: 125px;
left: 25px;
}
#playbutton {
color: black;
position: absolute;
top: 360px;
left: 660px;
font-size: 55px;
font-weight: bold;
transform: rotate(-7deg);
border: 5px;
border-style: double;
}
<body>
<div class="gamepage">
<div class="header">
<div id="home">
Home
</div>
<div id="how2play">
How to Play
</div>
<div id="character">
Character List
</div>
</div>
<div class="background">
<div id="title">Murder Mystery</div>
<div id="text">Find the murderer, before it's too late...</div>
<a href="homepage/thegame1.html">
<div id="playbutton">Play Now</div>
</a>
</div>
</div>
</body>
I've Tried
Changing all values to %'s
Changing all the values using vh and vw.
This fixed some of the problem but not all
Played around with the absolute and relative positioning/adding div parent tags
All this is very new to me so there might be a simple solution I don't know of
Your HTML and CSS should look something like the example below.
Here I have swapped out your IDs for semantic HTML elements, and absolute positioned elements for modern flexbox/grid
Look into flexbox and grid for single axis and dual axis positioning
body {
display: grid;
grid-template-rows: 30% 1fr;
min-height: 100vh;
margin: 0;
color: white;
background-color: black;
}
header {
background: url("https://www.waukeepubliclibrary.org/sites/default/files/Event%20Images/Teen%20Events/MurderMystery_TopBanner-1024x265.jpg") no-repeat 50% 50%;
background-size: cover;
}
header ul {
display: flex;
gap: 1rem;
min-height: 10vh;
list-style: none;
}
a:link,
a:visited {
display: inline-block; /* Allows for padding and your rotation of [Play Now] */
color: inherit;
padding: .2em .5em;
background: #000b;
text-decoration: none;
font-weight: bold;
}
main {
background: url("https://imagevars.gulfnews.com/2021/07/05/shutterstock_1016099710-1625487358677_17a7698bad7_large.jpg") no-repeat;
padding: 2rem;
background-size: cover;
}
h1 {
font-size: 2.5rem;
font-family: Courier New;
}
.playbutton {
color: black;
font-size: 3.5rem;
font-weight: bold;
transform: rotate(-7deg);
border: 5px;
border-style: double;
}
<!-- Use semantic HTML instead of divs with IDs -->
<header>
<nav>
<ul>
<li>
Home
</li>
<li>
How to Play
</li>
<li>
Character List
</li>
</ul>
</nav>
</header>
<main>
<h1>Murder Mystery</h1>
<p id="text">Find the murderer, before it's too late...</p>
Play Now
</main>
here is a fiddle link
.authorTag {
float: right;
position: absolute;
right: 0px;
top: 0px;
z-index: 1000;
background-color: #92AD40;
padding: 5px;
color: #FFFFFF;
font-weight: bold;
cursor: pointer;
}
.DateTag {
float: right;
position: relative;
right: 0px;
top: 0px;
z-index: 1000;
background-color: #92AD40;
padding: 5px;
color: #FFFFFF;
font-weight: bold;
cursor: pointer;
}
.tag {
float: left;
position: absolute;
left: 0px;
top: 0px;
z-index: 1000;
background-color: #92AD40;
padding: 5px;
color: #FFFFFF;
font-weight: bold;
cursor: pointer;
}
.DivTitle {
float: left;
position: absolute;
left: 0px;
bottom: 0px;
z-index: 1000;
background-color: #92AD40;
padding: 5px;
color: #FFFFFF;
font-weight: bold;
cursor: pointer;
width: 100%;
}
.contentContainer {
position: relative;
width: 300px;
height: 300px;
/* top:0;
left:0;*/
border: 1px solid black;
margin: 5px;
}
<div class="contentContainer">
<div class="tag">Featured</div>
<div class="authorTag">authorTag</div>
<div class="DateTag">Time</div>
<img src="https://dummyimage.com/100/000000/fff" width="100%">
<div class="DivTitle"> Title </div>
</div>
Fiddle Link
the scenario
a container div
image fill the container div (No Problem if it is background of the container div)
Title div at the bottom of the container
four div in every corner in the remaining space
Note : the Title div with dynamic text which means it might be one or more lines
image of the desired output
Hope the following code helps. I made the image as the background image with background-size: cover;. Also I separated the tags into top and bottom section, and used float left and right to position the tags.
.contentContainer {
position: relative;
width: 300px;
height: 300px;
border: 1px solid black;
margin: 5px;
background: url('https://dummyimage.com/100/000000/fff') no-repeat center center;
background-size: cover;
}
.topTags {
position: absolute;
top: 0;
left: 0;
width: 100%;
}
.bottomTags {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
}
.tag {
width: auto;
z-index: 1000;
background-color: #92AD40;
padding: 5px;
color: #FFFFFF;
font-weight: bold;
box-sizing: border-box;
}
.left {
float: left;
}
.right {
float: right;
}
.divTitle {
width: 100%;
clear: both;
}
<div class="contentContainer">
<div class="topTags">
<div class="tag left">Featured</div>
<div class="tag right">authorTag</div>
</div>
<div class="bottomTags">
<div class="tag left">Time</div>
<div class="tag right">Bottom Left</div>
<div class="tag divTitle">Title can be very long. Title can be very long. Title can be very long.</div>
</div>
</div>
Solution 2, image as <img>
.contentContainer {
position: relative;
width: 300px;
height: 300px;
border: 1px solid black;
margin: 5px;
}
.bgImage {
position: absolute;
width: 100%;
height: 100%;
}
.topTags {
position: absolute;
top: 0;
left: 0;
width: 100%;
z-index: 1000;
}
.bottomTags {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
z-index: 1000;
}
.tag {
width: auto;
background-color: #92AD40;
padding: 5px;
color: #FFFFFF;
font-weight: bold;
box-sizing: border-box;
}
.left {
float: left;
}
.right {
float: right;
}
.divTitle {
width: 100%;
clear: both;
}
<div class="contentContainer">
<div class="topTags">
<div class="tag left">Featured</div>
<div class="tag right">authorTag</div>
</div>
<img class="bgImage" src="https://dummyimage.com/100/000000/fff" />
<div class="bottomTags">
<div class="tag left">Time</div>
<div class="tag right">Bottom Left</div>
<div class="tag divTitle">Title can be very long. Title can be very long. Title can be very long.</div>
</div>
</div>
Here is an alternate solution. By placing the bottom tags in the title bar we can position them relative to it.
.background {
position: absolute;
top: 0px;
left: 0px;
z-index: 999;
}
.topLeft {
position: absolute;
top: 0px;
left: 0px;
z-index: 1000;
background-color: #92AD40;
padding: 5px;
color: #FFFFFF;
font-weight: bold;
cursor: pointer;
}
.topRight {
position: absolute;
top: 0px;
right: 0px;
z-index: 1000;
background-color: #92AD40;
padding: 5px;
color: #FFFFFF;
font-weight: bold;
cursor: pointer;
}
.bottomLeft {
position: absolute;
bottom: 100%;
left: 0px;
z-index: 1000;
background-color: #92AD40;
padding: 5px;
color: #FFFFFF;
font-weight: bold;
cursor: pointer;
}
.bottomRight {
position: absolute;
bottom: 100%;
right: 0px;
z-index: 1000;
background-color: #92AD40;
padding: 5px;
color: #FFFFFF;
font-weight: bold;
cursor: pointer;
}
.bottomBar {
position: absolute;
bottom: 0px;
left: 0px;
z-index: 1000;
background-color: #92AD40;
padding: 5px;
color: #FFFFFF;
font-weight: bold;
cursor: pointer;
/* Remove padding left and right from width*/
width: calc(100% - 10px);
}
.contentContainer {
position: relative;
width: 300px;
height: 300px;
border: 1px solid black;
margin: 5px;
}
<div class="contentContainer">
<img class="background" src="https://dummyimage.com/100/000000/fff" width="100%">
<div class="tag topLeft">Featured</div>
<div class="authorTag topRight">authorTag</div>
<div class="bottomBar">
<div class="otherTag bottomLeft">Other</div>
<div class="dateTag bottomRight">Time</div>
<div class="divTitle">Title - this can be any amount of text, bottom tags will move up.</div>
</div>
</div>
Here you go. Your issue was that the image should be a background image set to the container div. Then you need to add a background size to "cover" to get it to fit. Next you had some screwed up css. Your "Divtitle" class had a padding set so it forced it to go out of bounds. If you want padding top or left or bottom use "padding-left", "padding-right", ect. I also added an extra container div with a set height and width so that way "contentContainer" can be set to 100% width and height with the image but nor screwing anything up.
Here is your fiddle with the corrections: https://jsfiddle.net/32vg2466/1/
HTML:
<div style="width: 250px; height: 250px;">
<div class="contentContainer" >
<div class="tag">Featured</div>
<div class="authorTag">authorTag</div>
<div class="DateTag">Time</div>
<div class="DivTitle"> Title </div>
</div>
</div>
CSS:
.authorTag
{
float: right;
position: absolute;
right: 0px;
top: 0px;
z-index: 1000;
background-color: #92AD40;
padding: 5px;
color: #FFFFFF;
font-weight: bold;
cursor:pointer;
}
.DateTag
{
float: right;
position: relative;
right: 0px;
top: 0px;
z-index: 1000;
background-color: #92AD40;
padding: 5px;
color: #FFFFFF;
font-weight: bold;
cursor:pointer;
}
.tag {
float: left;
position: absolute;
left: 0px;
top: 0px;
z-index: 1000;
background-color: #92AD40;
padding: 5px;
color: #FFFFFF;
font-weight: bold;
cursor:pointer;
}
.DivTitle {
float: left;
position: absolute;
left: 0px;
bottom: 0px;
z-index: 1000;
background-color: #92AD40;
color: #FFFFFF;
font-weight: bold;
cursor:pointer;
width: 100%;
}
.contentContainer{
position:relative;
width:100%;
height:100%;
/* top:0;
left:0;*/
border:1px solid black;
margin:5px;
**background-image: url("https://dummyimage.com/100/000000/fff");
background-position: center;
background-size: cover;**
}
I'm trying to create a badge, containing a hexagon with a number in it. The badge/list-item itself would contain some info/name.
this is what I have so far:
.item {
display: block;
background-color: blue;
}
.item > span {
color: white;
display: inline-block;
}
.hexagon {
position: relative;
width: 65px;
height: 65px;
line-height: 65px;
text-align: center;
color: white;
}
.hexagon span {
position: absolute;
color: white;
z-index: 2;
left: 30;
}
.hexagon:before {
color: #ef473a;
position: absolute;
content: "\2B22";
font-size: 65px;
z-index: 1;
width: 100%;
height: 100%;
left: 0;
top: 0;
}
<div class="item">
<div class="hexagon"><span>1</span></div>
<span class="title">TEST test</span> <!-- maximum width? > new line -->
<span class="info">something darkside</span>
</div>
This is what I'm trying to achieve:
As you can see, the "blue" background should only start at the tip of the hexagon. Width and height of it, aren't going to change. So now I'm wondering whether it would be easier to use an image or if someone could help me recreate the image, would be fine too :)
Thanks in advance!
Try the flexbox way, it's made for your case since you have three items (medal, title, description) that you want to have vertically aligned in the middle next to each other.
Below is a starting point, you can probably extend that to your needs by yourself.
Please note that I also changed the way the hexagon is created, it's not using an UTF8 character now but simply colored borders. This gives you more control about the size of the actual hexagon shaped medal.
Standing on one of its tips, the height of this hexagon is equivalent with its diameter (d) which in turn is twice as long as one of the six lines (s) forming the hexagon. The width (w) of this hexagon is then: s * sqrt(3) or .5 * d * sqrt(3).
.badge {
height: 64px;
margin-left: 35px;
color: white;
font-family: sans-serif;
background: blue;
border: 1px solid transparent;
display: flex;
align-item: middle;
}
.medal {
position: relative;
margin-left: -30px;
min-width: 75px;
}
.count {
position: absolute;
width: 58px;
text-align: center;
line-height: 64px;
font-size: 30px;
top: -16.74px;
}
h3 {
max-width: 40%;
margin-right: 30px;
font-size: 14px;
}
p {
font-size: .875em;
}
.hexagon {
position: relative;
width: 58px;
height: 33.49px;
background-color: #ff2600;
margin: 14.74px 0 16.74px 0;
}
.hexagon:before,
.hexagon:after {
content: "";
position: absolute;
width: 0;
border-left: 29px solid transparent;
border-right: 29px solid transparent;
}
.hexagon:before {
bottom: 100%;
border-bottom: 16.74px solid #ff2600;
}
.hexagon:after {
top: 100%;
width: 0;
border-top: 16.74px solid #ff2600;
}
<div class="badge">
<div class="medal">
<div class="hexagon">
<div class="count">1</div>
</div>
</div>
<h3>The HEXAGON Badge Quest</h3>
<p>You successfully posted a valid question on Stack Overflow and received an answer.</p>
</div>
Try the following. I haven't tested on mobile. Just chrome at this point, but it should get you close. You'll need to play around with the text somewhat to handle the wrapping and sizing inside the blue bar, but your question was in regards to the badge. The corner effects are clipping the shape by about 10px. So setting a fixed height on the bar and a 10px taller height on the hexagon did the trick. Then just some positioning and margin to move things into position. Good luck.
.item {
display: block;
background-color: blue;
height: 66px;
position: relative;
left: 35px;
width: 100%;
}
.item > span {
color: white;
display: inline-block;
}
.hexagon {
display: inline-block;
position: relative;
width: 66px;
height: 66px;
line-height: 66px;
text-align: center;
color: white;
top: 0;
left: -35px;
}
.hexagon span {
position: absolute;
color: white;
z-index: 2;
width: 66px;
height: 66px;
line-height: 66px;
text-align:center;
left: -0;
}
.hexagon:before {
color: #ef473a;
position: absolute;
content: "\2B22";
font-size: 76px;
z-index: 1;
width: 66px;
height: 66px;
left: 0;
top: -5px;
}
.title {
position: absolute;
font-size: 1.75rem;
top: 12px;
left: 33px;
margin: 0;
text-align:center;
display:block;
height: 66px;
width: 20%;
line-height: 18px;
}
.info {
position: absolute;
top: 0px;
left: 20%;
margin: 0;
text-align:center;
display:block;
height: 66px;
width: 70%;
line-height: 66px;
vertical-align: center;
}
<div class="item">
<div class="hexagon"><span>1</span></div>
<span class="title">TEST test</span> <!-- maximum width? > new line -->
<span class="info">something darkside</span>
</div>
There is some layout:
.block {
background: #aaa;
width: 300px;
height: 150px;
position: relative;
}
.contents {
position: absolute;
bottom: 0;
left: 10px;
line-height: 1;
font-size: 30px;
}
.contens > * {
vertical-align: baseline;
}
.content1 {
display: inline-block;
width: 20px;
height: 20px;
background: #000;
}
.content2 {
font-size: 45px;
}
<div class="block">
<div class="contents">
<span class="content1"></span>
<span class="content2">Foo</span>
<span class="content3">Bar</span>
</div>
</div>
How to make text baseline of .contents be pushed to the bottom of the .block regardless of the font face?
Expected result:
Shifting down the .contents block by bottom: -0.1em; is not suitable because font faces have different baseline level.
Changed line-height to 0, added overflow:hidden
.block {
background: #aaa;
width: 300px;
height: 150px;
position: relative;
overflow:hidden;
}
.contents {
position: absolute;
bottom: 0;
left: 10px;
line-height:0;
font-size: 30px;
}
.contents > * {
vertical-align: baseline;
}
.content1 {
display: inline-block;
width: 20px;
height: 20px;
background: #000;
}
.content2 {
font-size: 45px;
}
<div class="block">
<div class="contents">
<span class="content1"></span>
<span class="content2">Foo</span>
<span class="content3">Bar</span>
</div>
</div>
Just set css line-height: 0;
See : http://codepen.io/ivoglent/pen/KzaWNG