让文本显示在导航栏下(Getting text to appear under navbar)
我想让我的文字出现在屏幕中间。 我已经完成了这个工作,但是我认为我已经在编码方面做得不好,我想看看是否有更好的方法可以不做。
所以我这样做的方式是
.homeMess { position: absolute; top: 50%; left: 50%; margin-top: -109px; margin-left: -725px; }
但使用
margin-left: -725px;
我并不了解,所以试图寻找另一种方式。我的html:
<div class="parallax"> <div class="navbar navbar-default navbar-fixed-top" role="navigation"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <div class="logo"><img src="Images/logo1.png"></div> </div> <div id="navbar" class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li><a href="#">a</a></li> <li><a href="#">b</a></li> <li><a href="#">c</a></li> <li><a href="#">d</a></li> </ul> </div><!--/.nav-collapse --> </div> </div> <div class="container"> <div class="homeMess "> <h1> a| v </div> </div> </div>
CSS:
body { font-family: 'Open Sans', sans-serif, Arial; font-size: 16px; color: #6D6D6D; background-color: #F5F5F5; font-weight: 300; } h1,h2,h3,h4,h5,h6 { font-family: 'Montserrat', sans-serif, Arial; padding-bottom: 5px; color: #373432; line-height: 1em; font-weight: normal; } a { text-decoration: none; outline: none; } .parallax { background-image: url("../Images/back1.jpg"); min-height: 1000px; background-attachment: fixed; background-position: center; background-repeat: no-repeat; background-size: cover; width: 100%; } .parallax1 { min-height: 1000px; } .container { margin: 0; width: auto; } .navbar-nav { float: right; margin-top: -15px; } .navbar-nav>li>a { line-height: 6px; } .navbar { padding-top: 46px; padding-right: 60px; font-size: 13px; text-transform: uppercase; } .navbar-default { background-color: transparent; border-top: 0px solid rgba(0, 0, 0, 0.5); border-bottom: 0px solid rgba(0, 0, 0, 0.5); border-left: 0px solid rgba(0, 0, 0, 0.5); border-right: 0px solid rgba(0, 0, 0, 0.5); -webkit-transition: background-color 200ms linear; -moz-transition: background-color 200ms linear; -o-transition: background-color 200ms linear; -ms-transition: background-color 200ms linear; transition: background-color 200ms linear; height: 87px; } .navbar-default .navbar-nav>li>a { color: #ffffff; } .navbar-default .navbar-nav > li > a:hover, .navbar-default .navbar-nav > li > a:focus { background-color: #F8BD23; text-decoration: none; color: #ffffff; -webkit-transition: background-color 200ms linear; -moz-transition: background-color 200ms linear; -o-transition: background-color 200ms linear; -ms-transition: background-color 200ms linear; transition: background-color 200ms linear; } .navbar-nav > li{ padding-left:30px; } .logo { margin-left: 40px; margin-top: -17px; } .homeMess { position: absolute; top: 50%; left: 50%; margin-top: -109px; margin-left: -725px; } .homeMess h1 { font-size: 100px; text-transform: uppercase; font-weight: 900; font-size: 60px; letter-spacing: -5px; line-height: 50px; color: white; }
所以我只是想让
homeMess
教室的课程处于屏幕中间,但我的做法并不好。 另外我正在使用bootstrap v3。I want to get my text to appear in the middle of the screen. I have done this but I think I have done this in a bad way of coding and I want to see if there is a better way of doing it without doing.
So the way I did it was
.homeMess { position: absolute; top: 50%; left: 50%; margin-top: -109px; margin-left: -725px; }
but using
margin-left: -725px;
is not amazing I know so trying to find another way.My html:
<div class="parallax"> <div class="navbar navbar-default navbar-fixed-top" role="navigation"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <div class="logo"><img src="Images/logo1.png"></div> </div> <div id="navbar" class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li><a href="#">a</a></li> <li><a href="#">b</a></li> <li><a href="#">c</a></li> <li><a href="#">d</a></li> </ul> </div><!--/.nav-collapse --> </div> </div> <div class="container"> <div class="homeMess "> <h1> a| v </div> </div> </div>
CSS:
body { font-family: 'Open Sans', sans-serif, Arial; font-size: 16px; color: #6D6D6D; background-color: #F5F5F5; font-weight: 300; } h1,h2,h3,h4,h5,h6 { font-family: 'Montserrat', sans-serif, Arial; padding-bottom: 5px; color: #373432; line-height: 1em; font-weight: normal; } a { text-decoration: none; outline: none; } .parallax { background-image: url("../Images/back1.jpg"); min-height: 1000px; background-attachment: fixed; background-position: center; background-repeat: no-repeat; background-size: cover; width: 100%; } .parallax1 { min-height: 1000px; } .container { margin: 0; width: auto; } .navbar-nav { float: right; margin-top: -15px; } .navbar-nav>li>a { line-height: 6px; } .navbar { padding-top: 46px; padding-right: 60px; font-size: 13px; text-transform: uppercase; } .navbar-default { background-color: transparent; border-top: 0px solid rgba(0, 0, 0, 0.5); border-bottom: 0px solid rgba(0, 0, 0, 0.5); border-left: 0px solid rgba(0, 0, 0, 0.5); border-right: 0px solid rgba(0, 0, 0, 0.5); -webkit-transition: background-color 200ms linear; -moz-transition: background-color 200ms linear; -o-transition: background-color 200ms linear; -ms-transition: background-color 200ms linear; transition: background-color 200ms linear; height: 87px; } .navbar-default .navbar-nav>li>a { color: #ffffff; } .navbar-default .navbar-nav > li > a:hover, .navbar-default .navbar-nav > li > a:focus { background-color: #F8BD23; text-decoration: none; color: #ffffff; -webkit-transition: background-color 200ms linear; -moz-transition: background-color 200ms linear; -o-transition: background-color 200ms linear; -ms-transition: background-color 200ms linear; transition: background-color 200ms linear; } .navbar-nav > li{ padding-left:30px; } .logo { margin-left: 40px; margin-top: -17px; } .homeMess { position: absolute; top: 50%; left: 50%; margin-top: -109px; margin-left: -725px; } .homeMess h1 { font-size: 100px; text-transform: uppercase; font-weight: 900; font-size: 60px; letter-spacing: -5px; line-height: 50px; color: white; }
So I am just trying to get the
homeMess
class to be in the middle of the screen but the way I am doing it is not good. Also I am using bootstrap v3.
原文:https://stackoverflow.com/questions/45394524
最满意答案
这是适用于我的解决方案。
FactoryGirl.define do factory :company do #company attributes end factory :user do companies {[FactoryGirl.create(:company)]} #user attributes end end
如果你需要特定的公司,你可以这样使用工厂
company = FactoryGirl.create(:company, #{company attributes}) user = FactoryGirl.create(:user, :companies => [company])
希望这将有助于某人。
Factorygirl has since been updated and now includes callbacks to solve this problem. Take a look at http://robots.thoughtbot.com/post/254496652/aint-no-calla-back-girl for more info.
相关问答
更多-
工厂女孩嵌套协会(Factory Girl Nested Associations)[2022-06-09]
您需要create而不是build 。 这应该工作: FactoryGirl.define do factory :user do after(:create) do |user| user.subscription = FactoryGirl.create(:subscription) end end factory :plan do usage_limit end factory :subscription do plan end ... -
如何在工厂女孩中创建has_and_belongs_to_many关联(How to create has_and_belongs_to_many associations in Factory girl)[2022-10-27]
这是适用于我的解决方案。 FactoryGirl.define do factory :company do #company attributes end factory :user do companies {[FactoryGirl.create(:company)]} #user attributes end end 如果你需要特定的公司,你可以这样使用工厂 company = FactoryGirl.create(:company, #{company ... -
对于我通常在FactoryGirl使用after(:build)使用的关联,然后我可以确切地说明应该发生什么。 ( association xxx通常不像我想要的那样工作,对我感到羞耻。) 所以在你的情况下,我认为你可以解决这个问题: require 'faker' FactoryGirl.define do factory :adhoc_mapping do |f| transient do default_parent { Parent.where(parent: Faker: ...
-
您应该能够像其他属性一样分配关系。 例如: user = create(:user) foobar = create(:foobar) blogs = create_list(:blog, 5, user: user, foobar: foobar) You should be able to assign the relationships like other attributes. e.g: user = create(:user) foobar = create(:foobar) blogs = ...
-
对于ActiveRecord 4,您应该使用范围块内的新样式查询接口 http://guides.rubyonrails.org/active_record_querying.html 完全未经测试,但以下内容应该是如何构建查询的指南:(请注意,每个方法都链接到上面的方法) scope :unread, { joins( "LEFT JOIN notifications_users ON notifications.id = notifications_users.notification_id") ...
-
事实证明,你不能在工厂内真正做到这种关系。 最后,我删除了关联,并首先手动构建代理和任何其他关联,然后将它们传递到工厂的构建中。 例如: let(:agency) { build(:agency) } let(:account_manager) { build(:agent, agency: agency) } let(:landlord) { build(:landlord, agency: agency) } let(:property) { build(:property, agenc ...
-
以下是解释的答案: FactoryGirl.define do factory :trip do description { Faker::Lorem.sentence } end_date { DateTime.now + 1.day } after(:build) do |trip, evaluator| trip.countries << FactoryGirl.create(:country, :with_currencies) end en ...
-
不要为所有用户执行此操作,而应创建从用户工厂继承的另一个工厂。 Factory.define :user_with_group, :parent => :user do |u| u.groups { |g| [ g.association(:group), g.association(:group) ]} end 你可以在https://github.com/drhenner/ror_ecommerce/tree/mast ...
-
最后,我使用FactoryGirl特性和attributes 这是poll工厂代码: FactoryGirl.define do factory :poll do title { FFaker::Lorem.phrase } description { FFaker::Lorem.sentences } user choices_attributes { [FactoryGirl.attributes_for(:choice), FactoryGirl.attri ...
-
试试这样: class Activity < ActiveRecord::Base belongs_to :pictogram has_and_belongs_to_many :users accepts_nested_attributes_for :pictogram, allow_destroy: false def user_ids=(values) self.users << User.find(values) end end #controller def ac ...