Hello I have read a few articles of people with similar struggles to me but none of the solutions seem to work for me.enter image description here
I am trying to create something like the picture attached but the text always seems to go underneath the image, whatever CSS I edit.
.newstitle {
background-color: #ffed00;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: 20px;
display: inline-block;
}
.newspic img {
padding: 20px;
height: 300px;
vertical-align: middle;
}
<section class="main">
<div class="newspic">
<img src="https://placehold.it/500x300" alt="Photo placeholder">
</div>
<div class="newstitle">
D'votion presents his bassline remix of Post Malone's Rockstar
</div>
</section>
Just place the text container inside the div with the image.
<section class="">
<div class="newspic">
<img src="Art portfolio/illustrations/IMG_0844.JPG" alt="Photo placeholder">
<div class="newstitle">
D'votion presents his bassline remix of Post Malone's Rockstar
</div>
</div>
</section>
Why not try this instead:
HTML
<section class="main">
<div class="newspic">
<img src="https://images.unsplash.com/photo-1476124861542-44354851e622?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&s=eac3b3d003e83c809de608dd6dcc3857" alt="Photo placeholder">
</div>
<div class="newstitle">
D'votion presents his bassline remix of Post Malone's Rockstar
</div>
</section>
CSS
.main {
display: flex;
justify-content: space-between;
}
.newspic {
width: 50%;
}
.newspic img {
max-width: 100%;
}
You can view it here: https://codepen.io/jobaelish/pen/QaxXww
This is a simple fix.
Nonetheless, if you're HTML is not being affected, then you need to make sure your stylesheet is linked in your document head element properly.
<link rel="stylesheet" type="text/css" href="PATHTOCSSHERE">
There are "several" ways to accomplish this task. One way is to just add display inline on your side text and float the picture to the left. Also set a width on your picture. You could also use flexbox or you could of just used float with the text in the same div as the picture.
.newstitle{
background-color: #ffed00;
font-family : Arial, Helvetica, sans-serif;
font-weight : bold;
font-size: 20px;
display: inline;
}
.newspic img{
width: 300px;
float: left;
padding: 20px;
height: 300px;
vertical-align: middle;
}
<section class="main">
<div class="newspic">
<img src="https://www.google.com/logos/doodles/2018/zhou-youguangs-112th-birthday-5826412689752064-law.gif" alt="Photo placeholder">
</div>
<div class="newstitle">
D'votion presents his bassline remix of Post Malone's Rockstar
</div>
</section>
I removed the <div> container for the <img> and passed the class="newspic" to the image. Then I positioned both .newstitle and .newspic relatively to their parent and gave them width:70% and width:30%; respectively.
The key here, since you are using paddings is to include box-sizing:border-box; into both classes so the paddings are taken account for when calculating the width.
Here is the working code: (run the snippet & try full screen)
.main{
}
.newstitle
{
position:relative;
float:left;
width:70%;
background-color: #ffed00;
font-family : Arial, Helvetica, sans-serif;
font-weight : bold;
font-size: 16px;
box-sizing:border-box;
}
.newspic
{
position:relative;
float:left;
padding: 20px;
width:30%;
height: auto;
box-sizing:border-box;
}
<section class="main">
<img class="newspic" src="https://i2.wp.com/farm3.staticflickr.com/2883/9197736562_3cce3c65ee_o.jpg" alt="Photo placeholder" />
<div class="newstitle">
<p>D'votion presents his bassline remix of Post Malone's Rockstar</p>
</div>
</section>
Related
I start to learn HTML and on my website in the middle of the top there should be a heading in the center. In the left top corner, there is a picture.
If I want to set the heading with align="center"; into the middle I can only set it into the middle between the right end of the picture and the right end of the Display...
I hope it's understandable and someone can help me!
The code is:
<div style="float:left; width=600px; height=152px;">
<img src="bilder/logo.jpg" height="54px" width="214px" hspace="0" vspace="0"/>
</div>
<p>
<h1 align="center" style="margin-top:15px; margin-bottom:20px;"><u>Peter Möhle</u></h1>
</p>
enter image description here
It should look like the Picture at the Bottom but this was made mith margin-left and isnt a fixed Position if i use another browser or display
I've updated your snippet as you are using deprecated tags. Happy to hear and clear your doubts, if you have any.
Ref: W3 CSS, W3 HTML
.nav {
width: 100%;
}
.logo-holder {
float: left;
height: 50px;
width: 100px;
}
.logo {
height: 100%;
width: 100%;
}
.nav-text {
text-align: center;
text-decoration: underline;
}
<div class="nav">
<div class="logo-holder">
<img class="logo" src="bilder/logo.jpg" />
</div>
<div class="nav-text">
<h1>Peter Möhle</h1>
</div>
</div>
You can use text-align: center; to centre text, but as mentioned in the comments you are using some deprecated tags.
<h1 style="margin-top: 15px; margin-bottom: 20px; text-align: center; text-decoration: underline;">Peter Möhle</h1>
It's even better to remove the style attribute and create a css file to put the styles in.
CSS
h1 {
margin-top: 15px;
margin-bottom: 20px;
text-align: center;
text-decoration: underline;
}
I'd also change the div markup to
<div style="float: left; width: 600px; height: 152px;">
<img src="bilder/logo.jpg" style="height: 54px; width: 214px;">
</div>
I've used padding to the left now using relative value
<div style="float:left; width=600px; height=152px;">
<img src="bilder/logo.jpg" height="54px" width="214px" hspace="0" vspace="0"/>
</div>
<p>
<h1 style="margin-top:15px; margin-bottom:20px; padding-left: 50% "><u>Peter Möhle</u></h1>
</p>
Everything seems to be positioned where I want it but the image and video will overlap the jumbotron on the smaller size. I have checked other posts and have not found anything useful to answer my question. I should clarify that it comes out at the right side of the jumbotron.
<style>
body {
margin: 20px;
}
#img_position {
position: relative;
left: 14%;
padding: 15px;
max-width: 100%;
}
#jumbo
{
background-color: #bfff80;
font-family: 'Cinzel', serif;
min-width: 100%;
}
.gw_vid{
position:relative;
padding-top:5%;
max-width:32%;
margin:0 auto;
}
</style>
<div class="container box ">
<div id="jumbo" class="jumbotron box">
<h1 style="text-align: center">George Washington</h1>
<h4 style="text-align:center">The first President of the Untited States of America</h4>
<img id="img_position" src="http://projectmanagementhacks.com/wp-content/uploads/2015/03/George-Washington-Success-Principles.jpg">
<div class="gw_vid">
<iframe width="350px" height="350px" src="https://www.youtube.com/embed/thin1LeCrxY" target="blank"></iframe>
</iframe>
</div>
</div>
I added col-md-12 to my picture and that resolved that issue for now but I tried the col-md-12 with the video and got no good results.
Any help with the video issue would be great.
I put your code into Codepen and It told me i don't need tags, first of all after i took out the style tags i ran the code and it looks perfectly fine. I beleive solution here is to create a new file for the CSS then link them in the head. If you don't know how to do that, here is the code
<link rel="stylesheet" type="text/css" href="nameoffyourfile.css"
**HTML**
<div class="container box ">
<div id="jumbo" class="jumbotron box">
<h1 style="text-align: center">George Washington</h1>
<h4 style="text-align:center">The first President of the Untited States of
America</h4>
<img id="img_position" src="http://projectmanagementhacks.com/wp-
content/uploads/2015/03/George-Washington-Success-Principles.jpg">
<div class="gw_vid">
<iframe width="350px" height="350px"
src="https://www.youtube.com/embed/thin1LeCrxY" target="blank"></iframe>
</iframe>
</div>
</div>
**CSS**
body {
margin: 20px;
}
#img_position {
position: relative;
left: 14%;
padding: 15px;
max-width: 100%;
}
#jumbo {
background-color: #bfff80;
font-family: 'Cinzel', serif;
min-width: 100%;
}
.gw_vid {
position: relative;
padding-top: 5%;
max-width: 32%;
margin: 0 auto;
}
Since you are using Bootstrap, you can use the native responsive embed for your YouTube video: http://getbootstrap.com/components/#responsive-embed
I am trying to get text to vertically align to the middle but can't seem to get it to work.
HTML:
<div class="row">
<div class="col-md-4">
Login
</div>
<div class="col-md-4">
Menu
</div>
<div class="col-md-4">
Contact
</div>
</div>
CSS:
.custom-button {
color:#ECDBFF;
background-color:#4F0100;
display:inline-block;
height: 220px;
font-family:Verdana, Geneva, sans-serif;
font-size:20px;
font-weight:bold;
text-align:center;
text-decoration:none;
}
.width-100 {width: 100%;}
I have googled quite a bit and tried a couple of things but i can't seem to get the text to go to the middle. can anyone advise what i would need to add/change to get this to work.
If your have a text which is restricted to single line then line-height would be the best solution.
try with this
line-height:220px; /*height of your container */
JsFiddle Demo
You can as well use vertical-align a pseudo element (:before or :after ) and an extra box (inline-block) to allow content to wrap on a few lines : see and run snippet below.
.custom-button {
color: #ECDBFF;
background-color: #4F0100;
display: inline-block;
height: 220px;
font-family: Verdana, Geneva, sans-serif;
font-size: 20px;
font-weight: bold;
text-align: center;
text-decoration: none;
}
.width-100 {
width: 100%;
}
.custom-button:before {
display:inline-block;
content:'';
height:220px;
vertical-align:middle;
margin:-0 -0.25em;;
}
a span {display:inline-block;
vertical-align:middle;
}
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"/>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css"/>
<div class="row">
<div class="col-md-4 col-xs-4">
Login
</div>
<div class="col-md-4 col-xs-4">
Menu
</div>
<div class="col-md-4 col-xs-4">
<span>Cont<br/>act</span>
</div>
</div>
I am adding an image in HTML which is the title for the page. When I add it, it overlaps the rest of the content that comes after that. I need the rest of the content to adapt accordingly. Not sure how to do this.
My code looks like this:
HTML:
<div class="page_book"><div class="book_wrapper"><div class="book_content"> <!-- start description for page 1-->
<div class="title"><img src="img/soho_page1_image_0.png" alt="Introduction" width="30" height="50"></div>
<img src="pages/page_1.jpg" />
<p>This content.</p>
</p>
</div></div></div><!-- end description for page 1-->
<div class="meta">
<span class="num">1</span>
</div>
<div class="gradient"></div><div class="loader"></div>
</div>
CSS:
.title
{
position:absolute;
left: 20px;
}
.page_book img {
width: 70%;
margin: 10px auto;
display: block;
cursor: pointer;
}
.page_book p {
line-height: 20px;
}
I tried removing the .title class but the image covers the whole width.
Try:
.title
{
position:relative;
margin-left: 20px;
}
Also, use
.title img{
margin:0px;
width:auto;
}
The image currently inherits the styles of .page_book img and that's what's causing all the mess..
Next time adding a jsFiddle to the question would be helpful
I would like to know what the best way is to format the following layout:
(with eveything aligned and spaced neatly):
Here is the HTML:
<div class"wrapper">
<img alt="Image 1" src="images/image1.png" />
<div class="description">
<h1>Heading 1</h1>
<p>Paragraph 1</h1>
</div>
</div>
I tried the following but the vertical-align property does not seem to be working as I cannot align the top of the h1 with the top of the image:
img, div.description {
float: left;
}
div.description { margin-left: 10px; vertical-align: top; }
h1 { background: blue; }
p { background: red; }
What if instead of how the right hand side part is displayed below,
we wanted the right hand side to also be vertically centered instead
of being top aligned?
Here is the JSFiddle link:
http://jsfiddle.net/johngoche99/ZPKZj/1/
OK, to keep the text from dropping down below when the browser is resized it is necessary to specify the width of the wrapper element to something like 700px. Then it works.
Thanks.
in css you need to do this
img{
float: left;
height: 300px
}
div{
float: left;
}
h1{
padding: 10px;
background-color: #584480;
color: #fff;
font-weight: normal;
font-size: 25px;
margin: 0 0 10px 10px;
}
p{
padding: 10px;
background-color: #E24480;
color: #fff;
font-weight: normal;
font-size: 25px;
margin: 0 0 10px 10px;
}
nothing more ...
Hope this will help you ...
This can be accomplished with simple CSS.
img, div{
float: left;
margin: 10px;
}
http://jsfiddle.net/ZPKZj/2/
IRL, do NOT use this CSS. It is far too generic to be useful in any production environment. You might give your elements IDs or classes to allow the rules to be much more specific.
It looks you markup need a little change to be more, khm right;
HTML:
<div id="all">
<div id="sidebar">
<img class="side_image" alt="Image 1" src="http://images.nationalgeographic.com/wpf/media-live/photos/000/005/cache/green-iguana_563_600x450.jpg" />
</div>
<div id="main">
<h1>Heading 1</h1>
<p>Paragraph 1</h1>
</div>
</div>
CSS:
#sidebar { float: left; }
#sidebar { margin-right: 40px; }
h1 {
margin-bottom: 30px;
margin-top: 0;
}
link to look how it will be:
http://jsfiddle.net/56Z7C/1/
I think you want something like this:
JSFIDDLE
You want to use css here. You will add an ID to the first div like <div id="wrapper"> this is your main div. Then in the second div you add <div id="headings"> for the headings. then in your css add the beneath code. (note: this isn't the best css code ever. but it works :))
html:
<div id="wrapper">
<img alt="Image 1" src="http://images.nationalgeographic.com/wpf/media-live/photos/000/005/cache/green-iguana_563_600x450.jpg" />
<div id="headings">
<h1>Heading 1</h1>
<p>Paragraph 1</h1>
</div>
</div>
css:
#wrapper{
width: 960px;
margin: 0 auto;
}
#wrapper img{
float: left;\
margin-right: 40px;
padding-right: 40px;
}
#headings{
position: relative;
float: left;
}
h1{
margin-top: -5px;
}
Hope it helps!
Vertical-align only works on tables. If you want to do that with divs, you could try using display: table:
<div class="table">
<div class="row">
<div class="cell">
<img alt="Image 1" width="100" src="http://images.nationalgeographic.com/wpf/media-live/photos/000/005/cache/green-iguana_563_600x450.jpg" />
</div>
<div class="cell" id="stuff">
<h1>Heading 1</h1>
<p>Paragraph 1</p>
</div>
</div>
</div>
And the CSS:
.table { display: table; }
.row { display: table-row; }
.cell { display: table-cell; }
#stuff { vertical-align: middle; }
This has the advantage of not being dependent on sizes/margins of elements, but is unsupported in IE7 and below. As all things in life, display: table is a tradeoff.